docker 36 KB

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