docker 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040
  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. # DOCKER_COMPLETION_SHOW_NODE_IDS
  25. # DOCKER_COMPLETION_SHOW_SERVICE_IDS
  26. # "no" - Show names only (default)
  27. # "yes" - Show names and ids
  28. #
  29. # You can tailor completion for the "events", "history", "inspect", "run",
  30. # "rmi" and "save" commands by settings the following environment
  31. # variables:
  32. #
  33. # DOCKER_COMPLETION_SHOW_IMAGE_IDS
  34. # "none" - Show names only (default)
  35. # "non-intermediate" - Show names and ids, but omit intermediate image IDs
  36. # "all" - Show names and ids, including intermediate image IDs
  37. #
  38. # DOCKER_COMPLETION_SHOW_TAGS
  39. # "yes" - include tags in completion options (default)
  40. # "no" - don't include tags in completion options
  41. #
  42. # Note:
  43. # Currently, the completions will not work if the docker daemon is not
  44. # bound to the default communication port/socket
  45. # If the docker daemon is using a unix socket for communication your user
  46. # must have access to the socket for the completions to function correctly
  47. #
  48. # Note for developers:
  49. # Please arrange options sorted alphabetically by long name with the short
  50. # options immediately following their corresponding long form.
  51. # This order should be applied to lists, alternatives and code blocks.
  52. __docker_previous_extglob_setting=$(shopt -p extglob)
  53. shopt -s extglob
  54. __docker_q() {
  55. docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@"
  56. }
  57. __docker_complete_containers_all() {
  58. local IFS=$'\n'
  59. local containers=( $(__docker_q ps -aq --no-trunc) )
  60. if [ "$1" ]; then
  61. containers=( $(__docker_q inspect --format "{{if $1}}{{.Id}}{{end}}" "${containers[@]}") )
  62. fi
  63. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  64. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  65. unset IFS
  66. COMPREPLY=( $(compgen -W "${names[*]} ${containers[*]}" -- "$cur") )
  67. }
  68. __docker_complete_containers_running() {
  69. __docker_complete_containers_all '.State.Running'
  70. }
  71. __docker_complete_containers_stopped() {
  72. __docker_complete_containers_all 'not .State.Running'
  73. }
  74. __docker_complete_containers_pauseable() {
  75. __docker_complete_containers_all 'and .State.Running (not .State.Paused)'
  76. }
  77. __docker_complete_containers_unpauseable() {
  78. __docker_complete_containers_all '.State.Paused'
  79. }
  80. __docker_complete_container_names() {
  81. local containers=( $(__docker_q ps -aq --no-trunc) )
  82. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  83. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  84. COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") )
  85. }
  86. __docker_complete_container_ids() {
  87. local containers=( $(__docker_q ps -aq) )
  88. COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") )
  89. }
  90. __docker_complete_images() {
  91. local images_args=""
  92. case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
  93. all)
  94. images_args="--no-trunc -a"
  95. ;;
  96. non-intermediate)
  97. images_args="--no-trunc"
  98. ;;
  99. esac
  100. local repo_print_command
  101. if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then
  102. repo_print_command='print $1; print $1":"$2'
  103. else
  104. repo_print_command='print $1'
  105. fi
  106. local awk_script
  107. case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
  108. all|non-intermediate)
  109. awk_script='NR>1 { print $3; if ($1 != "<none>") { '"$repo_print_command"' } }'
  110. ;;
  111. none|*)
  112. awk_script='NR>1 && $1 != "<none>" { '"$repo_print_command"' }'
  113. ;;
  114. esac
  115. local images=$(__docker_q images $images_args | awk "$awk_script")
  116. COMPREPLY=( $(compgen -W "$images" -- "$cur") )
  117. __ltrim_colon_completions "$cur"
  118. }
  119. __docker_complete_image_repos() {
  120. local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')"
  121. COMPREPLY=( $(compgen -W "$repos" -- "$cur") )
  122. }
  123. __docker_complete_image_repos_and_tags() {
  124. local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')"
  125. COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") )
  126. __ltrim_colon_completions "$cur"
  127. }
  128. __docker_complete_containers_and_images() {
  129. __docker_complete_containers_all
  130. local containers=( "${COMPREPLY[@]}" )
  131. __docker_complete_images
  132. COMPREPLY+=( "${containers[@]}" )
  133. }
  134. # Returns the names and optionally IDs of networks.
  135. # The selection can be narrowed by an optional filter parameter, e.g. 'type=custom'
  136. __docker_networks() {
  137. local filter="$1"
  138. # By default, only network names are completed.
  139. # Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete network IDs.
  140. local fields='$2'
  141. [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] && fields='$1,$2'
  142. __docker_q network ls --no-trunc ${filter:+-f "$filter"} | awk "NR>1 {print $fields}"
  143. #__docker_q network ls --no-trunc | awk "NR>1 {print $fields}"
  144. }
  145. __docker_complete_networks() {
  146. COMPREPLY=( $(compgen -W "$(__docker_networks $@)" -- "$cur") )
  147. }
  148. __docker_complete_network_ids() {
  149. COMPREPLY=( $(compgen -W "$(__docker_q network ls -q --no-trunc)" -- "$cur") )
  150. }
  151. __docker_complete_network_names() {
  152. COMPREPLY=( $(compgen -W "$(__docker_q network ls | awk 'NR>1 {print $2}')" -- "$cur") )
  153. }
  154. __docker_complete_containers_in_network() {
  155. local containers=$(__docker_q network inspect -f '{{range $i, $c := .Containers}}{{$i}} {{$c.Name}} {{end}}' "$1")
  156. COMPREPLY=( $(compgen -W "$containers" -- "$cur") )
  157. }
  158. __docker_complete_volumes() {
  159. COMPREPLY=( $(compgen -W "$(__docker_q volume ls -q)" -- "$cur") )
  160. }
  161. __docker_plugins() {
  162. __docker_q info | sed -n "/^Plugins/,/^[^ ]/s/ $1: //p"
  163. }
  164. __docker_complete_plugins() {
  165. COMPREPLY=( $(compgen -W "$(__docker_plugins $1)" -- "$cur") )
  166. }
  167. __docker_runtimes() {
  168. __docker_q info | sed -n 's/^Runtimes: \(.*\)/\1/p'
  169. }
  170. __docker_complete_runtimes() {
  171. COMPREPLY=( $(compgen -W "$(__docker_runtimes)" -- "$cur") )
  172. }
  173. # Returns a list of all nodes. Additional arguments to `docker node`
  174. # may be specified in order to filter the node list, e.g.
  175. # `__docker_nodes --filter role=manager`
  176. # By default, only node names are completed.
  177. # Set DOCKER_COMPLETION_SHOW_NODE_IDS=yes to also complete node IDs.
  178. # An optional first argument `--id|--name` may be used to limit
  179. # the output to the IDs or names of matching nodes. This setting takes
  180. # precedence over the environment setting.
  181. __docker_nodes() {
  182. local fields='$2' # default: node name only
  183. [ "${DOCKER_COMPLETION_SHOW_NODE_IDS}" = yes ] && fields='$1,$2' # ID and name
  184. if [ "$1" = "--id" ] ; then
  185. fields='$1' # IDs only
  186. shift
  187. elif [ "$1" = "--name" ] ; then
  188. fields='$2' # names only
  189. shift
  190. fi
  191. __docker_q node ls "$@" | tr -d '*' | awk "NR>1 {print $fields}"
  192. }
  193. # Applies completion of nodes based on the current value of `$cur` or
  194. # the value of the optional first argument `--cur`, if given.
  195. # Additional filters may be appended, see `__docker_nodes`.
  196. __docker_complete_nodes() {
  197. local current=$cur
  198. if [ "$1" = "--cur" ] ; then
  199. current="$2"
  200. shift 2
  201. fi
  202. COMPREPLY=( $(compgen -W "$(__docker_nodes "$@")" -- "$current") )
  203. }
  204. __docker_complete_nodes_plus_self() {
  205. __docker_complete_nodes "$@"
  206. COMPREPLY+=( self )
  207. }
  208. # Returns a list of all services. Additional arguments to `docker service ls`
  209. # may be specified in order to filter the service list, e.g.
  210. # `__docker_services --filter name=xxx`
  211. # By default, only node names are completed.
  212. # Set DOCKER_COMPLETION_SHOW_SERVICE_IDS=yes to also complete service IDs.
  213. # An optional first argument `--id|--name` may be used to limit
  214. # the output to the IDs or names of matching services. This setting takes
  215. # precedence over the environment setting.
  216. __docker_services() {
  217. local fields='$2' # default: service name only
  218. [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name
  219. if [ "$1" = "--id" ] ; then
  220. fields='$1' # IDs only
  221. shift
  222. elif [ "$1" = "--name" ] ; then
  223. fields='$2' # names only
  224. shift
  225. fi
  226. __docker_q service ls "$@" | awk "NR>1 {print $fields}"
  227. }
  228. # Applies completion of services based on the current value of `$cur` or
  229. # the value of the optional first argument `--cur`, if given.
  230. # Additional filters may be appended, see `__docker_services`.
  231. __docker_complete_services() {
  232. local current=$cur
  233. if [ "$1" = "--cur" ] ; then
  234. current="$2"
  235. shift 2
  236. fi
  237. COMPREPLY=( $(compgen -W "$(__docker_services "$@")" -- "$current") )
  238. }
  239. # Appends the word passed as an argument to every word in `$COMPREPLY`.
  240. # Normally you do this with `compgen -S`. This function exists so that you can use
  241. # the __docker_complete_XXX functions in cases where you need a suffix.
  242. __docker_append_to_completions() {
  243. COMPREPLY=( ${COMPREPLY[@]/%/"$1"} )
  244. }
  245. # Finds the position of the first word that is neither option nor an option's argument.
  246. # If there are options that require arguments, you should pass a glob describing those
  247. # options, e.g. "--option1|-o|--option2"
  248. # Use this function to restrict completions to exact positions after the argument list.
  249. __docker_pos_first_nonflag() {
  250. local argument_flags=$1
  251. local counter=$((${subcommand_pos:-${command_pos}} + 1))
  252. while [ $counter -le $cword ]; do
  253. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  254. (( counter++ ))
  255. # eat "=" in case of --option=arg syntax
  256. [ "${words[$counter]}" = "=" ] && (( counter++ ))
  257. else
  258. case "${words[$counter]}" in
  259. -*)
  260. ;;
  261. *)
  262. break
  263. ;;
  264. esac
  265. fi
  266. # Bash splits words at "=", retaining "=" as a word, examples:
  267. # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
  268. while [ "${words[$counter + 1]}" = "=" ] ; do
  269. counter=$(( counter + 2))
  270. done
  271. (( counter++ ))
  272. done
  273. echo $counter
  274. }
  275. # If we are currently completing the value of a map option (key=value)
  276. # which matches the extglob given as an argument, returns key.
  277. # This function is needed for key-specific completions.
  278. __docker_map_key_of_current_option() {
  279. local glob="$1"
  280. local key glob_pos
  281. if [ "$cur" = "=" ] ; then # key= case
  282. key="$prev"
  283. glob_pos=$((cword - 2))
  284. elif [[ $cur == *=* ]] ; then # key=value case (OSX)
  285. key=${cur%=*}
  286. glob_pos=$((cword - 1))
  287. elif [ "$prev" = "=" ] ; then
  288. key=${words[$cword - 2]} # key=value case
  289. glob_pos=$((cword - 3))
  290. else
  291. return
  292. fi
  293. [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax
  294. [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key"
  295. }
  296. # Returns the value of the first option matching option_glob.
  297. # Valid values for option_glob are option names like '--log-level' and
  298. # globs like '--log-level|-l'
  299. # Only positions between the command and the current word are considered.
  300. __docker_value_of_option() {
  301. local option_extglob=$(__docker_to_extglob "$1")
  302. local counter=$((command_pos + 1))
  303. while [ $counter -lt $cword ]; do
  304. case ${words[$counter]} in
  305. $option_extglob )
  306. echo ${words[$counter + 1]}
  307. break
  308. ;;
  309. esac
  310. (( counter++ ))
  311. done
  312. }
  313. # Transforms a multiline list of strings into a single line string
  314. # with the words separated by "|".
  315. # This is used to prepare arguments to __docker_pos_first_nonflag().
  316. __docker_to_alternatives() {
  317. local parts=( $1 )
  318. local IFS='|'
  319. echo "${parts[*]}"
  320. }
  321. # Transforms a multiline list of options into an extglob pattern
  322. # suitable for use in case statements.
  323. __docker_to_extglob() {
  324. local extglob=$( __docker_to_alternatives "$1" )
  325. echo "@($extglob)"
  326. }
  327. # Subcommand processing.
  328. # Locates the first occurrence of any of the subcommands contained in the
  329. # first argument. In case of a match, calls the corresponding completion
  330. # function and returns 0.
  331. # If no match is found, 1 is returned. The calling function can then
  332. # continue processing its completion.
  333. #
  334. # TODO if the preceding command has options that accept arguments and an
  335. # argument is equal ot one of the subcommands, this is falsely detected as
  336. # a match.
  337. __docker_subcommands() {
  338. local subcommands="$1"
  339. local counter=$(($command_pos + 1))
  340. while [ $counter -lt $cword ]; do
  341. case "${words[$counter]}" in
  342. $(__docker_to_extglob "$subcommands") )
  343. subcommand_pos=$counter
  344. local subcommand=${words[$counter]}
  345. local completions_func=_docker_${command}_${subcommand}
  346. declare -F $completions_func >/dev/null && $completions_func
  347. return 0
  348. ;;
  349. esac
  350. (( counter++ ))
  351. done
  352. return 1
  353. }
  354. # suppress trailing whitespace
  355. __docker_nospace() {
  356. # compopt is not available in ancient bash versions
  357. type compopt &>/dev/null && compopt -o nospace
  358. }
  359. __docker_complete_resolved_hostname() {
  360. command -v host >/dev/null 2>&1 || return
  361. COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
  362. }
  363. __docker_local_interfaces() {
  364. command -v ip >/dev/null 2>&1 || return
  365. ip addr show scope global 2>/dev/null | sed -n 's| \+inet \([0-9.]\+\).* \([^ ]\+\)|\1 \2|p'
  366. }
  367. __docker_complete_local_interfaces() {
  368. local additional_interface
  369. if [ "$1" = "--add" ] ; then
  370. additional_interface="$2"
  371. fi
  372. COMPREPLY=( $( compgen -W "$(__docker_local_interfaces) $additional_interface" -- "$cur" ) )
  373. }
  374. __docker_complete_capabilities() {
  375. # The list of capabilities is defined in types.go, ALL was added manually.
  376. COMPREPLY=( $( compgen -W "
  377. ALL
  378. AUDIT_CONTROL
  379. AUDIT_WRITE
  380. AUDIT_READ
  381. BLOCK_SUSPEND
  382. CHOWN
  383. DAC_OVERRIDE
  384. DAC_READ_SEARCH
  385. FOWNER
  386. FSETID
  387. IPC_LOCK
  388. IPC_OWNER
  389. KILL
  390. LEASE
  391. LINUX_IMMUTABLE
  392. MAC_ADMIN
  393. MAC_OVERRIDE
  394. MKNOD
  395. NET_ADMIN
  396. NET_BIND_SERVICE
  397. NET_BROADCAST
  398. NET_RAW
  399. SETFCAP
  400. SETGID
  401. SETPCAP
  402. SETUID
  403. SYS_ADMIN
  404. SYS_BOOT
  405. SYS_CHROOT
  406. SYSLOG
  407. SYS_MODULE
  408. SYS_NICE
  409. SYS_PACCT
  410. SYS_PTRACE
  411. SYS_RAWIO
  412. SYS_RESOURCE
  413. SYS_TIME
  414. SYS_TTY_CONFIG
  415. WAKE_ALARM
  416. " -- "$cur" ) )
  417. }
  418. __docker_complete_detach-keys() {
  419. case "$prev" in
  420. --detach-keys)
  421. case "$cur" in
  422. *,)
  423. COMPREPLY=( $( compgen -W "${cur}ctrl-" -- "$cur" ) )
  424. ;;
  425. *)
  426. COMPREPLY=( $( compgen -W "ctrl-" -- "$cur" ) )
  427. ;;
  428. esac
  429. __docker_nospace
  430. return
  431. ;;
  432. esac
  433. return 1
  434. }
  435. __docker_complete_isolation() {
  436. COMPREPLY=( $( compgen -W "default hyperv process" -- "$cur" ) )
  437. }
  438. __docker_complete_log_drivers() {
  439. COMPREPLY=( $( compgen -W "
  440. awslogs
  441. etwlogs
  442. fluentd
  443. gcplogs
  444. gelf
  445. journald
  446. json-file
  447. none
  448. splunk
  449. syslog
  450. " -- "$cur" ) )
  451. }
  452. __docker_complete_log_options() {
  453. # see docs/reference/logging/index.md
  454. local awslogs_options="awslogs-region awslogs-group awslogs-stream"
  455. local fluentd_options="env fluentd-address fluentd-async-connect fluentd-buffer-limit fluentd-retry-wait fluentd-max-retries labels tag"
  456. local gcplogs_options="env gcp-log-cmd gcp-project labels"
  457. local gelf_options="env gelf-address gelf-compression-level gelf-compression-type labels tag"
  458. local journald_options="env labels tag"
  459. local json_file_options="env labels max-file max-size"
  460. local syslog_options="env labels syslog-address syslog-facility syslog-format syslog-tls-ca-cert syslog-tls-cert syslog-tls-key syslog-tls-skip-verify tag"
  461. local splunk_options="env labels splunk-caname splunk-capath splunk-format splunk-gzip splunk-gzip-level splunk-index splunk-insecureskipverify splunk-source splunk-sourcetype splunk-token splunk-url splunk-verify-connection tag"
  462. local all_options="$fluentd_options $gcplogs_options $gelf_options $journald_options $json_file_options $syslog_options $splunk_options"
  463. case $(__docker_value_of_option --log-driver) in
  464. '')
  465. COMPREPLY=( $( compgen -W "$all_options" -S = -- "$cur" ) )
  466. ;;
  467. awslogs)
  468. COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) )
  469. ;;
  470. fluentd)
  471. COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) )
  472. ;;
  473. gcplogs)
  474. COMPREPLY=( $( compgen -W "$gcplogs_options" -S = -- "$cur" ) )
  475. ;;
  476. gelf)
  477. COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) )
  478. ;;
  479. journald)
  480. COMPREPLY=( $( compgen -W "$journald_options" -S = -- "$cur" ) )
  481. ;;
  482. json-file)
  483. COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) )
  484. ;;
  485. syslog)
  486. COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) )
  487. ;;
  488. splunk)
  489. COMPREPLY=( $( compgen -W "$splunk_options" -S = -- "$cur" ) )
  490. ;;
  491. *)
  492. return
  493. ;;
  494. esac
  495. __docker_nospace
  496. }
  497. __docker_complete_log_driver_options() {
  498. local key=$(__docker_map_key_of_current_option '--log-opt')
  499. case "$key" in
  500. fluentd-async-connect)
  501. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  502. return
  503. ;;
  504. gelf-address)
  505. COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur##*=}" ) )
  506. __docker_nospace
  507. return
  508. ;;
  509. gelf-compression-level)
  510. COMPREPLY=( $( compgen -W "1 2 3 4 5 6 7 8 9" -- "${cur##*=}" ) )
  511. return
  512. ;;
  513. gelf-compression-type)
  514. COMPREPLY=( $( compgen -W "gzip none zlib" -- "${cur##*=}" ) )
  515. return
  516. ;;
  517. syslog-address)
  518. COMPREPLY=( $( compgen -W "tcp:// tcp+tls:// udp:// unix://" -- "${cur##*=}" ) )
  519. __docker_nospace
  520. __ltrim_colon_completions "${cur}"
  521. return
  522. ;;
  523. syslog-facility)
  524. COMPREPLY=( $( compgen -W "
  525. auth
  526. authpriv
  527. cron
  528. daemon
  529. ftp
  530. kern
  531. local0
  532. local1
  533. local2
  534. local3
  535. local4
  536. local5
  537. local6
  538. local7
  539. lpr
  540. mail
  541. news
  542. syslog
  543. user
  544. uucp
  545. " -- "${cur##*=}" ) )
  546. return
  547. ;;
  548. syslog-format)
  549. COMPREPLY=( $( compgen -W "rfc3164 rfc5424 rfc5424micro" -- "${cur##*=}" ) )
  550. return
  551. ;;
  552. syslog-tls-ca-cert|syslog-tls-cert|syslog-tls-key)
  553. _filedir
  554. return
  555. ;;
  556. syslog-tls-skip-verify)
  557. COMPREPLY=( $( compgen -W "true" -- "${cur##*=}" ) )
  558. return
  559. ;;
  560. splunk-url)
  561. COMPREPLY=( $( compgen -W "http:// https://" -- "${cur##*=}" ) )
  562. __docker_nospace
  563. __ltrim_colon_completions "${cur}"
  564. return
  565. ;;
  566. splunk-gzip|splunk-insecureskipverify|splunk-verify-connection)
  567. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  568. return
  569. ;;
  570. splunk-format)
  571. COMPREPLY=( $( compgen -W "inline json raw" -- "${cur##*=}" ) )
  572. return
  573. ;;
  574. esac
  575. return 1
  576. }
  577. __docker_complete_log_levels() {
  578. COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) )
  579. }
  580. __docker_complete_restart() {
  581. case "$prev" in
  582. --restart)
  583. case "$cur" in
  584. on-failure:*)
  585. ;;
  586. *)
  587. COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") )
  588. ;;
  589. esac
  590. return
  591. ;;
  592. esac
  593. return 1
  594. }
  595. # a selection of the available signals that is most likely of interest in the
  596. # context of docker containers.
  597. __docker_complete_signals() {
  598. local signals=(
  599. SIGCONT
  600. SIGHUP
  601. SIGINT
  602. SIGKILL
  603. SIGQUIT
  604. SIGSTOP
  605. SIGTERM
  606. SIGUSR1
  607. SIGUSR2
  608. )
  609. COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) )
  610. }
  611. __docker_complete_user_group() {
  612. if [[ $cur == *:* ]] ; then
  613. COMPREPLY=( $(compgen -g -- "${cur#*:}") )
  614. else
  615. COMPREPLY=( $(compgen -u -S : -- "$cur") )
  616. __docker_nospace
  617. fi
  618. }
  619. # global options that may appear after the docker command
  620. _docker_docker() {
  621. local boolean_options="
  622. $global_boolean_options
  623. --help
  624. --version -v
  625. "
  626. case "$prev" in
  627. --config)
  628. _filedir -d
  629. return
  630. ;;
  631. --log-level|-l)
  632. __docker_complete_log_levels
  633. return
  634. ;;
  635. $(__docker_to_extglob "$global_options_with_args") )
  636. return
  637. ;;
  638. esac
  639. case "$cur" in
  640. -*)
  641. COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) )
  642. ;;
  643. *)
  644. local counter=$( __docker_pos_first_nonflag "$(__docker_to_extglob "$global_options_with_args")" )
  645. if [ $cword -eq $counter ]; then
  646. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  647. fi
  648. ;;
  649. esac
  650. }
  651. _docker_attach() {
  652. __docker_complete_detach-keys && return
  653. case "$cur" in
  654. -*)
  655. COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) )
  656. ;;
  657. *)
  658. local counter=$(__docker_pos_first_nonflag '--detach-keys')
  659. if [ $cword -eq $counter ]; then
  660. __docker_complete_containers_running
  661. fi
  662. ;;
  663. esac
  664. }
  665. _docker_build() {
  666. local options_with_args="
  667. --build-arg
  668. --cgroup-parent
  669. --cpuset-cpus
  670. --cpuset-mems
  671. --cpu-shares -c
  672. --cpu-period
  673. --cpu-quota
  674. --file -f
  675. --isolation
  676. --label
  677. --memory -m
  678. --memory-swap
  679. --shm-size
  680. --tag -t
  681. --ulimit
  682. "
  683. local boolean_options="
  684. --disable-content-trust=false
  685. --force-rm
  686. --help
  687. --no-cache
  688. --pull
  689. --quiet -q
  690. --rm
  691. "
  692. local all_options="$options_with_args $boolean_options"
  693. case "$prev" in
  694. --build-arg)
  695. COMPREPLY=( $( compgen -e -- "$cur" ) )
  696. __docker_nospace
  697. return
  698. ;;
  699. --file|-f)
  700. _filedir
  701. return
  702. ;;
  703. --isolation)
  704. __docker_complete_isolation
  705. return
  706. ;;
  707. --tag|-t)
  708. __docker_complete_image_repos_and_tags
  709. return
  710. ;;
  711. $(__docker_to_extglob "$options_with_args") )
  712. return
  713. ;;
  714. esac
  715. case "$cur" in
  716. -*)
  717. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  718. ;;
  719. *)
  720. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  721. if [ $cword -eq $counter ]; then
  722. _filedir -d
  723. fi
  724. ;;
  725. esac
  726. }
  727. _docker_commit() {
  728. case "$prev" in
  729. --author|-a|--change|-c|--message|-m)
  730. return
  731. ;;
  732. esac
  733. case "$cur" in
  734. -*)
  735. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) )
  736. ;;
  737. *)
  738. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  739. if [ $cword -eq $counter ]; then
  740. __docker_complete_containers_all
  741. return
  742. fi
  743. (( counter++ ))
  744. if [ $cword -eq $counter ]; then
  745. __docker_complete_image_repos_and_tags
  746. return
  747. fi
  748. ;;
  749. esac
  750. }
  751. _docker_cp() {
  752. case "$cur" in
  753. -*)
  754. COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) )
  755. ;;
  756. *)
  757. local counter=$(__docker_pos_first_nonflag)
  758. if [ $cword -eq $counter ]; then
  759. case "$cur" in
  760. *:)
  761. return
  762. ;;
  763. *)
  764. # combined container and filename completion
  765. _filedir
  766. local files=( ${COMPREPLY[@]} )
  767. __docker_complete_containers_all
  768. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  769. local containers=( ${COMPREPLY[@]} )
  770. COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) )
  771. if [[ "$COMPREPLY" == *: ]]; then
  772. __docker_nospace
  773. fi
  774. return
  775. ;;
  776. esac
  777. fi
  778. (( counter++ ))
  779. if [ $cword -eq $counter ]; then
  780. if [ -e "$prev" ]; then
  781. __docker_complete_containers_all
  782. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  783. __docker_nospace
  784. else
  785. _filedir
  786. fi
  787. return
  788. fi
  789. ;;
  790. esac
  791. }
  792. _docker_create() {
  793. _docker_run
  794. }
  795. _docker_daemon() {
  796. local boolean_options="
  797. $global_boolean_options
  798. --disable-legacy-registry
  799. --help
  800. --icc=false
  801. --ip-forward=false
  802. --ip-masq=false
  803. --iptables=false
  804. --ipv6
  805. --live-restore
  806. --raw-logs
  807. --selinux-enabled
  808. --userland-proxy=false
  809. "
  810. local options_with_args="
  811. $global_options_with_args
  812. --add-runtime
  813. --api-cors-header
  814. --authorization-plugin
  815. --bip
  816. --bridge -b
  817. --cgroup-parent
  818. --cluster-advertise
  819. --cluster-store
  820. --cluster-store-opt
  821. --config-file
  822. --containerd
  823. --default-gateway
  824. --default-gateway-v6
  825. --default-ulimit
  826. --dns
  827. --dns-search
  828. --dns-opt
  829. --exec-opt
  830. --exec-root
  831. --fixed-cidr
  832. --fixed-cidr-v6
  833. --graph -g
  834. --group -G
  835. --insecure-registry
  836. --ip
  837. --label
  838. --log-driver
  839. --log-opt
  840. --max-concurrent-downloads
  841. --max-concurrent-uploads
  842. --mtu
  843. --oom-score-adjust
  844. --pidfile -p
  845. --registry-mirror
  846. --storage-driver -s
  847. --storage-opt
  848. --userns-remap
  849. "
  850. __docker_complete_log_driver_options && return
  851. key=$(__docker_map_key_of_current_option '--cluster-store-opt')
  852. case "$key" in
  853. kv.*file)
  854. cur=${cur##*=}
  855. _filedir
  856. return
  857. ;;
  858. esac
  859. local key=$(__docker_map_key_of_current_option '--storage-opt')
  860. case "$key" in
  861. dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion)
  862. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  863. return
  864. ;;
  865. dm.fs)
  866. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) )
  867. return
  868. ;;
  869. dm.thinpooldev)
  870. cur=${cur##*=}
  871. _filedir
  872. return
  873. ;;
  874. esac
  875. case "$prev" in
  876. --authorization-plugin)
  877. __docker_complete_plugins Authorization
  878. return
  879. ;;
  880. --cluster-store)
  881. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  882. __docker_nospace
  883. return
  884. ;;
  885. --cluster-store-opt)
  886. COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) )
  887. __docker_nospace
  888. return
  889. ;;
  890. --exec-root|--graph|-g)
  891. _filedir -d
  892. return
  893. ;;
  894. --log-driver)
  895. __docker_complete_log_drivers
  896. return
  897. ;;
  898. --config-file|--containerd|--pidfile|-p|--tlscacert|--tlscert|--tlskey)
  899. _filedir
  900. return
  901. ;;
  902. --storage-driver|-s)
  903. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  904. return
  905. ;;
  906. --storage-opt)
  907. local btrfs_options="btrfs.min_space"
  908. local devicemapper_options="
  909. dm.basesize
  910. dm.blkdiscard
  911. dm.blocksize
  912. dm.fs
  913. dm.loopdatasize
  914. dm.loopmetadatasize
  915. dm.min_free_space
  916. dm.mkfsarg
  917. dm.mountopt
  918. dm.override_udev_sync_check
  919. dm.thinpooldev
  920. dm.use_deferred_deletion
  921. dm.use_deferred_removal
  922. "
  923. local zfs_options="zfs.fsname"
  924. case $(__docker_value_of_option '--storage-driver|-s') in
  925. '')
  926. COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) )
  927. ;;
  928. btrfs)
  929. COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) )
  930. ;;
  931. devicemapper)
  932. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  933. ;;
  934. zfs)
  935. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  936. ;;
  937. *)
  938. return
  939. ;;
  940. esac
  941. __docker_nospace
  942. return
  943. ;;
  944. --log-level|-l)
  945. __docker_complete_log_levels
  946. return
  947. ;;
  948. --log-opt)
  949. __docker_complete_log_options
  950. return
  951. ;;
  952. --userns-remap)
  953. __docker_complete_user_group
  954. return
  955. ;;
  956. $(__docker_to_extglob "$options_with_args") )
  957. return
  958. ;;
  959. esac
  960. case "$cur" in
  961. -*)
  962. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  963. ;;
  964. esac
  965. }
  966. _docker_diff() {
  967. case "$cur" in
  968. -*)
  969. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  970. ;;
  971. *)
  972. local counter=$(__docker_pos_first_nonflag)
  973. if [ $cword -eq $counter ]; then
  974. __docker_complete_containers_all
  975. fi
  976. ;;
  977. esac
  978. }
  979. _docker_events() {
  980. local key=$(__docker_map_key_of_current_option '-f|--filter')
  981. case "$key" in
  982. container)
  983. cur="${cur##*=}"
  984. __docker_complete_containers_all
  985. return
  986. ;;
  987. daemon)
  988. local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
  989. COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
  990. return
  991. ;;
  992. event)
  993. COMPREPLY=( $( compgen -W "
  994. attach
  995. commit
  996. connect
  997. copy
  998. create
  999. delete
  1000. destroy
  1001. detach
  1002. die
  1003. disconnect
  1004. exec_create
  1005. exec_detach
  1006. exec_start
  1007. export
  1008. health_status
  1009. import
  1010. kill
  1011. load
  1012. mount
  1013. oom
  1014. pause
  1015. pull
  1016. push
  1017. reload
  1018. rename
  1019. resize
  1020. restart
  1021. save
  1022. start
  1023. stop
  1024. tag
  1025. top
  1026. unmount
  1027. unpause
  1028. untag
  1029. update
  1030. " -- "${cur##*=}" ) )
  1031. return
  1032. ;;
  1033. image)
  1034. cur="${cur##*=}"
  1035. __docker_complete_images
  1036. return
  1037. ;;
  1038. network)
  1039. cur="${cur##*=}"
  1040. __docker_complete_networks
  1041. return
  1042. ;;
  1043. type)
  1044. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  1045. return
  1046. ;;
  1047. volume)
  1048. cur="${cur##*=}"
  1049. __docker_complete_volumes
  1050. return
  1051. ;;
  1052. esac
  1053. case "$prev" in
  1054. --filter|-f)
  1055. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  1056. __docker_nospace
  1057. return
  1058. ;;
  1059. --since|--until)
  1060. return
  1061. ;;
  1062. esac
  1063. case "$cur" in
  1064. -*)
  1065. COMPREPLY=( $( compgen -W "--filter -f --help --since --until --format" -- "$cur" ) )
  1066. ;;
  1067. esac
  1068. }
  1069. _docker_exec() {
  1070. __docker_complete_detach-keys && return
  1071. case "$prev" in
  1072. --user|-u)
  1073. __docker_complete_user_group
  1074. return
  1075. ;;
  1076. esac
  1077. case "$cur" in
  1078. -*)
  1079. COMPREPLY=( $( compgen -W "--detach -d --detach-keys --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  1080. ;;
  1081. *)
  1082. __docker_complete_containers_running
  1083. ;;
  1084. esac
  1085. }
  1086. _docker_export() {
  1087. case "$cur" in
  1088. -*)
  1089. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1090. ;;
  1091. *)
  1092. local counter=$(__docker_pos_first_nonflag)
  1093. if [ $cword -eq $counter ]; then
  1094. __docker_complete_containers_all
  1095. fi
  1096. ;;
  1097. esac
  1098. }
  1099. _docker_help() {
  1100. local counter=$(__docker_pos_first_nonflag)
  1101. if [ $cword -eq $counter ]; then
  1102. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  1103. fi
  1104. }
  1105. _docker_history() {
  1106. case "$cur" in
  1107. -*)
  1108. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  1109. ;;
  1110. *)
  1111. local counter=$(__docker_pos_first_nonflag)
  1112. if [ $cword -eq $counter ]; then
  1113. __docker_complete_images
  1114. fi
  1115. ;;
  1116. esac
  1117. }
  1118. _docker_images() {
  1119. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1120. case "$key" in
  1121. before)
  1122. cur="${cur##*=}"
  1123. __docker_complete_images
  1124. return
  1125. ;;
  1126. dangling)
  1127. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1128. return
  1129. ;;
  1130. label)
  1131. return
  1132. ;;
  1133. since)
  1134. cur="${cur##*=}"
  1135. __docker_complete_images
  1136. return
  1137. ;;
  1138. esac
  1139. case "$prev" in
  1140. --filter|-f)
  1141. COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) )
  1142. __docker_nospace
  1143. return
  1144. ;;
  1145. --format)
  1146. return
  1147. ;;
  1148. esac
  1149. case "$cur" in
  1150. -*)
  1151. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1152. ;;
  1153. =)
  1154. return
  1155. ;;
  1156. *)
  1157. __docker_complete_image_repos
  1158. ;;
  1159. esac
  1160. }
  1161. _docker_import() {
  1162. case "$prev" in
  1163. --change|-c|--message|-m)
  1164. return
  1165. ;;
  1166. esac
  1167. case "$cur" in
  1168. -*)
  1169. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1170. ;;
  1171. *)
  1172. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1173. if [ $cword -eq $counter ]; then
  1174. return
  1175. fi
  1176. (( counter++ ))
  1177. if [ $cword -eq $counter ]; then
  1178. __docker_complete_image_repos_and_tags
  1179. return
  1180. fi
  1181. ;;
  1182. esac
  1183. }
  1184. _docker_info() {
  1185. case "$prev" in
  1186. --format|-f)
  1187. return
  1188. ;;
  1189. esac
  1190. case "$cur" in
  1191. -*)
  1192. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1193. ;;
  1194. esac
  1195. }
  1196. _docker_inspect() {
  1197. case "$prev" in
  1198. --format|-f)
  1199. return
  1200. ;;
  1201. --type)
  1202. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  1203. return
  1204. ;;
  1205. esac
  1206. case "$cur" in
  1207. -*)
  1208. COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) )
  1209. ;;
  1210. *)
  1211. case $(__docker_value_of_option --type) in
  1212. '')
  1213. __docker_complete_containers_and_images
  1214. ;;
  1215. container)
  1216. __docker_complete_containers_all
  1217. ;;
  1218. image)
  1219. __docker_complete_images
  1220. ;;
  1221. esac
  1222. esac
  1223. }
  1224. _docker_kill() {
  1225. case "$prev" in
  1226. --signal|-s)
  1227. __docker_complete_signals
  1228. return
  1229. ;;
  1230. esac
  1231. case "$cur" in
  1232. -*)
  1233. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  1234. ;;
  1235. *)
  1236. __docker_complete_containers_running
  1237. ;;
  1238. esac
  1239. }
  1240. _docker_load() {
  1241. case "$prev" in
  1242. --input|-i)
  1243. _filedir
  1244. return
  1245. ;;
  1246. esac
  1247. case "$cur" in
  1248. -*)
  1249. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1250. ;;
  1251. esac
  1252. }
  1253. _docker_login() {
  1254. case "$prev" in
  1255. --password|-p|--username|-u)
  1256. return
  1257. ;;
  1258. esac
  1259. case "$cur" in
  1260. -*)
  1261. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  1262. ;;
  1263. esac
  1264. }
  1265. _docker_logout() {
  1266. case "$cur" in
  1267. -*)
  1268. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1269. ;;
  1270. esac
  1271. }
  1272. _docker_logs() {
  1273. case "$prev" in
  1274. --since|--tail)
  1275. return
  1276. ;;
  1277. esac
  1278. case "$cur" in
  1279. -*)
  1280. COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  1281. ;;
  1282. *)
  1283. local counter=$(__docker_pos_first_nonflag '--since|--tail')
  1284. if [ $cword -eq $counter ]; then
  1285. __docker_complete_containers_all
  1286. fi
  1287. ;;
  1288. esac
  1289. }
  1290. _docker_network_connect() {
  1291. local options_with_args="
  1292. --alias
  1293. --ip
  1294. --ip6
  1295. --link
  1296. --link-local-ip
  1297. "
  1298. local boolean_options="
  1299. --help
  1300. "
  1301. case "$prev" in
  1302. --link)
  1303. case "$cur" in
  1304. *:*)
  1305. ;;
  1306. *)
  1307. __docker_complete_containers_running
  1308. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1309. __docker_nospace
  1310. ;;
  1311. esac
  1312. return
  1313. ;;
  1314. $(__docker_to_extglob "$options_with_args") )
  1315. return
  1316. ;;
  1317. esac
  1318. case "$cur" in
  1319. -*)
  1320. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1321. ;;
  1322. *)
  1323. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1324. if [ $cword -eq $counter ]; then
  1325. __docker_complete_networks
  1326. elif [ $cword -eq $(($counter + 1)) ]; then
  1327. __docker_complete_containers_all
  1328. fi
  1329. ;;
  1330. esac
  1331. }
  1332. _docker_network_create() {
  1333. case "$prev" in
  1334. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  1335. return
  1336. ;;
  1337. --ipam-driver)
  1338. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  1339. return
  1340. ;;
  1341. --driver|-d)
  1342. local plugins="$(__docker_plugins Network) macvlan"
  1343. # remove drivers that allow one instance only
  1344. plugins=${plugins/ host / }
  1345. plugins=${plugins/ null / }
  1346. COMPREPLY=( $(compgen -W "$plugins" -- "$cur") )
  1347. return
  1348. ;;
  1349. --label)
  1350. return
  1351. ;;
  1352. esac
  1353. case "$cur" in
  1354. -*)
  1355. COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  1356. ;;
  1357. esac
  1358. }
  1359. _docker_network_disconnect() {
  1360. case "$cur" in
  1361. -*)
  1362. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1363. ;;
  1364. *)
  1365. local counter=$(__docker_pos_first_nonflag)
  1366. if [ $cword -eq $counter ]; then
  1367. __docker_complete_networks
  1368. elif [ $cword -eq $(($counter + 1)) ]; then
  1369. __docker_complete_containers_in_network "$prev"
  1370. fi
  1371. ;;
  1372. esac
  1373. }
  1374. _docker_network_inspect() {
  1375. case "$prev" in
  1376. --format|-f)
  1377. return
  1378. ;;
  1379. esac
  1380. case "$cur" in
  1381. -*)
  1382. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1383. ;;
  1384. *)
  1385. __docker_complete_networks
  1386. esac
  1387. }
  1388. _docker_network_ls() {
  1389. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1390. case "$key" in
  1391. driver)
  1392. local plugins=" $(__docker_plugins Network) "
  1393. COMPREPLY=( $(compgen -W "$plugins" -- "${cur##*=}") )
  1394. return
  1395. ;;
  1396. id)
  1397. cur="${cur##*=}"
  1398. __docker_complete_network_ids
  1399. return
  1400. ;;
  1401. name)
  1402. cur="${cur##*=}"
  1403. __docker_complete_network_names
  1404. return
  1405. ;;
  1406. type)
  1407. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  1408. return
  1409. ;;
  1410. esac
  1411. case "$prev" in
  1412. --filter|-f)
  1413. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  1414. __docker_nospace
  1415. return
  1416. ;;
  1417. --format)
  1418. return
  1419. ;;
  1420. esac
  1421. case "$cur" in
  1422. -*)
  1423. COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1424. ;;
  1425. esac
  1426. }
  1427. _docker_network_rm() {
  1428. case "$cur" in
  1429. -*)
  1430. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1431. ;;
  1432. *)
  1433. __docker_complete_networks type=custom
  1434. esac
  1435. }
  1436. _docker_network() {
  1437. local subcommands="
  1438. connect
  1439. create
  1440. disconnect
  1441. inspect
  1442. ls
  1443. rm
  1444. "
  1445. __docker_subcommands "$subcommands" && return
  1446. case "$cur" in
  1447. -*)
  1448. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1449. ;;
  1450. *)
  1451. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1452. ;;
  1453. esac
  1454. }
  1455. _docker_service() {
  1456. local subcommands="
  1457. create
  1458. inspect
  1459. ls list
  1460. rm remove
  1461. scale
  1462. ps
  1463. update
  1464. "
  1465. __docker_subcommands "$subcommands" && return
  1466. case "$cur" in
  1467. -*)
  1468. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1469. ;;
  1470. *)
  1471. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1472. ;;
  1473. esac
  1474. }
  1475. _docker_service_create() {
  1476. _docker_service_update
  1477. }
  1478. _docker_service_inspect() {
  1479. case "$prev" in
  1480. --format|-f)
  1481. return
  1482. ;;
  1483. esac
  1484. case "$cur" in
  1485. -*)
  1486. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  1487. ;;
  1488. *)
  1489. __docker_complete_services
  1490. esac
  1491. }
  1492. _docker_service_list() {
  1493. _docker_service_ls
  1494. }
  1495. _docker_service_ls() {
  1496. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1497. case "$key" in
  1498. id)
  1499. __docker_complete_services --cur "${cur##*=}" --id
  1500. return
  1501. ;;
  1502. name)
  1503. __docker_complete_services --cur "${cur##*=}" --name
  1504. return
  1505. ;;
  1506. esac
  1507. case "$prev" in
  1508. --filter|-f)
  1509. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  1510. __docker_nospace
  1511. return
  1512. ;;
  1513. esac
  1514. case "$cur" in
  1515. -*)
  1516. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1517. ;;
  1518. esac
  1519. }
  1520. _docker_service_remove() {
  1521. _docker_service_rm
  1522. }
  1523. _docker_service_rm() {
  1524. case "$cur" in
  1525. -*)
  1526. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1527. ;;
  1528. *)
  1529. __docker_complete_services
  1530. esac
  1531. }
  1532. _docker_service_scale() {
  1533. case "$cur" in
  1534. -*)
  1535. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1536. ;;
  1537. *)
  1538. __docker_complete_services
  1539. __docker_append_to_completions "="
  1540. __docker_nospace
  1541. ;;
  1542. esac
  1543. }
  1544. _docker_service_ps() {
  1545. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1546. case "$key" in
  1547. desired-state)
  1548. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  1549. return
  1550. ;;
  1551. name)
  1552. __docker_complete_services --cur "${cur##*=}" --name
  1553. return
  1554. ;;
  1555. esac
  1556. case "$prev" in
  1557. --filter|-f)
  1558. COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) )
  1559. __docker_nospace
  1560. return
  1561. ;;
  1562. esac
  1563. case "$cur" in
  1564. -*)
  1565. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  1566. ;;
  1567. *)
  1568. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  1569. if [ $cword -eq $counter ]; then
  1570. __docker_complete_services
  1571. fi
  1572. ;;
  1573. esac
  1574. }
  1575. _docker_service_update() {
  1576. local $subcommand="${words[$subcommand_pos]}"
  1577. local options_with_args="
  1578. --constraint
  1579. --endpoint-mode
  1580. --env -e
  1581. --group-add
  1582. --label -l
  1583. --limit-cpu
  1584. --limit-memory
  1585. --log-driver
  1586. --log-opt
  1587. --mount
  1588. --name
  1589. --network
  1590. --publish -p
  1591. --replicas
  1592. --reserve-cpu
  1593. --reserve-memory
  1594. --restart-condition
  1595. --restart-delay
  1596. --restart-max-attempts
  1597. --restart-window
  1598. --stop-grace-period
  1599. --update-delay
  1600. --update-failure-action
  1601. --update-parallelism
  1602. --user -u
  1603. --workdir -w
  1604. "
  1605. local boolean_options="
  1606. --help
  1607. --with-registry-auth
  1608. "
  1609. __docker_complete_log_driver_options && return
  1610. if [ "$subcommand" = "create" ] ; then
  1611. options_with_args="$options_with_args
  1612. --container-label
  1613. --mode
  1614. "
  1615. case "$prev" in
  1616. --mode)
  1617. COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) )
  1618. return
  1619. ;;
  1620. esac
  1621. fi
  1622. if [ "$subcommand" = "update" ] ; then
  1623. options_with_args="$options_with_args
  1624. --arg
  1625. --container-label-add
  1626. --container-label-rm
  1627. --group-rm
  1628. --image
  1629. "
  1630. case "$prev" in
  1631. --group-rm)
  1632. COMPREPLY=( $(compgen -g -- "$cur") )
  1633. return
  1634. ;;
  1635. --image)
  1636. __docker_complete_image_repos_and_tags
  1637. return
  1638. ;;
  1639. esac
  1640. fi
  1641. case "$prev" in
  1642. --endpoint-mode)
  1643. COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) )
  1644. return
  1645. ;;
  1646. --env|-e)
  1647. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  1648. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1649. __docker_nospace
  1650. return
  1651. ;;
  1652. --group-add)
  1653. COMPREPLY=( $(compgen -g -- "$cur") )
  1654. return
  1655. ;;
  1656. --log-driver)
  1657. __docker_complete_log_drivers
  1658. return
  1659. ;;
  1660. --log-opt)
  1661. __docker_complete_log_options
  1662. return
  1663. ;;
  1664. --network)
  1665. __docker_complete_networks
  1666. return
  1667. ;;
  1668. --restart-condition)
  1669. COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) )
  1670. return
  1671. ;;
  1672. --user|-u)
  1673. __docker_complete_user_group
  1674. return
  1675. ;;
  1676. $(__docker_to_extglob "$options_with_args") )
  1677. return
  1678. ;;
  1679. esac
  1680. case "$cur" in
  1681. -*)
  1682. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1683. ;;
  1684. *)
  1685. if [ "$subcommand" = "update" ] ; then
  1686. __docker_complete_services
  1687. fi
  1688. esac
  1689. }
  1690. _docker_swarm() {
  1691. local subcommands="
  1692. init
  1693. join
  1694. join-token
  1695. leave
  1696. update
  1697. "
  1698. __docker_subcommands "$subcommands" && return
  1699. case "$cur" in
  1700. -*)
  1701. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1702. ;;
  1703. *)
  1704. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1705. ;;
  1706. esac
  1707. }
  1708. _docker_swarm_init() {
  1709. case "$prev" in
  1710. --advertise-addr)
  1711. if [[ $cur == *: ]] ; then
  1712. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1713. else
  1714. __docker_complete_local_interfaces
  1715. __docker_nospace
  1716. fi
  1717. return
  1718. ;;
  1719. --listen-addr)
  1720. if [[ $cur == *: ]] ; then
  1721. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1722. else
  1723. __docker_complete_local_interfaces --add 0.0.0.0
  1724. __docker_nospace
  1725. fi
  1726. return
  1727. ;;
  1728. esac
  1729. case "$cur" in
  1730. -*)
  1731. COMPREPLY=( $( compgen -W "--advertise-addr --force-new-cluster --help --listen-addr" -- "$cur" ) )
  1732. ;;
  1733. esac
  1734. }
  1735. _docker_swarm_join() {
  1736. case "$prev" in
  1737. --advertise-addr)
  1738. if [[ $cur == *: ]] ; then
  1739. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1740. else
  1741. __docker_complete_local_interfaces
  1742. __docker_nospace
  1743. fi
  1744. return
  1745. ;;
  1746. --listen-addr)
  1747. if [[ $cur == *: ]] ; then
  1748. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1749. else
  1750. __docker_complete_local_interfaces --add 0.0.0.0
  1751. __docker_nospace
  1752. fi
  1753. return
  1754. ;;
  1755. --token)
  1756. return
  1757. ;;
  1758. esac
  1759. case "$cur" in
  1760. -*)
  1761. COMPREPLY=( $( compgen -W "--advertise-addr --help --listen-addr --token" -- "$cur" ) )
  1762. ;;
  1763. *:)
  1764. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1765. ;;
  1766. esac
  1767. }
  1768. _docker_swarm_join-token() {
  1769. case "$cur" in
  1770. -*)
  1771. COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) )
  1772. ;;
  1773. *)
  1774. local counter=$( __docker_pos_first_nonflag )
  1775. if [ $cword -eq $counter ]; then
  1776. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  1777. fi
  1778. ;;
  1779. esac
  1780. }
  1781. _docker_swarm_leave() {
  1782. case "$cur" in
  1783. -*)
  1784. COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) )
  1785. ;;
  1786. esac
  1787. }
  1788. _docker_swarm_update() {
  1789. case "$prev" in
  1790. --cert-expiry|--dispatcher-heartbeat|--task-history-limit)
  1791. return
  1792. ;;
  1793. esac
  1794. case "$cur" in
  1795. -*)
  1796. COMPREPLY=( $( compgen -W "--cert-expiry --dispatcher-heartbeat --help --task-history-limit" -- "$cur" ) )
  1797. ;;
  1798. esac
  1799. }
  1800. _docker_node() {
  1801. local subcommands="
  1802. demote
  1803. inspect
  1804. ls list
  1805. promote
  1806. rm remove
  1807. ps
  1808. update
  1809. "
  1810. __docker_subcommands "$subcommands" && return
  1811. case "$cur" in
  1812. -*)
  1813. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1814. ;;
  1815. *)
  1816. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1817. ;;
  1818. esac
  1819. }
  1820. _docker_node_demote() {
  1821. case "$cur" in
  1822. -*)
  1823. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1824. ;;
  1825. *)
  1826. __docker_complete_nodes --filter role=manager
  1827. esac
  1828. }
  1829. _docker_node_inspect() {
  1830. case "$prev" in
  1831. --format|-f)
  1832. return
  1833. ;;
  1834. esac
  1835. case "$cur" in
  1836. -*)
  1837. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  1838. ;;
  1839. *)
  1840. __docker_complete_nodes_plus_self
  1841. esac
  1842. }
  1843. _docker_node_list() {
  1844. _docker_node_ls
  1845. }
  1846. _docker_node_ls() {
  1847. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1848. case "$key" in
  1849. id)
  1850. __docker_complete_nodes --cur "${cur##*=}" --id
  1851. return
  1852. ;;
  1853. name)
  1854. __docker_complete_nodes --cur "${cur##*=}" --name
  1855. return
  1856. ;;
  1857. esac
  1858. case "$prev" in
  1859. --filter|-f)
  1860. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  1861. __docker_nospace
  1862. return
  1863. ;;
  1864. esac
  1865. case "$cur" in
  1866. -*)
  1867. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1868. ;;
  1869. esac
  1870. }
  1871. _docker_node_promote() {
  1872. case "$cur" in
  1873. -*)
  1874. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1875. ;;
  1876. *)
  1877. __docker_complete_nodes --filter role=worker
  1878. esac
  1879. }
  1880. _docker_node_remove() {
  1881. _docker_node_rm
  1882. }
  1883. _docker_node_rm() {
  1884. case "$cur" in
  1885. -*)
  1886. COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) )
  1887. ;;
  1888. *)
  1889. __docker_complete_nodes
  1890. esac
  1891. }
  1892. _docker_node_ps() {
  1893. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1894. case "$key" in
  1895. desired-state)
  1896. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  1897. return
  1898. ;;
  1899. name)
  1900. __docker_complete_services --cur "${cur##*=}" --name
  1901. return
  1902. ;;
  1903. esac
  1904. case "$prev" in
  1905. --filter|-f)
  1906. COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) )
  1907. __docker_nospace
  1908. return
  1909. ;;
  1910. esac
  1911. case "$cur" in
  1912. -*)
  1913. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  1914. ;;
  1915. *)
  1916. __docker_complete_nodes_plus_self
  1917. ;;
  1918. esac
  1919. }
  1920. _docker_node_update() {
  1921. case "$prev" in
  1922. --availability)
  1923. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  1924. return
  1925. ;;
  1926. --role)
  1927. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  1928. return
  1929. ;;
  1930. --label-add|--label-rm)
  1931. return
  1932. ;;
  1933. esac
  1934. case "$cur" in
  1935. -*)
  1936. COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) )
  1937. ;;
  1938. *)
  1939. __docker_complete_nodes
  1940. esac
  1941. }
  1942. _docker_pause() {
  1943. case "$cur" in
  1944. -*)
  1945. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1946. ;;
  1947. *)
  1948. local counter=$(__docker_pos_first_nonflag)
  1949. if [ $cword -eq $counter ]; then
  1950. __docker_complete_containers_pauseable
  1951. fi
  1952. ;;
  1953. esac
  1954. }
  1955. _docker_port() {
  1956. case "$cur" in
  1957. -*)
  1958. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1959. ;;
  1960. *)
  1961. local counter=$(__docker_pos_first_nonflag)
  1962. if [ $cword -eq $counter ]; then
  1963. __docker_complete_containers_all
  1964. fi
  1965. ;;
  1966. esac
  1967. }
  1968. _docker_ps() {
  1969. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1970. case "$key" in
  1971. ancestor)
  1972. cur="${cur##*=}"
  1973. __docker_complete_images
  1974. return
  1975. ;;
  1976. before)
  1977. cur="${cur##*=}"
  1978. __docker_complete_containers_all
  1979. return
  1980. ;;
  1981. id)
  1982. cur="${cur##*=}"
  1983. __docker_complete_container_ids
  1984. return
  1985. ;;
  1986. is-task)
  1987. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  1988. return
  1989. ;;
  1990. name)
  1991. cur="${cur##*=}"
  1992. __docker_complete_container_names
  1993. return
  1994. ;;
  1995. network)
  1996. cur="${cur##*=}"
  1997. __docker_complete_networks
  1998. return
  1999. ;;
  2000. since)
  2001. cur="${cur##*=}"
  2002. __docker_complete_containers_all
  2003. return
  2004. ;;
  2005. status)
  2006. COMPREPLY=( $( compgen -W "created dead exited paused restarting running removing" -- "${cur##*=}" ) )
  2007. return
  2008. ;;
  2009. volume)
  2010. cur="${cur##*=}"
  2011. __docker_complete_volumes
  2012. return
  2013. ;;
  2014. esac
  2015. case "$prev" in
  2016. --filter|-f)
  2017. COMPREPLY=( $( compgen -S = -W "ancestor before exited id label name network since status volume" -- "$cur" ) )
  2018. __docker_nospace
  2019. return
  2020. ;;
  2021. --format|--last|-n)
  2022. return
  2023. ;;
  2024. esac
  2025. case "$cur" in
  2026. -*)
  2027. COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) )
  2028. ;;
  2029. esac
  2030. }
  2031. _docker_pull() {
  2032. case "$cur" in
  2033. -*)
  2034. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  2035. ;;
  2036. *)
  2037. local counter=$(__docker_pos_first_nonflag)
  2038. if [ $cword -eq $counter ]; then
  2039. for arg in "${COMP_WORDS[@]}"; do
  2040. case "$arg" in
  2041. --all-tags|-a)
  2042. __docker_complete_image_repos
  2043. return
  2044. ;;
  2045. esac
  2046. done
  2047. __docker_complete_image_repos_and_tags
  2048. fi
  2049. ;;
  2050. esac
  2051. }
  2052. _docker_push() {
  2053. case "$cur" in
  2054. -*)
  2055. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  2056. ;;
  2057. *)
  2058. local counter=$(__docker_pos_first_nonflag)
  2059. if [ $cword -eq $counter ]; then
  2060. __docker_complete_image_repos_and_tags
  2061. fi
  2062. ;;
  2063. esac
  2064. }
  2065. _docker_rename() {
  2066. case "$cur" in
  2067. -*)
  2068. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2069. ;;
  2070. *)
  2071. local counter=$(__docker_pos_first_nonflag)
  2072. if [ $cword -eq $counter ]; then
  2073. __docker_complete_containers_all
  2074. fi
  2075. ;;
  2076. esac
  2077. }
  2078. _docker_restart() {
  2079. case "$prev" in
  2080. --time|-t)
  2081. return
  2082. ;;
  2083. esac
  2084. case "$cur" in
  2085. -*)
  2086. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2087. ;;
  2088. *)
  2089. __docker_complete_containers_all
  2090. ;;
  2091. esac
  2092. }
  2093. _docker_rm() {
  2094. case "$cur" in
  2095. -*)
  2096. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  2097. ;;
  2098. *)
  2099. for arg in "${COMP_WORDS[@]}"; do
  2100. case "$arg" in
  2101. --force|-f)
  2102. __docker_complete_containers_all
  2103. return
  2104. ;;
  2105. esac
  2106. done
  2107. __docker_complete_containers_stopped
  2108. ;;
  2109. esac
  2110. }
  2111. _docker_rmi() {
  2112. case "$cur" in
  2113. -*)
  2114. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  2115. ;;
  2116. *)
  2117. __docker_complete_images
  2118. ;;
  2119. esac
  2120. }
  2121. _docker_run() {
  2122. local options_with_args="
  2123. --add-host
  2124. --attach -a
  2125. --blkio-weight
  2126. --blkio-weight-device
  2127. --cap-add
  2128. --cap-drop
  2129. --cgroup-parent
  2130. --cidfile
  2131. --cpu-period
  2132. --cpu-quota
  2133. --cpuset-cpus
  2134. --cpuset-mems
  2135. --cpu-shares -c
  2136. --device
  2137. --device-read-bps
  2138. --device-read-iops
  2139. --device-write-bps
  2140. --device-write-iops
  2141. --dns
  2142. --dns-opt
  2143. --dns-search
  2144. --entrypoint
  2145. --env -e
  2146. --env-file
  2147. --expose
  2148. --group-add
  2149. --hostname -h
  2150. --ip
  2151. --ip6
  2152. --ipc
  2153. --isolation
  2154. --kernel-memory
  2155. --label-file
  2156. --label -l
  2157. --link
  2158. --link-local-ip
  2159. --log-driver
  2160. --log-opt
  2161. --mac-address
  2162. --memory -m
  2163. --memory-swap
  2164. --memory-swappiness
  2165. --memory-reservation
  2166. --name
  2167. --network
  2168. --network-alias
  2169. --oom-score-adj
  2170. --pid
  2171. --pids-limit
  2172. --publish -p
  2173. --restart
  2174. --runtime
  2175. --security-opt
  2176. --shm-size
  2177. --stop-signal
  2178. --storage-opt
  2179. --tmpfs
  2180. --sysctl
  2181. --ulimit
  2182. --user -u
  2183. --userns
  2184. --uts
  2185. --volume-driver
  2186. --volumes-from
  2187. --volume -v
  2188. --workdir -w
  2189. "
  2190. local boolean_options="
  2191. --disable-content-trust=false
  2192. --help
  2193. --interactive -i
  2194. --oom-kill-disable
  2195. --privileged
  2196. --publish-all -P
  2197. --read-only
  2198. --tty -t
  2199. "
  2200. if [ "$command" = "run" ] ; then
  2201. options_with_args="$options_with_args
  2202. --detach-keys
  2203. --health-cmd
  2204. --health-interval
  2205. --health-retries
  2206. --health-timeout
  2207. "
  2208. boolean_options="$boolean_options
  2209. --detach -d
  2210. --no-healthcheck
  2211. --rm
  2212. --sig-proxy=false
  2213. "
  2214. __docker_complete_detach-keys && return
  2215. fi
  2216. local all_options="$options_with_args $boolean_options"
  2217. __docker_complete_log_driver_options && return
  2218. __docker_complete_restart && return
  2219. local key=$(__docker_map_key_of_current_option '--security-opt')
  2220. case "$key" in
  2221. label)
  2222. [[ $cur == *: ]] && return
  2223. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  2224. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  2225. __docker_nospace
  2226. fi
  2227. return
  2228. ;;
  2229. seccomp)
  2230. local cur=${cur##*=}
  2231. _filedir
  2232. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  2233. return
  2234. ;;
  2235. esac
  2236. case "$prev" in
  2237. --add-host)
  2238. case "$cur" in
  2239. *:)
  2240. __docker_complete_resolved_hostname
  2241. return
  2242. ;;
  2243. esac
  2244. ;;
  2245. --attach|-a)
  2246. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  2247. return
  2248. ;;
  2249. --cap-add|--cap-drop)
  2250. __docker_complete_capabilities
  2251. return
  2252. ;;
  2253. --cidfile|--env-file|--label-file)
  2254. _filedir
  2255. return
  2256. ;;
  2257. --device|--tmpfs|--volume|-v)
  2258. case "$cur" in
  2259. *:*)
  2260. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  2261. ;;
  2262. '')
  2263. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  2264. __docker_nospace
  2265. ;;
  2266. /*)
  2267. _filedir
  2268. __docker_nospace
  2269. ;;
  2270. esac
  2271. return
  2272. ;;
  2273. --env|-e)
  2274. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  2275. COMPREPLY=( $( compgen -e -- "$cur" ) )
  2276. __docker_nospace
  2277. return
  2278. ;;
  2279. --ipc)
  2280. case "$cur" in
  2281. *:*)
  2282. cur="${cur#*:}"
  2283. __docker_complete_containers_running
  2284. ;;
  2285. *)
  2286. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  2287. if [ "$COMPREPLY" = "container:" ]; then
  2288. __docker_nospace
  2289. fi
  2290. ;;
  2291. esac
  2292. return
  2293. ;;
  2294. --isolation)
  2295. __docker_complete_isolation
  2296. return
  2297. ;;
  2298. --link)
  2299. case "$cur" in
  2300. *:*)
  2301. ;;
  2302. *)
  2303. __docker_complete_containers_running
  2304. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  2305. __docker_nospace
  2306. ;;
  2307. esac
  2308. return
  2309. ;;
  2310. --log-driver)
  2311. __docker_complete_log_drivers
  2312. return
  2313. ;;
  2314. --log-opt)
  2315. __docker_complete_log_options
  2316. return
  2317. ;;
  2318. --network)
  2319. case "$cur" in
  2320. container:*)
  2321. local cur=${cur#*:}
  2322. __docker_complete_containers_all
  2323. ;;
  2324. *)
  2325. COMPREPLY=( $( compgen -W "$(__docker_plugins Network) $(__docker_networks) container:" -- "$cur") )
  2326. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  2327. __docker_nospace
  2328. fi
  2329. ;;
  2330. esac
  2331. return
  2332. ;;
  2333. --pid)
  2334. case "$cur" in
  2335. *:*)
  2336. cur="${cur#*:}"
  2337. __docker_complete_containers_running
  2338. ;;
  2339. *)
  2340. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  2341. if [ "$COMPREPLY" = "container:" ]; then
  2342. __docker_nospace
  2343. fi
  2344. ;;
  2345. esac
  2346. return
  2347. ;;
  2348. --runtime)
  2349. __docker_complete_runtimes
  2350. return
  2351. ;;
  2352. --security-opt)
  2353. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  2354. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  2355. __docker_nospace
  2356. fi
  2357. return
  2358. ;;
  2359. --storage-opt)
  2360. COMPREPLY=( $( compgen -W "size" -S = -- "$cur") )
  2361. __docker_nospace
  2362. return
  2363. ;;
  2364. --user|-u)
  2365. __docker_complete_user_group
  2366. return
  2367. ;;
  2368. --userns)
  2369. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  2370. return
  2371. ;;
  2372. --volume-driver)
  2373. __docker_complete_plugins Volume
  2374. return
  2375. ;;
  2376. --volumes-from)
  2377. __docker_complete_containers_all
  2378. return
  2379. ;;
  2380. $(__docker_to_extglob "$options_with_args") )
  2381. return
  2382. ;;
  2383. esac
  2384. case "$cur" in
  2385. -*)
  2386. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2387. ;;
  2388. *)
  2389. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2390. if [ $cword -eq $counter ]; then
  2391. __docker_complete_images
  2392. fi
  2393. ;;
  2394. esac
  2395. }
  2396. _docker_save() {
  2397. case "$prev" in
  2398. --output|-o)
  2399. _filedir
  2400. return
  2401. ;;
  2402. esac
  2403. case "$cur" in
  2404. -*)
  2405. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  2406. ;;
  2407. *)
  2408. __docker_complete_images
  2409. ;;
  2410. esac
  2411. }
  2412. _docker_search() {
  2413. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2414. case "$key" in
  2415. is-automated)
  2416. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2417. return
  2418. ;;
  2419. is-official)
  2420. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2421. return
  2422. ;;
  2423. esac
  2424. case "$prev" in
  2425. --filter|-f)
  2426. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  2427. __docker_nospace
  2428. return
  2429. ;;
  2430. --limit)
  2431. return
  2432. ;;
  2433. esac
  2434. case "$cur" in
  2435. -*)
  2436. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  2437. ;;
  2438. esac
  2439. }
  2440. _docker_start() {
  2441. __docker_complete_detach-keys && return
  2442. case "$cur" in
  2443. -*)
  2444. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  2445. ;;
  2446. *)
  2447. __docker_complete_containers_stopped
  2448. ;;
  2449. esac
  2450. }
  2451. _docker_stats() {
  2452. case "$prev" in
  2453. --format)
  2454. return
  2455. ;;
  2456. esac
  2457. case "$cur" in
  2458. -*)
  2459. COMPREPLY=( $( compgen -W "--all -a --format --help --no-stream" -- "$cur" ) )
  2460. ;;
  2461. *)
  2462. __docker_complete_containers_running
  2463. ;;
  2464. esac
  2465. }
  2466. _docker_stop() {
  2467. case "$prev" in
  2468. --time|-t)
  2469. return
  2470. ;;
  2471. esac
  2472. case "$cur" in
  2473. -*)
  2474. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2475. ;;
  2476. *)
  2477. __docker_complete_containers_running
  2478. ;;
  2479. esac
  2480. }
  2481. _docker_tag() {
  2482. case "$cur" in
  2483. -*)
  2484. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2485. ;;
  2486. *)
  2487. local counter=$(__docker_pos_first_nonflag)
  2488. if [ $cword -eq $counter ]; then
  2489. __docker_complete_image_repos_and_tags
  2490. return
  2491. fi
  2492. (( counter++ ))
  2493. if [ $cword -eq $counter ]; then
  2494. __docker_complete_image_repos_and_tags
  2495. return
  2496. fi
  2497. ;;
  2498. esac
  2499. }
  2500. _docker_unpause() {
  2501. case "$cur" in
  2502. -*)
  2503. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2504. ;;
  2505. *)
  2506. local counter=$(__docker_pos_first_nonflag)
  2507. if [ $cword -eq $counter ]; then
  2508. __docker_complete_containers_unpauseable
  2509. fi
  2510. ;;
  2511. esac
  2512. }
  2513. _docker_update() {
  2514. local options_with_args="
  2515. --blkio-weight
  2516. --cpu-period
  2517. --cpu-quota
  2518. --cpuset-cpus
  2519. --cpuset-mems
  2520. --cpu-shares -c
  2521. --kernel-memory
  2522. --memory -m
  2523. --memory-reservation
  2524. --memory-swap
  2525. --restart
  2526. "
  2527. local boolean_options="
  2528. --help
  2529. "
  2530. local all_options="$options_with_args $boolean_options"
  2531. __docker_complete_restart && return
  2532. case "$prev" in
  2533. $(__docker_to_extglob "$options_with_args") )
  2534. return
  2535. ;;
  2536. esac
  2537. case "$cur" in
  2538. -*)
  2539. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2540. ;;
  2541. *)
  2542. __docker_complete_containers_all
  2543. ;;
  2544. esac
  2545. }
  2546. _docker_top() {
  2547. case "$cur" in
  2548. -*)
  2549. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2550. ;;
  2551. *)
  2552. local counter=$(__docker_pos_first_nonflag)
  2553. if [ $cword -eq $counter ]; then
  2554. __docker_complete_containers_running
  2555. fi
  2556. ;;
  2557. esac
  2558. }
  2559. _docker_version() {
  2560. case "$cur" in
  2561. -*)
  2562. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2563. ;;
  2564. esac
  2565. }
  2566. _docker_volume_create() {
  2567. case "$prev" in
  2568. --driver|-d)
  2569. __docker_complete_plugins Volume
  2570. return
  2571. ;;
  2572. --label|--opt|-o)
  2573. return
  2574. ;;
  2575. esac
  2576. case "$cur" in
  2577. -*)
  2578. COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) )
  2579. ;;
  2580. esac
  2581. }
  2582. _docker_volume_inspect() {
  2583. case "$prev" in
  2584. --format|-f)
  2585. return
  2586. ;;
  2587. esac
  2588. case "$cur" in
  2589. -*)
  2590. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2591. ;;
  2592. *)
  2593. __docker_complete_volumes
  2594. ;;
  2595. esac
  2596. }
  2597. _docker_volume_ls() {
  2598. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2599. case "$key" in
  2600. dangling)
  2601. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  2602. return
  2603. ;;
  2604. driver)
  2605. cur=${cur##*=}
  2606. __docker_complete_plugins Volume
  2607. return
  2608. ;;
  2609. name)
  2610. cur=${cur##*=}
  2611. __docker_complete_volumes
  2612. return
  2613. ;;
  2614. esac
  2615. case "$prev" in
  2616. --filter|-f)
  2617. COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) )
  2618. __docker_nospace
  2619. return
  2620. ;;
  2621. --format)
  2622. return
  2623. ;;
  2624. esac
  2625. case "$cur" in
  2626. -*)
  2627. COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
  2628. ;;
  2629. esac
  2630. }
  2631. _docker_volume_rm() {
  2632. case "$cur" in
  2633. -*)
  2634. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2635. ;;
  2636. *)
  2637. __docker_complete_volumes
  2638. ;;
  2639. esac
  2640. }
  2641. _docker_volume() {
  2642. local subcommands="
  2643. create
  2644. inspect
  2645. ls
  2646. rm
  2647. "
  2648. __docker_subcommands "$subcommands" && return
  2649. case "$cur" in
  2650. -*)
  2651. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2652. ;;
  2653. *)
  2654. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2655. ;;
  2656. esac
  2657. }
  2658. _docker_wait() {
  2659. case "$cur" in
  2660. -*)
  2661. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2662. ;;
  2663. *)
  2664. __docker_complete_containers_all
  2665. ;;
  2666. esac
  2667. }
  2668. _docker() {
  2669. local previous_extglob_setting=$(shopt -p extglob)
  2670. shopt -s extglob
  2671. local commands=(
  2672. attach
  2673. build
  2674. commit
  2675. cp
  2676. create
  2677. daemon
  2678. diff
  2679. events
  2680. exec
  2681. export
  2682. history
  2683. images
  2684. import
  2685. info
  2686. inspect
  2687. kill
  2688. load
  2689. login
  2690. logout
  2691. logs
  2692. network
  2693. node
  2694. pause
  2695. port
  2696. ps
  2697. pull
  2698. push
  2699. rename
  2700. restart
  2701. rm
  2702. rmi
  2703. run
  2704. save
  2705. search
  2706. service
  2707. start
  2708. stats
  2709. stop
  2710. swarm
  2711. tag
  2712. top
  2713. unpause
  2714. update
  2715. version
  2716. volume
  2717. wait
  2718. )
  2719. # These options are valid as global options for all client commands
  2720. # and valid as command options for `docker daemon`
  2721. local global_boolean_options="
  2722. --debug -D
  2723. --tls
  2724. --tlsverify
  2725. "
  2726. local global_options_with_args="
  2727. --config
  2728. --host -H
  2729. --log-level -l
  2730. --tlscacert
  2731. --tlscert
  2732. --tlskey
  2733. "
  2734. local host config
  2735. COMPREPLY=()
  2736. local cur prev words cword
  2737. _get_comp_words_by_ref -n : cur prev words cword
  2738. local command='docker' command_pos=0 subcommand_pos
  2739. local counter=1
  2740. while [ $counter -lt $cword ]; do
  2741. case "${words[$counter]}" in
  2742. # save host so that completion can use custom daemon
  2743. --host|-H)
  2744. (( counter++ ))
  2745. host="${words[$counter]}"
  2746. ;;
  2747. # save config so that completion can use custom configuration directories
  2748. --config)
  2749. (( counter++ ))
  2750. config="${words[$counter]}"
  2751. ;;
  2752. $(__docker_to_extglob "$global_options_with_args") )
  2753. (( counter++ ))
  2754. ;;
  2755. -*)
  2756. ;;
  2757. =)
  2758. (( counter++ ))
  2759. ;;
  2760. *)
  2761. command="${words[$counter]}"
  2762. command_pos=$counter
  2763. break
  2764. ;;
  2765. esac
  2766. (( counter++ ))
  2767. done
  2768. local binary="${words[0]}"
  2769. if [[ $binary == ?(*/)dockerd ]] ; then
  2770. # for the dockerd binary, we reuse completion of `docker daemon`.
  2771. # dockerd does not have subcommands and global options.
  2772. command=daemon
  2773. command_pos=0
  2774. fi
  2775. local completions_func=_docker_${command}
  2776. declare -F $completions_func >/dev/null && $completions_func
  2777. eval "$previous_extglob_setting"
  2778. return 0
  2779. }
  2780. eval "$__docker_previous_extglob_setting"
  2781. unset __docker_previous_extglob_setting
  2782. complete -F _docker docker dockerd