docker 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913
  1. #!/bin/bash
  2. #
  3. # bash completion file for core docker commands
  4. #
  5. # This script provides completion of:
  6. # - commands and their options
  7. # - container ids and names
  8. # - image repos and tags
  9. # - filepaths
  10. #
  11. # To enable the completions either:
  12. # - place this file in /etc/bash_completion.d
  13. # or
  14. # - copy this file to e.g. ~/.docker-completion.sh and add the line
  15. # below to your .bashrc after bash completion features are loaded
  16. # . ~/.docker-completion.sh
  17. #
  18. # Configuration:
  19. #
  20. # For several commands, the amount of completions can be configured by
  21. # setting environment variables.
  22. #
  23. # DOCKER_COMPLETION_SHOW_NETWORK_IDS
  24. # "no" - Show names only (default)
  25. # "yes" - Show names and ids
  26. #
  27. # You can tailor completion for the "events", "history", "inspect", "run",
  28. # "rmi" and "save" commands by settings the following environment
  29. # variables:
  30. #
  31. # DOCKER_COMPLETION_SHOW_IMAGE_IDS
  32. # "none" - Show names only (default)
  33. # "non-intermediate" - Show names and ids, but omit intermediate image IDs
  34. # "all" - Show names and ids, including intermediate image IDs
  35. #
  36. # DOCKER_COMPLETION_SHOW_TAGS
  37. # "yes" - include tags in completion options (default)
  38. # "no" - don't include tags in completion options
  39. #
  40. # Note:
  41. # Currently, the completions will not work if the docker daemon is not
  42. # bound to the default communication port/socket
  43. # If the docker daemon is using a unix socket for communication your user
  44. # must have access to the socket for the completions to function correctly
  45. #
  46. # Note for developers:
  47. # Please arrange options sorted alphabetically by long name with the short
  48. # options immediately following their corresponding long form.
  49. # This order should be applied to lists, alternatives and code blocks.
  50. __docker_previous_extglob_setting=$(shopt -p extglob)
  51. shopt -s extglob
  52. __docker_q() {
  53. docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@"
  54. }
  55. __docker_containers_all() {
  56. local IFS=$'\n'
  57. local containers=( $(__docker_q ps -aq --no-trunc) )
  58. if [ "$1" ]; then
  59. containers=( $(__docker_q inspect --format "{{if $1}}{{.Id}}{{end}}" "${containers[@]}") )
  60. fi
  61. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  62. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  63. unset IFS
  64. COMPREPLY=( $(compgen -W "${names[*]} ${containers[*]}" -- "$cur") )
  65. }
  66. __docker_containers_running() {
  67. __docker_containers_all '.State.Running'
  68. }
  69. __docker_containers_stopped() {
  70. __docker_containers_all 'not .State.Running'
  71. }
  72. __docker_containers_pauseable() {
  73. __docker_containers_all 'and .State.Running (not .State.Paused)'
  74. }
  75. __docker_containers_unpauseable() {
  76. __docker_containers_all '.State.Paused'
  77. }
  78. __docker_container_names() {
  79. local containers=( $(__docker_q ps -aq --no-trunc) )
  80. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  81. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  82. COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") )
  83. }
  84. __docker_container_ids() {
  85. local containers=( $(__docker_q ps -aq) )
  86. COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") )
  87. }
  88. __docker_images() {
  89. local images_args=""
  90. case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
  91. all)
  92. images_args="--no-trunc -a"
  93. ;;
  94. non-intermediate)
  95. images_args="--no-trunc"
  96. ;;
  97. esac
  98. local repo_print_command
  99. if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then
  100. repo_print_command='print $1; print $1":"$2'
  101. else
  102. repo_print_command='print $1'
  103. fi
  104. local awk_script
  105. case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
  106. all|non-intermediate)
  107. awk_script='NR>1 { print $3; if ($1 != "<none>") { '"$repo_print_command"' } }'
  108. ;;
  109. none|*)
  110. awk_script='NR>1 && $1 != "<none>" { '"$repo_print_command"' }'
  111. ;;
  112. esac
  113. local images=$(__docker_q images $images_args | awk "$awk_script")
  114. COMPREPLY=( $(compgen -W "$images" -- "$cur") )
  115. __ltrim_colon_completions "$cur"
  116. }
  117. __docker_image_repos() {
  118. local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')"
  119. COMPREPLY=( $(compgen -W "$repos" -- "$cur") )
  120. }
  121. __docker_image_repos_and_tags() {
  122. local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')"
  123. COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") )
  124. __ltrim_colon_completions "$cur"
  125. }
  126. __docker_containers_and_images() {
  127. __docker_containers_all
  128. local containers=( "${COMPREPLY[@]}" )
  129. __docker_images
  130. COMPREPLY+=( "${containers[@]}" )
  131. }
  132. __docker_networks() {
  133. # By default, only network names are completed.
  134. # Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete network IDs.
  135. local fields='$2'
  136. [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] && fields='$1,$2'
  137. local networks=$(__docker_q network ls --no-trunc | awk "NR>1 {print $fields}")
  138. COMPREPLY=( $(compgen -W "$networks" -- "$cur") )
  139. }
  140. __docker_volumes() {
  141. COMPREPLY=( $(compgen -W "$(__docker_q volume ls -q)" -- "$cur") )
  142. }
  143. # Finds the position of the first word that is neither option nor an option's argument.
  144. # If there are options that require arguments, you should pass a glob describing those
  145. # options, e.g. "--option1|-o|--option2"
  146. # Use this function to restrict completions to exact positions after the argument list.
  147. __docker_pos_first_nonflag() {
  148. local argument_flags=$1
  149. local counter=$((${subcommand_pos:-${command_pos}} + 1))
  150. while [ $counter -le $cword ]; do
  151. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  152. (( counter++ ))
  153. # eat "=" in case of --option=arg syntax
  154. [ "${words[$counter]}" = "=" ] && (( counter++ ))
  155. else
  156. case "${words[$counter]}" in
  157. -*)
  158. ;;
  159. *)
  160. break
  161. ;;
  162. esac
  163. fi
  164. # Bash splits words at "=", retaining "=" as a word, examples:
  165. # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
  166. while [ "${words[$counter + 1]}" = "=" ] ; do
  167. counter=$(( counter + 2))
  168. done
  169. (( counter++ ))
  170. done
  171. echo $counter
  172. }
  173. # Returns the value of the first option matching option_glob.
  174. # Valid values for option_glob are option names like '--log-level' and
  175. # globs like '--log-level|-l'
  176. # Only positions between the command and the current word are considered.
  177. __docker_value_of_option() {
  178. local option_extglob=$(__docker_to_extglob "$1")
  179. local counter=$((command_pos + 1))
  180. while [ $counter -lt $cword ]; do
  181. case ${words[$counter]} in
  182. $option_extglob )
  183. echo ${words[$counter + 1]}
  184. break
  185. ;;
  186. esac
  187. (( counter++ ))
  188. done
  189. }
  190. # Transforms a multiline list of strings into a single line string
  191. # with the words separated by "|".
  192. # This is used to prepare arguments to __docker_pos_first_nonflag().
  193. __docker_to_alternatives() {
  194. local parts=( $1 )
  195. local IFS='|'
  196. echo "${parts[*]}"
  197. }
  198. # Transforms a multiline list of options into an extglob pattern
  199. # suitable for use in case statements.
  200. __docker_to_extglob() {
  201. local extglob=$( __docker_to_alternatives "$1" )
  202. echo "@($extglob)"
  203. }
  204. # Subcommand processing.
  205. # Locates the first occurrence of any of the subcommands contained in the
  206. # first argument. In case of a match, calls the corresponding completion
  207. # function and returns 0.
  208. # If no match is found, 1 is returned. The calling function can then
  209. # continue processing its completion.
  210. #
  211. # TODO if the preceding command has options that accept arguments and an
  212. # argument is equal ot one of the subcommands, this is falsely detected as
  213. # a match.
  214. __docker_subcommands() {
  215. local subcommands="$1"
  216. local counter=$(($command_pos + 1))
  217. while [ $counter -lt $cword ]; do
  218. case "${words[$counter]}" in
  219. $(__docker_to_extglob "$subcommands") )
  220. subcommand_pos=$counter
  221. local subcommand=${words[$counter]}
  222. local completions_func=_docker_${command}_${subcommand}
  223. declare -F $completions_func >/dev/null && $completions_func
  224. return 0
  225. ;;
  226. esac
  227. (( counter++ ))
  228. done
  229. return 1
  230. }
  231. # suppress trailing whitespace
  232. __docker_nospace() {
  233. # compopt is not available in ancient bash versions
  234. type compopt &>/dev/null && compopt -o nospace
  235. }
  236. __docker_resolve_hostname() {
  237. command -v host >/dev/null 2>&1 || return
  238. COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
  239. }
  240. __docker_capabilities() {
  241. # The list of capabilities is defined in types.go, ALL was added manually.
  242. COMPREPLY=( $( compgen -W "
  243. ALL
  244. AUDIT_CONTROL
  245. AUDIT_WRITE
  246. AUDIT_READ
  247. BLOCK_SUSPEND
  248. CHOWN
  249. DAC_OVERRIDE
  250. DAC_READ_SEARCH
  251. FOWNER
  252. FSETID
  253. IPC_LOCK
  254. IPC_OWNER
  255. KILL
  256. LEASE
  257. LINUX_IMMUTABLE
  258. MAC_ADMIN
  259. MAC_OVERRIDE
  260. MKNOD
  261. NET_ADMIN
  262. NET_BIND_SERVICE
  263. NET_BROADCAST
  264. NET_RAW
  265. SETFCAP
  266. SETGID
  267. SETPCAP
  268. SETUID
  269. SYS_ADMIN
  270. SYS_BOOT
  271. SYS_CHROOT
  272. SYSLOG
  273. SYS_MODULE
  274. SYS_NICE
  275. SYS_PACCT
  276. SYS_PTRACE
  277. SYS_RAWIO
  278. SYS_RESOURCE
  279. SYS_TIME
  280. SYS_TTY_CONFIG
  281. WAKE_ALARM
  282. " -- "$cur" ) )
  283. }
  284. __docker_log_drivers() {
  285. COMPREPLY=( $( compgen -W "
  286. awslogs
  287. fluentd
  288. gelf
  289. journald
  290. json-file
  291. none
  292. splunk
  293. syslog
  294. " -- "$cur" ) )
  295. }
  296. __docker_log_driver_options() {
  297. # see docs/reference/logging/index.md
  298. local awslogs_options="awslogs-region awslogs-group awslogs-stream"
  299. local fluentd_options="env fluentd-address labels tag"
  300. local gelf_options="env gelf-address labels tag"
  301. local journald_options="env labels"
  302. local json_file_options="env labels max-file max-size"
  303. local syslog_options="syslog-address syslog-facility tag"
  304. local splunk_options="env labels splunk-caname splunk-capath splunk-index splunk-insecureskipverify splunk-source splunk-sourcetype splunk-token splunk-url tag"
  305. local all_options="$fluentd_options $gelf_options $journald_options $json_file_options $syslog_options $splunk_options"
  306. case $(__docker_value_of_option --log-driver) in
  307. '')
  308. COMPREPLY=( $( compgen -W "$all_options" -S = -- "$cur" ) )
  309. ;;
  310. awslogs)
  311. COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) )
  312. ;;
  313. fluentd)
  314. COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) )
  315. ;;
  316. gelf)
  317. COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) )
  318. ;;
  319. journald)
  320. COMPREPLY=( $( compgen -W "$journald_options" -S = -- "$cur" ) )
  321. ;;
  322. json-file)
  323. COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) )
  324. ;;
  325. syslog)
  326. COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) )
  327. ;;
  328. splunk)
  329. COMPREPLY=( $( compgen -W "$splunk_options" -S = -- "$cur" ) )
  330. ;;
  331. *)
  332. return
  333. ;;
  334. esac
  335. __docker_nospace
  336. }
  337. __docker_complete_log_driver_options() {
  338. # "=" gets parsed to a word and assigned to either $cur or $prev depending on whether
  339. # it is the last character or not. So we search for "xxx=" in the the last two words.
  340. case "${words[$cword-2]}$prev=" in
  341. *gelf-address=*)
  342. COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur#=}" ) )
  343. __docker_nospace
  344. return
  345. ;;
  346. *syslog-address=*)
  347. COMPREPLY=( $( compgen -W "tcp udp unix" -S "://" -- "${cur#=}" ) )
  348. __docker_nospace
  349. return
  350. ;;
  351. *syslog-facility=*)
  352. COMPREPLY=( $( compgen -W "
  353. auth
  354. authpriv
  355. cron
  356. daemon
  357. ftp
  358. kern
  359. local0
  360. local1
  361. local2
  362. local3
  363. local4
  364. local5
  365. local6
  366. local7
  367. lpr
  368. mail
  369. news
  370. syslog
  371. user
  372. uucp
  373. " -- "${cur#=}" ) )
  374. return
  375. ;;
  376. *splunk-url=*)
  377. COMPREPLY=( $( compgen -W "http:// https://" -- "${cur#=}" ) )
  378. compopt -o nospace
  379. __ltrim_colon_completions "${cur}"
  380. return
  381. ;;
  382. *splunk-insecureskipverify=*)
  383. COMPREPLY=( $( compgen -W "true false" -- "${cur#=}" ) )
  384. compopt -o nospace
  385. return
  386. ;;
  387. esac
  388. return 1
  389. }
  390. __docker_log_levels() {
  391. COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) )
  392. }
  393. # a selection of the available signals that is most likely of interest in the
  394. # context of docker containers.
  395. __docker_signals() {
  396. local signals=(
  397. SIGCONT
  398. SIGHUP
  399. SIGINT
  400. SIGKILL
  401. SIGQUIT
  402. SIGSTOP
  403. SIGTERM
  404. SIGUSR1
  405. SIGUSR2
  406. )
  407. COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) )
  408. }
  409. # global options that may appear after the docker command
  410. _docker_docker() {
  411. local boolean_options="
  412. $global_boolean_options
  413. --help
  414. --version -v
  415. "
  416. case "$prev" in
  417. --config)
  418. _filedir -d
  419. return
  420. ;;
  421. --log-level|-l)
  422. __docker_log_levels
  423. return
  424. ;;
  425. $(__docker_to_extglob "$global_options_with_args") )
  426. return
  427. ;;
  428. esac
  429. case "$cur" in
  430. -*)
  431. COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) )
  432. ;;
  433. *)
  434. local counter=$( __docker_pos_first_nonflag $(__docker_to_extglob "$global_options_with_args") )
  435. if [ $cword -eq $counter ]; then
  436. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  437. fi
  438. ;;
  439. esac
  440. }
  441. _docker_attach() {
  442. case "$cur" in
  443. -*)
  444. COMPREPLY=( $( compgen -W "--help --no-stdin --sig-proxy" -- "$cur" ) )
  445. ;;
  446. *)
  447. local counter="$(__docker_pos_first_nonflag)"
  448. if [ $cword -eq $counter ]; then
  449. __docker_containers_running
  450. fi
  451. ;;
  452. esac
  453. }
  454. _docker_build() {
  455. local options_with_args="
  456. --build-arg
  457. --cgroup-parent
  458. --cpuset-cpus
  459. --cpuset-mems
  460. --cpu-shares
  461. --cpu-period
  462. --cpu-quota
  463. --file -f
  464. --memory -m
  465. --memory-swap
  466. --tag -t
  467. --ulimit
  468. "
  469. local boolean_options="
  470. --disable-content-trust=false
  471. --force-rm
  472. --help
  473. --no-cache
  474. --pull
  475. --quiet -q
  476. --rm
  477. "
  478. local all_options="$options_with_args $boolean_options"
  479. case "$prev" in
  480. --build-arg)
  481. COMPREPLY=( $( compgen -e -- "$cur" ) )
  482. __docker_nospace
  483. return
  484. ;;
  485. --file|-f)
  486. _filedir
  487. return
  488. ;;
  489. --tag|-t)
  490. __docker_image_repos_and_tags
  491. return
  492. ;;
  493. $(__docker_to_extglob "$options_with_args") )
  494. return
  495. ;;
  496. esac
  497. case "$cur" in
  498. -*)
  499. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  500. ;;
  501. *)
  502. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  503. if [ $cword -eq $counter ]; then
  504. _filedir -d
  505. fi
  506. ;;
  507. esac
  508. }
  509. _docker_commit() {
  510. case "$prev" in
  511. --author|-a|--change|-c|--message|-m)
  512. return
  513. ;;
  514. esac
  515. case "$cur" in
  516. -*)
  517. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause -p" -- "$cur" ) )
  518. ;;
  519. *)
  520. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  521. if [ $cword -eq $counter ]; then
  522. __docker_containers_all
  523. return
  524. fi
  525. (( counter++ ))
  526. if [ $cword -eq $counter ]; then
  527. __docker_image_repos_and_tags
  528. return
  529. fi
  530. ;;
  531. esac
  532. }
  533. _docker_cp() {
  534. case "$cur" in
  535. -*)
  536. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  537. ;;
  538. *)
  539. local counter=$(__docker_pos_first_nonflag)
  540. if [ $cword -eq $counter ]; then
  541. case "$cur" in
  542. *:)
  543. return
  544. ;;
  545. *)
  546. # combined container and filename completion
  547. _filedir
  548. local files=( ${COMPREPLY[@]} )
  549. __docker_containers_all
  550. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  551. local containers=( ${COMPREPLY[@]} )
  552. COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) )
  553. if [[ "$COMPREPLY" == *: ]]; then
  554. __docker_nospace
  555. fi
  556. return
  557. ;;
  558. esac
  559. fi
  560. (( counter++ ))
  561. if [ $cword -eq $counter ]; then
  562. if [ -e "$prev" ]; then
  563. __docker_containers_all
  564. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  565. __docker_nospace
  566. else
  567. _filedir
  568. fi
  569. return
  570. fi
  571. ;;
  572. esac
  573. }
  574. _docker_create() {
  575. _docker_run
  576. }
  577. _docker_daemon() {
  578. local boolean_options="
  579. $global_boolean_options
  580. --disable-legacy-registry
  581. --help
  582. --icc=false
  583. --ip-forward=false
  584. --ip-masq=false
  585. --iptables=false
  586. --ipv6
  587. --selinux-enabled
  588. --userland-proxy=false
  589. "
  590. local options_with_args="
  591. $global_options_with_args
  592. --api-cors-header
  593. --bip
  594. --bridge -b
  595. --cluster-advertise
  596. --cluster-store
  597. --cluster-store-opt
  598. --default-gateway
  599. --default-gateway-v6
  600. --default-ulimit
  601. --dns
  602. --dns-search
  603. --dns-opt
  604. --exec-opt
  605. --exec-root
  606. --fixed-cidr
  607. --fixed-cidr-v6
  608. --graph -g
  609. --group -G
  610. --insecure-registry
  611. --ip
  612. --label
  613. --log-driver
  614. --log-opt
  615. --mtu
  616. --pidfile -p
  617. --registry-mirror
  618. --storage-driver -s
  619. --storage-opt
  620. "
  621. case "$prev" in
  622. --cluster-store)
  623. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  624. __docker_nospace
  625. return
  626. ;;
  627. --cluster-store-opt)
  628. COMPREPLY=( $( compgen -W "kv.cacertfile kv.certfile kv.keyfile" -S = -- "$cur" ) )
  629. __docker_nospace
  630. return
  631. ;;
  632. --exec-root|--graph|-g)
  633. _filedir -d
  634. return
  635. ;;
  636. --log-driver)
  637. __docker_log_drivers
  638. return
  639. ;;
  640. --pidfile|-p|--tlscacert|--tlscert|--tlskey)
  641. _filedir
  642. return
  643. ;;
  644. --storage-driver|-s)
  645. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  646. return
  647. ;;
  648. --storage-opt)
  649. local devicemapper_options="
  650. dm.basesize
  651. dm.blkdiscard
  652. dm.blocksize
  653. dm.fs
  654. dm.loopdatasize
  655. dm.loopmetadatasize
  656. dm.mkfsarg
  657. dm.mountopt
  658. dm.override_udev_sync_check
  659. dm.thinpooldev
  660. dm.use_deferred_deletion
  661. dm.use_deferred_removal
  662. "
  663. local zfs_options="zfs.fsname"
  664. case $(__docker_value_of_option '--storage-driver|-s') in
  665. '')
  666. COMPREPLY=( $( compgen -W "$devicemapper_options $zfs_options" -S = -- "$cur" ) )
  667. ;;
  668. devicemapper)
  669. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  670. ;;
  671. zfs)
  672. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  673. ;;
  674. *)
  675. return
  676. ;;
  677. esac
  678. __docker_nospace
  679. return
  680. ;;
  681. --log-level|-l)
  682. __docker_log_levels
  683. return
  684. ;;
  685. --log-opt)
  686. __docker_log_driver_options
  687. return
  688. ;;
  689. $(__docker_to_extglob "$options_with_args") )
  690. return
  691. ;;
  692. esac
  693. __docker_complete_log_driver_options && return
  694. case "${words[$cword-2]}$prev=" in
  695. # completions for --storage-opt
  696. *dm.@(blkdiscard|override_udev_sync_check|use_deferred_@(removal|deletion))=*)
  697. COMPREPLY=( $( compgen -W "false true" -- "${cur#=}" ) )
  698. return
  699. ;;
  700. *dm.fs=*)
  701. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur#=}" ) )
  702. return
  703. ;;
  704. *dm.thinpooldev=*)
  705. _filedir
  706. return
  707. ;;
  708. # completions for --cluster-store-opt
  709. *kv.*file=*)
  710. _filedir
  711. return
  712. ;;
  713. esac
  714. case "$cur" in
  715. -*)
  716. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  717. ;;
  718. esac
  719. }
  720. _docker_diff() {
  721. case "$cur" in
  722. -*)
  723. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  724. ;;
  725. *)
  726. local counter=$(__docker_pos_first_nonflag)
  727. if [ $cword -eq $counter ]; then
  728. __docker_containers_all
  729. fi
  730. ;;
  731. esac
  732. }
  733. _docker_events() {
  734. case "$prev" in
  735. --filter|-f)
  736. COMPREPLY=( $( compgen -S = -W "container event image" -- "$cur" ) )
  737. __docker_nospace
  738. return
  739. ;;
  740. --since|--until)
  741. return
  742. ;;
  743. esac
  744. case "${words[$cword-2]}$prev=" in
  745. *container=*)
  746. cur="${cur#=}"
  747. __docker_containers_all
  748. return
  749. ;;
  750. *event=*)
  751. COMPREPLY=( $( compgen -W "
  752. attach
  753. commit
  754. copy
  755. create
  756. delete
  757. destroy
  758. die
  759. exec_create
  760. exec_start
  761. export
  762. import
  763. kill
  764. oom
  765. pause
  766. pull
  767. push
  768. rename
  769. resize
  770. restart
  771. start
  772. stop
  773. tag
  774. top
  775. unpause
  776. untag
  777. " -- "${cur#=}" ) )
  778. return
  779. ;;
  780. *image=*)
  781. cur="${cur#=}"
  782. __docker_images
  783. return
  784. ;;
  785. esac
  786. case "$cur" in
  787. -*)
  788. COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) )
  789. ;;
  790. esac
  791. }
  792. _docker_exec() {
  793. case "$prev" in
  794. --user|-u)
  795. return
  796. ;;
  797. esac
  798. case "$cur" in
  799. -*)
  800. COMPREPLY=( $( compgen -W "--detach -d --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  801. ;;
  802. *)
  803. __docker_containers_running
  804. ;;
  805. esac
  806. }
  807. _docker_export() {
  808. case "$cur" in
  809. -*)
  810. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  811. ;;
  812. *)
  813. local counter=$(__docker_pos_first_nonflag)
  814. if [ $cword -eq $counter ]; then
  815. __docker_containers_all
  816. fi
  817. ;;
  818. esac
  819. }
  820. _docker_help() {
  821. local counter=$(__docker_pos_first_nonflag)
  822. if [ $cword -eq $counter ]; then
  823. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  824. fi
  825. }
  826. _docker_history() {
  827. case "$cur" in
  828. -*)
  829. COMPREPLY=( $( compgen -W "--help --no-trunc --quiet -q" -- "$cur" ) )
  830. ;;
  831. *)
  832. local counter=$(__docker_pos_first_nonflag)
  833. if [ $cword -eq $counter ]; then
  834. __docker_images
  835. fi
  836. ;;
  837. esac
  838. }
  839. _docker_images() {
  840. case "$prev" in
  841. --filter|-f)
  842. COMPREPLY=( $( compgen -W "dangling=true label=" -- "$cur" ) )
  843. if [ "$COMPREPLY" = "label=" ]; then
  844. __docker_nospace
  845. fi
  846. return
  847. ;;
  848. esac
  849. case "${words[$cword-2]}$prev=" in
  850. *dangling=*)
  851. COMPREPLY=( $( compgen -W "true false" -- "${cur#=}" ) )
  852. return
  853. ;;
  854. *label=*)
  855. return
  856. ;;
  857. esac
  858. case "$cur" in
  859. -*)
  860. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
  861. ;;
  862. =)
  863. return
  864. ;;
  865. *)
  866. __docker_image_repos
  867. ;;
  868. esac
  869. }
  870. _docker_import() {
  871. case "$prev" in
  872. --change|-c|--message|-m)
  873. return
  874. ;;
  875. esac
  876. case "$cur" in
  877. -*)
  878. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  879. ;;
  880. *)
  881. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  882. if [ $cword -eq $counter ]; then
  883. return
  884. fi
  885. (( counter++ ))
  886. if [ $cword -eq $counter ]; then
  887. __docker_image_repos_and_tags
  888. return
  889. fi
  890. ;;
  891. esac
  892. }
  893. _docker_info() {
  894. case "$cur" in
  895. -*)
  896. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  897. ;;
  898. esac
  899. }
  900. _docker_inspect() {
  901. case "$prev" in
  902. --format|-f)
  903. return
  904. ;;
  905. --type)
  906. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  907. return
  908. ;;
  909. esac
  910. case "$cur" in
  911. -*)
  912. COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) )
  913. ;;
  914. *)
  915. case $(__docker_value_of_option --type) in
  916. '')
  917. __docker_containers_and_images
  918. ;;
  919. container)
  920. __docker_containers_all
  921. ;;
  922. image)
  923. __docker_images
  924. ;;
  925. esac
  926. esac
  927. }
  928. _docker_kill() {
  929. case "$prev" in
  930. --signal|-s)
  931. __docker_signals
  932. return
  933. ;;
  934. esac
  935. case "$cur" in
  936. -*)
  937. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  938. ;;
  939. *)
  940. __docker_containers_running
  941. ;;
  942. esac
  943. }
  944. _docker_load() {
  945. case "$prev" in
  946. --input|-i)
  947. _filedir
  948. return
  949. ;;
  950. esac
  951. case "$cur" in
  952. -*)
  953. COMPREPLY=( $( compgen -W "--help --input -i" -- "$cur" ) )
  954. ;;
  955. esac
  956. }
  957. _docker_login() {
  958. case "$prev" in
  959. --email|-e|--password|-p|--username|-u)
  960. return
  961. ;;
  962. esac
  963. case "$cur" in
  964. -*)
  965. COMPREPLY=( $( compgen -W "--email -e --help --password -p --username -u" -- "$cur" ) )
  966. ;;
  967. esac
  968. }
  969. _docker_logout() {
  970. case "$cur" in
  971. -*)
  972. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  973. ;;
  974. esac
  975. }
  976. _docker_logs() {
  977. case "$prev" in
  978. --since|--tail)
  979. return
  980. ;;
  981. esac
  982. case "$cur" in
  983. -*)
  984. COMPREPLY=( $( compgen -W "--follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  985. ;;
  986. *)
  987. local counter=$(__docker_pos_first_nonflag '--tail')
  988. if [ $cword -eq $counter ]; then
  989. __docker_containers_all
  990. fi
  991. ;;
  992. esac
  993. }
  994. _docker_network_connect() {
  995. case "$cur" in
  996. -*)
  997. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  998. ;;
  999. *)
  1000. local counter=$(__docker_pos_first_nonflag '--tail')
  1001. if [ $cword -eq $counter ]; then
  1002. __docker_networks
  1003. elif [ $cword -eq $(($counter + 1)) ]; then
  1004. __docker_containers_running
  1005. fi
  1006. ;;
  1007. esac
  1008. }
  1009. _docker_network_create() {
  1010. case "$prev" in
  1011. --aux-address|--gateway|--ip-range|--opt|-o|--subnet)
  1012. return
  1013. ;;
  1014. --ipam-driver)
  1015. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  1016. return
  1017. ;;
  1018. --driver|-d)
  1019. # no need to suggest drivers that allow one instance only
  1020. # (host, null)
  1021. COMPREPLY=( $( compgen -W "bridge overlay" -- "$cur" ) )
  1022. return
  1023. ;;
  1024. esac
  1025. case "$cur" in
  1026. -*)
  1027. COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --ip-range --ipam-driver --opt -o --subnet" -- "$cur" ) )
  1028. ;;
  1029. esac
  1030. }
  1031. _docker_network_disconnect() {
  1032. # TODO disconnect should only complete running containers connected
  1033. # to the specified network.
  1034. _docker_network_connect
  1035. }
  1036. _docker_network_inspect() {
  1037. case "$prev" in
  1038. --format|-f)
  1039. return
  1040. ;;
  1041. esac
  1042. case "$cur" in
  1043. -*)
  1044. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1045. ;;
  1046. *)
  1047. __docker_networks
  1048. esac
  1049. }
  1050. _docker_network_ls() {
  1051. case "$prev" in
  1052. -n)
  1053. return
  1054. ;;
  1055. esac
  1056. case "$cur" in
  1057. -*)
  1058. COMPREPLY=( $( compgen -W "--help --no-trunc --quiet -q" -- "$cur" ) )
  1059. ;;
  1060. esac
  1061. }
  1062. _docker_network_rm() {
  1063. _docker_network_inspect
  1064. }
  1065. _docker_network() {
  1066. local subcommands="
  1067. connect
  1068. create
  1069. disconnect
  1070. inspect
  1071. ls
  1072. rm
  1073. "
  1074. __docker_subcommands "$subcommands" && return
  1075. case "$cur" in
  1076. -*)
  1077. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1078. ;;
  1079. *)
  1080. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1081. ;;
  1082. esac
  1083. }
  1084. _docker_pause() {
  1085. case "$cur" in
  1086. -*)
  1087. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1088. ;;
  1089. *)
  1090. local counter=$(__docker_pos_first_nonflag)
  1091. if [ $cword -eq $counter ]; then
  1092. __docker_containers_pauseable
  1093. fi
  1094. ;;
  1095. esac
  1096. }
  1097. _docker_port() {
  1098. case "$cur" in
  1099. -*)
  1100. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1101. ;;
  1102. *)
  1103. local counter=$(__docker_pos_first_nonflag)
  1104. if [ $cword -eq $counter ]; then
  1105. __docker_containers_all
  1106. fi
  1107. ;;
  1108. esac
  1109. }
  1110. _docker_ps() {
  1111. case "$prev" in
  1112. --before|--since)
  1113. __docker_containers_all
  1114. ;;
  1115. --filter|-f)
  1116. COMPREPLY=( $( compgen -S = -W "ancestor exited id label name status" -- "$cur" ) )
  1117. __docker_nospace
  1118. return
  1119. ;;
  1120. --format|-n)
  1121. return
  1122. ;;
  1123. esac
  1124. case "${words[$cword-2]}$prev=" in
  1125. *ancestor=*)
  1126. cur="${cur#=}"
  1127. __docker_images
  1128. return
  1129. ;;
  1130. *id=*)
  1131. cur="${cur#=}"
  1132. __docker_container_ids
  1133. return
  1134. ;;
  1135. *name=*)
  1136. cur="${cur#=}"
  1137. __docker_container_names
  1138. return
  1139. ;;
  1140. *status=*)
  1141. COMPREPLY=( $( compgen -W "exited paused restarting running" -- "${cur#=}" ) )
  1142. return
  1143. ;;
  1144. esac
  1145. case "$cur" in
  1146. -*)
  1147. COMPREPLY=( $( compgen -W "--all -a --before --filter -f --format --help --latest -l -n --no-trunc --quiet -q --size -s --since" -- "$cur" ) )
  1148. ;;
  1149. esac
  1150. }
  1151. _docker_pull() {
  1152. case "$cur" in
  1153. -*)
  1154. COMPREPLY=( $( compgen -W "--all-tags -a --help" -- "$cur" ) )
  1155. ;;
  1156. *)
  1157. local counter=$(__docker_pos_first_nonflag)
  1158. if [ $cword -eq $counter ]; then
  1159. for arg in "${COMP_WORDS[@]}"; do
  1160. case "$arg" in
  1161. --all-tags|-a)
  1162. __docker_image_repos
  1163. return
  1164. ;;
  1165. esac
  1166. done
  1167. __docker_image_repos_and_tags
  1168. fi
  1169. ;;
  1170. esac
  1171. }
  1172. _docker_push() {
  1173. case "$cur" in
  1174. -*)
  1175. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1176. ;;
  1177. *)
  1178. local counter=$(__docker_pos_first_nonflag)
  1179. if [ $cword -eq $counter ]; then
  1180. __docker_image_repos_and_tags
  1181. fi
  1182. ;;
  1183. esac
  1184. }
  1185. _docker_rename() {
  1186. case "$cur" in
  1187. -*)
  1188. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1189. ;;
  1190. *)
  1191. local counter=$(__docker_pos_first_nonflag)
  1192. if [ $cword -eq $counter ]; then
  1193. __docker_containers_all
  1194. fi
  1195. ;;
  1196. esac
  1197. }
  1198. _docker_restart() {
  1199. case "$prev" in
  1200. --time|-t)
  1201. return
  1202. ;;
  1203. esac
  1204. case "$cur" in
  1205. -*)
  1206. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1207. ;;
  1208. *)
  1209. __docker_containers_all
  1210. ;;
  1211. esac
  1212. }
  1213. _docker_rm() {
  1214. case "$cur" in
  1215. -*)
  1216. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  1217. ;;
  1218. *)
  1219. for arg in "${COMP_WORDS[@]}"; do
  1220. case "$arg" in
  1221. --force|-f)
  1222. __docker_containers_all
  1223. return
  1224. ;;
  1225. esac
  1226. done
  1227. __docker_containers_stopped
  1228. ;;
  1229. esac
  1230. }
  1231. _docker_rmi() {
  1232. case "$cur" in
  1233. -*)
  1234. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  1235. ;;
  1236. *)
  1237. __docker_images
  1238. ;;
  1239. esac
  1240. }
  1241. _docker_run() {
  1242. local options_with_args="
  1243. --add-host
  1244. --attach -a
  1245. --blkio-weight
  1246. --blkio-weight-device
  1247. --cap-add
  1248. --cap-drop
  1249. --cgroup-parent
  1250. --cidfile
  1251. --cpu-period
  1252. --cpu-quota
  1253. --cpuset-cpus
  1254. --cpuset-mems
  1255. --cpu-shares
  1256. --device
  1257. --dns
  1258. --dns-opt
  1259. --dns-search
  1260. --entrypoint
  1261. --env -e
  1262. --env-file
  1263. --expose
  1264. --group-add
  1265. --hostname -h
  1266. --ipc
  1267. --kernel-memory
  1268. --label-file
  1269. --label -l
  1270. --link
  1271. --log-driver
  1272. --log-opt
  1273. --mac-address
  1274. --memory -m
  1275. --memory-swap
  1276. --memory-swappiness
  1277. --memory-reservation
  1278. --name
  1279. --net
  1280. --oom-score-adj
  1281. --pid
  1282. --publish -p
  1283. --restart
  1284. --security-opt
  1285. --stop-signal
  1286. --tmpfs
  1287. --ulimit
  1288. --user -u
  1289. --uts
  1290. --volume-driver
  1291. --volumes-from
  1292. --volume -v
  1293. --workdir -w
  1294. "
  1295. local boolean_options="
  1296. --disable-content-trust=false
  1297. --help
  1298. --interactive -i
  1299. --oom-kill-disable
  1300. --privileged
  1301. --publish-all -P
  1302. --read-only
  1303. --tty -t
  1304. "
  1305. local all_options="$options_with_args $boolean_options"
  1306. [ "$command" = "run" ] && all_options="$all_options
  1307. --detach -d
  1308. --rm
  1309. --sig-proxy=false
  1310. "
  1311. case "$prev" in
  1312. --add-host)
  1313. case "$cur" in
  1314. *:)
  1315. __docker_resolve_hostname
  1316. return
  1317. ;;
  1318. esac
  1319. ;;
  1320. --attach|-a)
  1321. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  1322. return
  1323. ;;
  1324. --cap-add|--cap-drop)
  1325. __docker_capabilities
  1326. return
  1327. ;;
  1328. --cidfile|--env-file|--label-file)
  1329. _filedir
  1330. return
  1331. ;;
  1332. --device|--tmpfs|--volume|-v)
  1333. case "$cur" in
  1334. *:*)
  1335. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  1336. ;;
  1337. '')
  1338. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  1339. __docker_nospace
  1340. ;;
  1341. /*)
  1342. _filedir
  1343. __docker_nospace
  1344. ;;
  1345. esac
  1346. return
  1347. ;;
  1348. --env|-e)
  1349. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1350. __docker_nospace
  1351. return
  1352. ;;
  1353. --ipc)
  1354. case "$cur" in
  1355. *:*)
  1356. cur="${cur#*:}"
  1357. __docker_containers_running
  1358. ;;
  1359. *)
  1360. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1361. if [ "$COMPREPLY" = "container:" ]; then
  1362. __docker_nospace
  1363. fi
  1364. ;;
  1365. esac
  1366. return
  1367. ;;
  1368. --link)
  1369. case "$cur" in
  1370. *:*)
  1371. ;;
  1372. *)
  1373. __docker_containers_running
  1374. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1375. __docker_nospace
  1376. ;;
  1377. esac
  1378. return
  1379. ;;
  1380. --log-driver)
  1381. __docker_log_drivers
  1382. return
  1383. ;;
  1384. --log-opt)
  1385. __docker_log_driver_options
  1386. return
  1387. ;;
  1388. --net)
  1389. case "$cur" in
  1390. container:*)
  1391. local cur=${cur#*:}
  1392. __docker_containers_all
  1393. ;;
  1394. *)
  1395. COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") )
  1396. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1397. __docker_nospace
  1398. fi
  1399. ;;
  1400. esac
  1401. return
  1402. ;;
  1403. --restart)
  1404. case "$cur" in
  1405. on-failure:*)
  1406. ;;
  1407. *)
  1408. COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") )
  1409. ;;
  1410. esac
  1411. return
  1412. ;;
  1413. --security-opt)
  1414. case "$cur" in
  1415. label:*:*)
  1416. ;;
  1417. label:*)
  1418. local cur=${cur##*:}
  1419. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") )
  1420. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  1421. __docker_nospace
  1422. fi
  1423. ;;
  1424. *)
  1425. COMPREPLY=( $( compgen -W "label apparmor seccomp" -S ":" -- "$cur") )
  1426. __docker_nospace
  1427. ;;
  1428. esac
  1429. return
  1430. ;;
  1431. --volume-driver)
  1432. COMPREPLY=( $( compgen -W "local" -- "$cur" ) )
  1433. return
  1434. ;;
  1435. --volumes-from)
  1436. __docker_containers_all
  1437. return
  1438. ;;
  1439. $(__docker_to_extglob "$options_with_args") )
  1440. return
  1441. ;;
  1442. esac
  1443. __docker_complete_log_driver_options && return
  1444. case "$cur" in
  1445. -*)
  1446. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1447. ;;
  1448. *)
  1449. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1450. if [ $cword -eq $counter ]; then
  1451. __docker_images
  1452. fi
  1453. ;;
  1454. esac
  1455. }
  1456. _docker_save() {
  1457. case "$prev" in
  1458. --output|-o)
  1459. _filedir
  1460. return
  1461. ;;
  1462. esac
  1463. case "$cur" in
  1464. -*)
  1465. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  1466. ;;
  1467. *)
  1468. __docker_images
  1469. ;;
  1470. esac
  1471. }
  1472. _docker_search() {
  1473. case "$prev" in
  1474. --stars|-s)
  1475. return
  1476. ;;
  1477. esac
  1478. case "$cur" in
  1479. -*)
  1480. COMPREPLY=( $( compgen -W "--automated --help --no-trunc --stars -s" -- "$cur" ) )
  1481. ;;
  1482. esac
  1483. }
  1484. _docker_start() {
  1485. case "$cur" in
  1486. -*)
  1487. COMPREPLY=( $( compgen -W "--attach -a --help --interactive -i" -- "$cur" ) )
  1488. ;;
  1489. *)
  1490. __docker_containers_stopped
  1491. ;;
  1492. esac
  1493. }
  1494. _docker_stats() {
  1495. case "$cur" in
  1496. -*)
  1497. COMPREPLY=( $( compgen -W "--all -a --help --no-stream" -- "$cur" ) )
  1498. ;;
  1499. *)
  1500. __docker_containers_running
  1501. ;;
  1502. esac
  1503. }
  1504. _docker_stop() {
  1505. case "$prev" in
  1506. --time|-t)
  1507. return
  1508. ;;
  1509. esac
  1510. case "$cur" in
  1511. -*)
  1512. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1513. ;;
  1514. *)
  1515. __docker_containers_running
  1516. ;;
  1517. esac
  1518. }
  1519. _docker_tag() {
  1520. case "$cur" in
  1521. -*)
  1522. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  1523. ;;
  1524. *)
  1525. local counter=$(__docker_pos_first_nonflag)
  1526. if [ $cword -eq $counter ]; then
  1527. __docker_image_repos_and_tags
  1528. return
  1529. fi
  1530. (( counter++ ))
  1531. if [ $cword -eq $counter ]; then
  1532. __docker_image_repos_and_tags
  1533. return
  1534. fi
  1535. ;;
  1536. esac
  1537. }
  1538. _docker_unpause() {
  1539. case "$cur" in
  1540. -*)
  1541. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1542. ;;
  1543. *)
  1544. local counter=$(__docker_pos_first_nonflag)
  1545. if [ $cword -eq $counter ]; then
  1546. __docker_containers_unpauseable
  1547. fi
  1548. ;;
  1549. esac
  1550. }
  1551. _docker_top() {
  1552. case "$cur" in
  1553. -*)
  1554. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1555. ;;
  1556. *)
  1557. local counter=$(__docker_pos_first_nonflag)
  1558. if [ $cword -eq $counter ]; then
  1559. __docker_containers_running
  1560. fi
  1561. ;;
  1562. esac
  1563. }
  1564. _docker_version() {
  1565. case "$cur" in
  1566. -*)
  1567. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1568. ;;
  1569. esac
  1570. }
  1571. _docker_volume_create() {
  1572. case "$prev" in
  1573. --driver|-d)
  1574. COMPREPLY=( $( compgen -W "local" -- "$cur" ) )
  1575. return
  1576. ;;
  1577. --name|--opt|-o)
  1578. return
  1579. ;;
  1580. esac
  1581. case "$cur" in
  1582. -*)
  1583. COMPREPLY=( $( compgen -W "--driver -d --help --name --opt -o" -- "$cur" ) )
  1584. ;;
  1585. esac
  1586. }
  1587. _docker_volume_inspect() {
  1588. case "$prev" in
  1589. --format|-f)
  1590. return
  1591. ;;
  1592. esac
  1593. case "$cur" in
  1594. -*)
  1595. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1596. ;;
  1597. *)
  1598. __docker_volumes
  1599. ;;
  1600. esac
  1601. }
  1602. _docker_volume_ls() {
  1603. case "$prev" in
  1604. --filter|-f)
  1605. COMPREPLY=( $( compgen -W "dangling=true" -- "$cur" ) )
  1606. return
  1607. ;;
  1608. esac
  1609. case "$cur" in
  1610. -*)
  1611. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1612. ;;
  1613. esac
  1614. }
  1615. _docker_volume_rm() {
  1616. case "$cur" in
  1617. -*)
  1618. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1619. ;;
  1620. *)
  1621. __docker_volumes
  1622. ;;
  1623. esac
  1624. }
  1625. _docker_volume() {
  1626. local subcommands="
  1627. create
  1628. inspect
  1629. ls
  1630. rm
  1631. "
  1632. __docker_subcommands "$subcommands" && return
  1633. case "$cur" in
  1634. -*)
  1635. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1636. ;;
  1637. *)
  1638. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1639. ;;
  1640. esac
  1641. }
  1642. _docker_wait() {
  1643. case "$cur" in
  1644. -*)
  1645. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1646. ;;
  1647. *)
  1648. __docker_containers_all
  1649. ;;
  1650. esac
  1651. }
  1652. _docker() {
  1653. local previous_extglob_setting=$(shopt -p extglob)
  1654. shopt -s extglob
  1655. local commands=(
  1656. attach
  1657. build
  1658. commit
  1659. cp
  1660. create
  1661. daemon
  1662. diff
  1663. events
  1664. exec
  1665. export
  1666. history
  1667. images
  1668. import
  1669. info
  1670. inspect
  1671. kill
  1672. load
  1673. login
  1674. logout
  1675. logs
  1676. network
  1677. pause
  1678. port
  1679. ps
  1680. pull
  1681. push
  1682. rename
  1683. restart
  1684. rm
  1685. rmi
  1686. run
  1687. save
  1688. search
  1689. start
  1690. stats
  1691. stop
  1692. tag
  1693. top
  1694. unpause
  1695. version
  1696. volume
  1697. wait
  1698. )
  1699. # These options are valid as global options for all client commands
  1700. # and valid as command options for `docker daemon`
  1701. local global_boolean_options="
  1702. --debug -D
  1703. --tls
  1704. --tlsverify
  1705. "
  1706. local global_options_with_args="
  1707. --config
  1708. --host -H
  1709. --log-level -l
  1710. --tlscacert
  1711. --tlscert
  1712. --tlskey
  1713. "
  1714. local host config
  1715. COMPREPLY=()
  1716. local cur prev words cword
  1717. _get_comp_words_by_ref -n : cur prev words cword
  1718. local command='docker' command_pos=0 subcommand_pos
  1719. local counter=1
  1720. while [ $counter -lt $cword ]; do
  1721. case "${words[$counter]}" in
  1722. # save host so that completion can use custom daemon
  1723. --host|-H)
  1724. (( counter++ ))
  1725. host="${words[$counter]}"
  1726. ;;
  1727. # save config so that completion can use custom configuration directories
  1728. --config)
  1729. (( counter++ ))
  1730. config="${words[$counter]}"
  1731. ;;
  1732. $(__docker_to_extglob "$global_options_with_args") )
  1733. (( counter++ ))
  1734. ;;
  1735. -*)
  1736. ;;
  1737. =)
  1738. (( counter++ ))
  1739. ;;
  1740. *)
  1741. command="${words[$counter]}"
  1742. command_pos=$counter
  1743. break
  1744. ;;
  1745. esac
  1746. (( counter++ ))
  1747. done
  1748. local completions_func=_docker_${command}
  1749. declare -F $completions_func >/dev/null && $completions_func
  1750. eval "$previous_extglob_setting"
  1751. return 0
  1752. }
  1753. eval "$__docker_previous_extglob_setting"
  1754. unset __docker_previous_extglob_setting
  1755. complete -F _docker docker