docker 45 KB

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