docker 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043
  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. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  1917. if [ $cword -eq $counter ]; then
  1918. __docker_complete_nodes_plus_self
  1919. fi
  1920. ;;
  1921. esac
  1922. }
  1923. _docker_node_update() {
  1924. case "$prev" in
  1925. --availability)
  1926. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  1927. return
  1928. ;;
  1929. --role)
  1930. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  1931. return
  1932. ;;
  1933. --label-add|--label-rm)
  1934. return
  1935. ;;
  1936. esac
  1937. case "$cur" in
  1938. -*)
  1939. COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) )
  1940. ;;
  1941. *)
  1942. __docker_complete_nodes
  1943. esac
  1944. }
  1945. _docker_pause() {
  1946. case "$cur" in
  1947. -*)
  1948. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1949. ;;
  1950. *)
  1951. local counter=$(__docker_pos_first_nonflag)
  1952. if [ $cword -eq $counter ]; then
  1953. __docker_complete_containers_pauseable
  1954. fi
  1955. ;;
  1956. esac
  1957. }
  1958. _docker_port() {
  1959. case "$cur" in
  1960. -*)
  1961. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1962. ;;
  1963. *)
  1964. local counter=$(__docker_pos_first_nonflag)
  1965. if [ $cword -eq $counter ]; then
  1966. __docker_complete_containers_all
  1967. fi
  1968. ;;
  1969. esac
  1970. }
  1971. _docker_ps() {
  1972. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1973. case "$key" in
  1974. ancestor)
  1975. cur="${cur##*=}"
  1976. __docker_complete_images
  1977. return
  1978. ;;
  1979. before)
  1980. cur="${cur##*=}"
  1981. __docker_complete_containers_all
  1982. return
  1983. ;;
  1984. id)
  1985. cur="${cur##*=}"
  1986. __docker_complete_container_ids
  1987. return
  1988. ;;
  1989. is-task)
  1990. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  1991. return
  1992. ;;
  1993. name)
  1994. cur="${cur##*=}"
  1995. __docker_complete_container_names
  1996. return
  1997. ;;
  1998. network)
  1999. cur="${cur##*=}"
  2000. __docker_complete_networks
  2001. return
  2002. ;;
  2003. since)
  2004. cur="${cur##*=}"
  2005. __docker_complete_containers_all
  2006. return
  2007. ;;
  2008. status)
  2009. COMPREPLY=( $( compgen -W "created dead exited paused restarting running removing" -- "${cur##*=}" ) )
  2010. return
  2011. ;;
  2012. volume)
  2013. cur="${cur##*=}"
  2014. __docker_complete_volumes
  2015. return
  2016. ;;
  2017. esac
  2018. case "$prev" in
  2019. --filter|-f)
  2020. COMPREPLY=( $( compgen -S = -W "ancestor before exited id label name network since status volume" -- "$cur" ) )
  2021. __docker_nospace
  2022. return
  2023. ;;
  2024. --format|--last|-n)
  2025. return
  2026. ;;
  2027. esac
  2028. case "$cur" in
  2029. -*)
  2030. COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) )
  2031. ;;
  2032. esac
  2033. }
  2034. _docker_pull() {
  2035. case "$cur" in
  2036. -*)
  2037. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  2038. ;;
  2039. *)
  2040. local counter=$(__docker_pos_first_nonflag)
  2041. if [ $cword -eq $counter ]; then
  2042. for arg in "${COMP_WORDS[@]}"; do
  2043. case "$arg" in
  2044. --all-tags|-a)
  2045. __docker_complete_image_repos
  2046. return
  2047. ;;
  2048. esac
  2049. done
  2050. __docker_complete_image_repos_and_tags
  2051. fi
  2052. ;;
  2053. esac
  2054. }
  2055. _docker_push() {
  2056. case "$cur" in
  2057. -*)
  2058. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  2059. ;;
  2060. *)
  2061. local counter=$(__docker_pos_first_nonflag)
  2062. if [ $cword -eq $counter ]; then
  2063. __docker_complete_image_repos_and_tags
  2064. fi
  2065. ;;
  2066. esac
  2067. }
  2068. _docker_rename() {
  2069. case "$cur" in
  2070. -*)
  2071. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2072. ;;
  2073. *)
  2074. local counter=$(__docker_pos_first_nonflag)
  2075. if [ $cword -eq $counter ]; then
  2076. __docker_complete_containers_all
  2077. fi
  2078. ;;
  2079. esac
  2080. }
  2081. _docker_restart() {
  2082. case "$prev" in
  2083. --time|-t)
  2084. return
  2085. ;;
  2086. esac
  2087. case "$cur" in
  2088. -*)
  2089. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2090. ;;
  2091. *)
  2092. __docker_complete_containers_all
  2093. ;;
  2094. esac
  2095. }
  2096. _docker_rm() {
  2097. case "$cur" in
  2098. -*)
  2099. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  2100. ;;
  2101. *)
  2102. for arg in "${COMP_WORDS[@]}"; do
  2103. case "$arg" in
  2104. --force|-f)
  2105. __docker_complete_containers_all
  2106. return
  2107. ;;
  2108. esac
  2109. done
  2110. __docker_complete_containers_stopped
  2111. ;;
  2112. esac
  2113. }
  2114. _docker_rmi() {
  2115. case "$cur" in
  2116. -*)
  2117. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  2118. ;;
  2119. *)
  2120. __docker_complete_images
  2121. ;;
  2122. esac
  2123. }
  2124. _docker_run() {
  2125. local options_with_args="
  2126. --add-host
  2127. --attach -a
  2128. --blkio-weight
  2129. --blkio-weight-device
  2130. --cap-add
  2131. --cap-drop
  2132. --cgroup-parent
  2133. --cidfile
  2134. --cpu-period
  2135. --cpu-quota
  2136. --cpuset-cpus
  2137. --cpuset-mems
  2138. --cpu-shares -c
  2139. --device
  2140. --device-read-bps
  2141. --device-read-iops
  2142. --device-write-bps
  2143. --device-write-iops
  2144. --dns
  2145. --dns-opt
  2146. --dns-search
  2147. --entrypoint
  2148. --env -e
  2149. --env-file
  2150. --expose
  2151. --group-add
  2152. --hostname -h
  2153. --ip
  2154. --ip6
  2155. --ipc
  2156. --isolation
  2157. --kernel-memory
  2158. --label-file
  2159. --label -l
  2160. --link
  2161. --link-local-ip
  2162. --log-driver
  2163. --log-opt
  2164. --mac-address
  2165. --memory -m
  2166. --memory-swap
  2167. --memory-swappiness
  2168. --memory-reservation
  2169. --name
  2170. --network
  2171. --network-alias
  2172. --oom-score-adj
  2173. --pid
  2174. --pids-limit
  2175. --publish -p
  2176. --restart
  2177. --runtime
  2178. --security-opt
  2179. --shm-size
  2180. --stop-signal
  2181. --storage-opt
  2182. --tmpfs
  2183. --sysctl
  2184. --ulimit
  2185. --user -u
  2186. --userns
  2187. --uts
  2188. --volume-driver
  2189. --volumes-from
  2190. --volume -v
  2191. --workdir -w
  2192. "
  2193. local boolean_options="
  2194. --disable-content-trust=false
  2195. --help
  2196. --interactive -i
  2197. --oom-kill-disable
  2198. --privileged
  2199. --publish-all -P
  2200. --read-only
  2201. --tty -t
  2202. "
  2203. if [ "$command" = "run" ] ; then
  2204. options_with_args="$options_with_args
  2205. --detach-keys
  2206. --health-cmd
  2207. --health-interval
  2208. --health-retries
  2209. --health-timeout
  2210. "
  2211. boolean_options="$boolean_options
  2212. --detach -d
  2213. --no-healthcheck
  2214. --rm
  2215. --sig-proxy=false
  2216. "
  2217. __docker_complete_detach-keys && return
  2218. fi
  2219. local all_options="$options_with_args $boolean_options"
  2220. __docker_complete_log_driver_options && return
  2221. __docker_complete_restart && return
  2222. local key=$(__docker_map_key_of_current_option '--security-opt')
  2223. case "$key" in
  2224. label)
  2225. [[ $cur == *: ]] && return
  2226. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  2227. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  2228. __docker_nospace
  2229. fi
  2230. return
  2231. ;;
  2232. seccomp)
  2233. local cur=${cur##*=}
  2234. _filedir
  2235. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  2236. return
  2237. ;;
  2238. esac
  2239. case "$prev" in
  2240. --add-host)
  2241. case "$cur" in
  2242. *:)
  2243. __docker_complete_resolved_hostname
  2244. return
  2245. ;;
  2246. esac
  2247. ;;
  2248. --attach|-a)
  2249. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  2250. return
  2251. ;;
  2252. --cap-add|--cap-drop)
  2253. __docker_complete_capabilities
  2254. return
  2255. ;;
  2256. --cidfile|--env-file|--label-file)
  2257. _filedir
  2258. return
  2259. ;;
  2260. --device|--tmpfs|--volume|-v)
  2261. case "$cur" in
  2262. *:*)
  2263. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  2264. ;;
  2265. '')
  2266. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  2267. __docker_nospace
  2268. ;;
  2269. /*)
  2270. _filedir
  2271. __docker_nospace
  2272. ;;
  2273. esac
  2274. return
  2275. ;;
  2276. --env|-e)
  2277. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  2278. COMPREPLY=( $( compgen -e -- "$cur" ) )
  2279. __docker_nospace
  2280. return
  2281. ;;
  2282. --ipc)
  2283. case "$cur" in
  2284. *:*)
  2285. cur="${cur#*:}"
  2286. __docker_complete_containers_running
  2287. ;;
  2288. *)
  2289. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  2290. if [ "$COMPREPLY" = "container:" ]; then
  2291. __docker_nospace
  2292. fi
  2293. ;;
  2294. esac
  2295. return
  2296. ;;
  2297. --isolation)
  2298. __docker_complete_isolation
  2299. return
  2300. ;;
  2301. --link)
  2302. case "$cur" in
  2303. *:*)
  2304. ;;
  2305. *)
  2306. __docker_complete_containers_running
  2307. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  2308. __docker_nospace
  2309. ;;
  2310. esac
  2311. return
  2312. ;;
  2313. --log-driver)
  2314. __docker_complete_log_drivers
  2315. return
  2316. ;;
  2317. --log-opt)
  2318. __docker_complete_log_options
  2319. return
  2320. ;;
  2321. --network)
  2322. case "$cur" in
  2323. container:*)
  2324. local cur=${cur#*:}
  2325. __docker_complete_containers_all
  2326. ;;
  2327. *)
  2328. COMPREPLY=( $( compgen -W "$(__docker_plugins Network) $(__docker_networks) container:" -- "$cur") )
  2329. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  2330. __docker_nospace
  2331. fi
  2332. ;;
  2333. esac
  2334. return
  2335. ;;
  2336. --pid)
  2337. case "$cur" in
  2338. *:*)
  2339. cur="${cur#*:}"
  2340. __docker_complete_containers_running
  2341. ;;
  2342. *)
  2343. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  2344. if [ "$COMPREPLY" = "container:" ]; then
  2345. __docker_nospace
  2346. fi
  2347. ;;
  2348. esac
  2349. return
  2350. ;;
  2351. --runtime)
  2352. __docker_complete_runtimes
  2353. return
  2354. ;;
  2355. --security-opt)
  2356. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  2357. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  2358. __docker_nospace
  2359. fi
  2360. return
  2361. ;;
  2362. --storage-opt)
  2363. COMPREPLY=( $( compgen -W "size" -S = -- "$cur") )
  2364. __docker_nospace
  2365. return
  2366. ;;
  2367. --user|-u)
  2368. __docker_complete_user_group
  2369. return
  2370. ;;
  2371. --userns)
  2372. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  2373. return
  2374. ;;
  2375. --volume-driver)
  2376. __docker_complete_plugins Volume
  2377. return
  2378. ;;
  2379. --volumes-from)
  2380. __docker_complete_containers_all
  2381. return
  2382. ;;
  2383. $(__docker_to_extglob "$options_with_args") )
  2384. return
  2385. ;;
  2386. esac
  2387. case "$cur" in
  2388. -*)
  2389. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2390. ;;
  2391. *)
  2392. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2393. if [ $cword -eq $counter ]; then
  2394. __docker_complete_images
  2395. fi
  2396. ;;
  2397. esac
  2398. }
  2399. _docker_save() {
  2400. case "$prev" in
  2401. --output|-o)
  2402. _filedir
  2403. return
  2404. ;;
  2405. esac
  2406. case "$cur" in
  2407. -*)
  2408. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  2409. ;;
  2410. *)
  2411. __docker_complete_images
  2412. ;;
  2413. esac
  2414. }
  2415. _docker_search() {
  2416. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2417. case "$key" in
  2418. is-automated)
  2419. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2420. return
  2421. ;;
  2422. is-official)
  2423. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2424. return
  2425. ;;
  2426. esac
  2427. case "$prev" in
  2428. --filter|-f)
  2429. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  2430. __docker_nospace
  2431. return
  2432. ;;
  2433. --limit)
  2434. return
  2435. ;;
  2436. esac
  2437. case "$cur" in
  2438. -*)
  2439. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  2440. ;;
  2441. esac
  2442. }
  2443. _docker_start() {
  2444. __docker_complete_detach-keys && return
  2445. case "$cur" in
  2446. -*)
  2447. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  2448. ;;
  2449. *)
  2450. __docker_complete_containers_stopped
  2451. ;;
  2452. esac
  2453. }
  2454. _docker_stats() {
  2455. case "$prev" in
  2456. --format)
  2457. return
  2458. ;;
  2459. esac
  2460. case "$cur" in
  2461. -*)
  2462. COMPREPLY=( $( compgen -W "--all -a --format --help --no-stream" -- "$cur" ) )
  2463. ;;
  2464. *)
  2465. __docker_complete_containers_running
  2466. ;;
  2467. esac
  2468. }
  2469. _docker_stop() {
  2470. case "$prev" in
  2471. --time|-t)
  2472. return
  2473. ;;
  2474. esac
  2475. case "$cur" in
  2476. -*)
  2477. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2478. ;;
  2479. *)
  2480. __docker_complete_containers_running
  2481. ;;
  2482. esac
  2483. }
  2484. _docker_tag() {
  2485. case "$cur" in
  2486. -*)
  2487. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2488. ;;
  2489. *)
  2490. local counter=$(__docker_pos_first_nonflag)
  2491. if [ $cword -eq $counter ]; then
  2492. __docker_complete_image_repos_and_tags
  2493. return
  2494. fi
  2495. (( counter++ ))
  2496. if [ $cword -eq $counter ]; then
  2497. __docker_complete_image_repos_and_tags
  2498. return
  2499. fi
  2500. ;;
  2501. esac
  2502. }
  2503. _docker_unpause() {
  2504. case "$cur" in
  2505. -*)
  2506. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2507. ;;
  2508. *)
  2509. local counter=$(__docker_pos_first_nonflag)
  2510. if [ $cword -eq $counter ]; then
  2511. __docker_complete_containers_unpauseable
  2512. fi
  2513. ;;
  2514. esac
  2515. }
  2516. _docker_update() {
  2517. local options_with_args="
  2518. --blkio-weight
  2519. --cpu-period
  2520. --cpu-quota
  2521. --cpuset-cpus
  2522. --cpuset-mems
  2523. --cpu-shares -c
  2524. --kernel-memory
  2525. --memory -m
  2526. --memory-reservation
  2527. --memory-swap
  2528. --restart
  2529. "
  2530. local boolean_options="
  2531. --help
  2532. "
  2533. local all_options="$options_with_args $boolean_options"
  2534. __docker_complete_restart && return
  2535. case "$prev" in
  2536. $(__docker_to_extglob "$options_with_args") )
  2537. return
  2538. ;;
  2539. esac
  2540. case "$cur" in
  2541. -*)
  2542. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2543. ;;
  2544. *)
  2545. __docker_complete_containers_all
  2546. ;;
  2547. esac
  2548. }
  2549. _docker_top() {
  2550. case "$cur" in
  2551. -*)
  2552. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2553. ;;
  2554. *)
  2555. local counter=$(__docker_pos_first_nonflag)
  2556. if [ $cword -eq $counter ]; then
  2557. __docker_complete_containers_running
  2558. fi
  2559. ;;
  2560. esac
  2561. }
  2562. _docker_version() {
  2563. case "$cur" in
  2564. -*)
  2565. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2566. ;;
  2567. esac
  2568. }
  2569. _docker_volume_create() {
  2570. case "$prev" in
  2571. --driver|-d)
  2572. __docker_complete_plugins Volume
  2573. return
  2574. ;;
  2575. --label|--opt|-o)
  2576. return
  2577. ;;
  2578. esac
  2579. case "$cur" in
  2580. -*)
  2581. COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) )
  2582. ;;
  2583. esac
  2584. }
  2585. _docker_volume_inspect() {
  2586. case "$prev" in
  2587. --format|-f)
  2588. return
  2589. ;;
  2590. esac
  2591. case "$cur" in
  2592. -*)
  2593. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2594. ;;
  2595. *)
  2596. __docker_complete_volumes
  2597. ;;
  2598. esac
  2599. }
  2600. _docker_volume_ls() {
  2601. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2602. case "$key" in
  2603. dangling)
  2604. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  2605. return
  2606. ;;
  2607. driver)
  2608. cur=${cur##*=}
  2609. __docker_complete_plugins Volume
  2610. return
  2611. ;;
  2612. name)
  2613. cur=${cur##*=}
  2614. __docker_complete_volumes
  2615. return
  2616. ;;
  2617. esac
  2618. case "$prev" in
  2619. --filter|-f)
  2620. COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) )
  2621. __docker_nospace
  2622. return
  2623. ;;
  2624. --format)
  2625. return
  2626. ;;
  2627. esac
  2628. case "$cur" in
  2629. -*)
  2630. COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
  2631. ;;
  2632. esac
  2633. }
  2634. _docker_volume_rm() {
  2635. case "$cur" in
  2636. -*)
  2637. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2638. ;;
  2639. *)
  2640. __docker_complete_volumes
  2641. ;;
  2642. esac
  2643. }
  2644. _docker_volume() {
  2645. local subcommands="
  2646. create
  2647. inspect
  2648. ls
  2649. rm
  2650. "
  2651. __docker_subcommands "$subcommands" && return
  2652. case "$cur" in
  2653. -*)
  2654. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2655. ;;
  2656. *)
  2657. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2658. ;;
  2659. esac
  2660. }
  2661. _docker_wait() {
  2662. case "$cur" in
  2663. -*)
  2664. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2665. ;;
  2666. *)
  2667. __docker_complete_containers_all
  2668. ;;
  2669. esac
  2670. }
  2671. _docker() {
  2672. local previous_extglob_setting=$(shopt -p extglob)
  2673. shopt -s extglob
  2674. local commands=(
  2675. attach
  2676. build
  2677. commit
  2678. cp
  2679. create
  2680. daemon
  2681. diff
  2682. events
  2683. exec
  2684. export
  2685. history
  2686. images
  2687. import
  2688. info
  2689. inspect
  2690. kill
  2691. load
  2692. login
  2693. logout
  2694. logs
  2695. network
  2696. node
  2697. pause
  2698. port
  2699. ps
  2700. pull
  2701. push
  2702. rename
  2703. restart
  2704. rm
  2705. rmi
  2706. run
  2707. save
  2708. search
  2709. service
  2710. start
  2711. stats
  2712. stop
  2713. swarm
  2714. tag
  2715. top
  2716. unpause
  2717. update
  2718. version
  2719. volume
  2720. wait
  2721. )
  2722. # These options are valid as global options for all client commands
  2723. # and valid as command options for `docker daemon`
  2724. local global_boolean_options="
  2725. --debug -D
  2726. --tls
  2727. --tlsverify
  2728. "
  2729. local global_options_with_args="
  2730. --config
  2731. --host -H
  2732. --log-level -l
  2733. --tlscacert
  2734. --tlscert
  2735. --tlskey
  2736. "
  2737. local host config
  2738. COMPREPLY=()
  2739. local cur prev words cword
  2740. _get_comp_words_by_ref -n : cur prev words cword
  2741. local command='docker' command_pos=0 subcommand_pos
  2742. local counter=1
  2743. while [ $counter -lt $cword ]; do
  2744. case "${words[$counter]}" in
  2745. # save host so that completion can use custom daemon
  2746. --host|-H)
  2747. (( counter++ ))
  2748. host="${words[$counter]}"
  2749. ;;
  2750. # save config so that completion can use custom configuration directories
  2751. --config)
  2752. (( counter++ ))
  2753. config="${words[$counter]}"
  2754. ;;
  2755. $(__docker_to_extglob "$global_options_with_args") )
  2756. (( counter++ ))
  2757. ;;
  2758. -*)
  2759. ;;
  2760. =)
  2761. (( counter++ ))
  2762. ;;
  2763. *)
  2764. command="${words[$counter]}"
  2765. command_pos=$counter
  2766. break
  2767. ;;
  2768. esac
  2769. (( counter++ ))
  2770. done
  2771. local binary="${words[0]}"
  2772. if [[ $binary == ?(*/)dockerd ]] ; then
  2773. # for the dockerd binary, we reuse completion of `docker daemon`.
  2774. # dockerd does not have subcommands and global options.
  2775. command=daemon
  2776. command_pos=0
  2777. fi
  2778. local completions_func=_docker_${command}
  2779. declare -F $completions_func >/dev/null && $completions_func
  2780. eval "$previous_extglob_setting"
  2781. return 0
  2782. }
  2783. eval "$__docker_previous_extglob_setting"
  2784. unset __docker_previous_extglob_setting
  2785. complete -F _docker docker dockerd