docker 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022
  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-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-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. import
  1009. kill
  1010. load
  1011. mount
  1012. oom
  1013. pause
  1014. pull
  1015. push
  1016. reload
  1017. rename
  1018. resize
  1019. restart
  1020. save
  1021. start
  1022. stop
  1023. tag
  1024. top
  1025. unmount
  1026. unpause
  1027. untag
  1028. update
  1029. " -- "${cur##*=}" ) )
  1030. return
  1031. ;;
  1032. image)
  1033. cur="${cur##*=}"
  1034. __docker_complete_images
  1035. return
  1036. ;;
  1037. network)
  1038. cur="${cur##*=}"
  1039. __docker_complete_networks
  1040. return
  1041. ;;
  1042. type)
  1043. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  1044. return
  1045. ;;
  1046. volume)
  1047. cur="${cur##*=}"
  1048. __docker_complete_volumes
  1049. return
  1050. ;;
  1051. esac
  1052. case "$prev" in
  1053. --filter|-f)
  1054. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  1055. __docker_nospace
  1056. return
  1057. ;;
  1058. --since|--until)
  1059. return
  1060. ;;
  1061. esac
  1062. case "$cur" in
  1063. -*)
  1064. COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) )
  1065. ;;
  1066. esac
  1067. }
  1068. _docker_exec() {
  1069. __docker_complete_detach-keys && return
  1070. case "$prev" in
  1071. --user|-u)
  1072. __docker_complete_user_group
  1073. return
  1074. ;;
  1075. esac
  1076. case "$cur" in
  1077. -*)
  1078. COMPREPLY=( $( compgen -W "--detach -d --detach-keys --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  1079. ;;
  1080. *)
  1081. __docker_complete_containers_running
  1082. ;;
  1083. esac
  1084. }
  1085. _docker_export() {
  1086. case "$cur" in
  1087. -*)
  1088. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1089. ;;
  1090. *)
  1091. local counter=$(__docker_pos_first_nonflag)
  1092. if [ $cword -eq $counter ]; then
  1093. __docker_complete_containers_all
  1094. fi
  1095. ;;
  1096. esac
  1097. }
  1098. _docker_help() {
  1099. local counter=$(__docker_pos_first_nonflag)
  1100. if [ $cword -eq $counter ]; then
  1101. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  1102. fi
  1103. }
  1104. _docker_history() {
  1105. case "$cur" in
  1106. -*)
  1107. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  1108. ;;
  1109. *)
  1110. local counter=$(__docker_pos_first_nonflag)
  1111. if [ $cword -eq $counter ]; then
  1112. __docker_complete_images
  1113. fi
  1114. ;;
  1115. esac
  1116. }
  1117. _docker_images() {
  1118. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1119. case "$key" in
  1120. before)
  1121. cur="${cur##*=}"
  1122. __docker_complete_images
  1123. return
  1124. ;;
  1125. dangling)
  1126. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1127. return
  1128. ;;
  1129. label)
  1130. return
  1131. ;;
  1132. since)
  1133. cur="${cur##*=}"
  1134. __docker_complete_images
  1135. return
  1136. ;;
  1137. esac
  1138. case "$prev" in
  1139. --filter|-f)
  1140. COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) )
  1141. __docker_nospace
  1142. return
  1143. ;;
  1144. --format)
  1145. return
  1146. ;;
  1147. esac
  1148. case "$cur" in
  1149. -*)
  1150. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1151. ;;
  1152. =)
  1153. return
  1154. ;;
  1155. *)
  1156. __docker_complete_image_repos
  1157. ;;
  1158. esac
  1159. }
  1160. _docker_import() {
  1161. case "$prev" in
  1162. --change|-c|--message|-m)
  1163. return
  1164. ;;
  1165. esac
  1166. case "$cur" in
  1167. -*)
  1168. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1169. ;;
  1170. *)
  1171. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1172. if [ $cword -eq $counter ]; then
  1173. return
  1174. fi
  1175. (( counter++ ))
  1176. if [ $cword -eq $counter ]; then
  1177. __docker_complete_image_repos_and_tags
  1178. return
  1179. fi
  1180. ;;
  1181. esac
  1182. }
  1183. _docker_info() {
  1184. case "$prev" in
  1185. --format|-f)
  1186. return
  1187. ;;
  1188. esac
  1189. case "$cur" in
  1190. -*)
  1191. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1192. ;;
  1193. esac
  1194. }
  1195. _docker_inspect() {
  1196. case "$prev" in
  1197. --format|-f)
  1198. return
  1199. ;;
  1200. --type)
  1201. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  1202. return
  1203. ;;
  1204. esac
  1205. case "$cur" in
  1206. -*)
  1207. COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) )
  1208. ;;
  1209. *)
  1210. case $(__docker_value_of_option --type) in
  1211. '')
  1212. __docker_complete_containers_and_images
  1213. ;;
  1214. container)
  1215. __docker_complete_containers_all
  1216. ;;
  1217. image)
  1218. __docker_complete_images
  1219. ;;
  1220. esac
  1221. esac
  1222. }
  1223. _docker_kill() {
  1224. case "$prev" in
  1225. --signal|-s)
  1226. __docker_complete_signals
  1227. return
  1228. ;;
  1229. esac
  1230. case "$cur" in
  1231. -*)
  1232. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  1233. ;;
  1234. *)
  1235. __docker_complete_containers_running
  1236. ;;
  1237. esac
  1238. }
  1239. _docker_load() {
  1240. case "$prev" in
  1241. --input|-i)
  1242. _filedir
  1243. return
  1244. ;;
  1245. esac
  1246. case "$cur" in
  1247. -*)
  1248. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1249. ;;
  1250. esac
  1251. }
  1252. _docker_login() {
  1253. case "$prev" in
  1254. --password|-p|--username|-u)
  1255. return
  1256. ;;
  1257. esac
  1258. case "$cur" in
  1259. -*)
  1260. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  1261. ;;
  1262. esac
  1263. }
  1264. _docker_logout() {
  1265. case "$cur" in
  1266. -*)
  1267. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1268. ;;
  1269. esac
  1270. }
  1271. _docker_logs() {
  1272. case "$prev" in
  1273. --since|--tail)
  1274. return
  1275. ;;
  1276. esac
  1277. case "$cur" in
  1278. -*)
  1279. COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  1280. ;;
  1281. *)
  1282. local counter=$(__docker_pos_first_nonflag '--tail')
  1283. if [ $cword -eq $counter ]; then
  1284. __docker_complete_containers_all
  1285. fi
  1286. ;;
  1287. esac
  1288. }
  1289. _docker_network_connect() {
  1290. local options_with_args="
  1291. --alias
  1292. --ip
  1293. --ip6
  1294. --link
  1295. --link-local-ip
  1296. "
  1297. local boolean_options="
  1298. --help
  1299. "
  1300. case "$prev" in
  1301. --link)
  1302. case "$cur" in
  1303. *:*)
  1304. ;;
  1305. *)
  1306. __docker_complete_containers_running
  1307. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1308. __docker_nospace
  1309. ;;
  1310. esac
  1311. return
  1312. ;;
  1313. $(__docker_to_extglob "$options_with_args") )
  1314. return
  1315. ;;
  1316. esac
  1317. case "$cur" in
  1318. -*)
  1319. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1320. ;;
  1321. *)
  1322. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1323. if [ $cword -eq $counter ]; then
  1324. __docker_complete_networks
  1325. elif [ $cword -eq $(($counter + 1)) ]; then
  1326. __docker_complete_containers_all
  1327. fi
  1328. ;;
  1329. esac
  1330. }
  1331. _docker_network_create() {
  1332. case "$prev" in
  1333. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  1334. return
  1335. ;;
  1336. --ipam-driver)
  1337. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  1338. return
  1339. ;;
  1340. --driver|-d)
  1341. local plugins="$(__docker_plugins Network) macvlan"
  1342. # remove drivers that allow one instance only
  1343. plugins=${plugins/ host / }
  1344. plugins=${plugins/ null / }
  1345. COMPREPLY=( $(compgen -W "$plugins" -- "$cur") )
  1346. return
  1347. ;;
  1348. --label)
  1349. return
  1350. ;;
  1351. esac
  1352. case "$cur" in
  1353. -*)
  1354. COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  1355. ;;
  1356. esac
  1357. }
  1358. _docker_network_disconnect() {
  1359. case "$cur" in
  1360. -*)
  1361. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1362. ;;
  1363. *)
  1364. local counter=$(__docker_pos_first_nonflag)
  1365. if [ $cword -eq $counter ]; then
  1366. __docker_complete_networks
  1367. elif [ $cword -eq $(($counter + 1)) ]; then
  1368. __docker_complete_containers_in_network "$prev"
  1369. fi
  1370. ;;
  1371. esac
  1372. }
  1373. _docker_network_inspect() {
  1374. case "$prev" in
  1375. --format|-f)
  1376. return
  1377. ;;
  1378. esac
  1379. case "$cur" in
  1380. -*)
  1381. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1382. ;;
  1383. *)
  1384. __docker_complete_networks
  1385. esac
  1386. }
  1387. _docker_network_ls() {
  1388. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1389. case "$key" in
  1390. driver)
  1391. local plugins=" $(__docker_plugins Network) "
  1392. COMPREPLY=( $(compgen -W "$plugins" -- "${cur##*=}") )
  1393. return
  1394. ;;
  1395. id)
  1396. cur="${cur##*=}"
  1397. __docker_complete_network_ids
  1398. return
  1399. ;;
  1400. name)
  1401. cur="${cur##*=}"
  1402. __docker_complete_network_names
  1403. return
  1404. ;;
  1405. type)
  1406. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  1407. return
  1408. ;;
  1409. esac
  1410. case "$prev" in
  1411. --filter|-f)
  1412. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  1413. __docker_nospace
  1414. return
  1415. ;;
  1416. --format)
  1417. return
  1418. ;;
  1419. esac
  1420. case "$cur" in
  1421. -*)
  1422. COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1423. ;;
  1424. esac
  1425. }
  1426. _docker_network_rm() {
  1427. case "$cur" in
  1428. -*)
  1429. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1430. ;;
  1431. *)
  1432. __docker_complete_networks type=custom
  1433. esac
  1434. }
  1435. _docker_network() {
  1436. local subcommands="
  1437. connect
  1438. create
  1439. disconnect
  1440. inspect
  1441. ls
  1442. rm
  1443. "
  1444. __docker_subcommands "$subcommands" && return
  1445. case "$cur" in
  1446. -*)
  1447. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1448. ;;
  1449. *)
  1450. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1451. ;;
  1452. esac
  1453. }
  1454. _docker_service() {
  1455. local subcommands="
  1456. create
  1457. inspect
  1458. ls list
  1459. rm remove
  1460. scale
  1461. ps
  1462. update
  1463. "
  1464. __docker_subcommands "$subcommands" && return
  1465. case "$cur" in
  1466. -*)
  1467. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1468. ;;
  1469. *)
  1470. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1471. ;;
  1472. esac
  1473. }
  1474. _docker_service_create() {
  1475. _docker_service_update
  1476. }
  1477. _docker_service_inspect() {
  1478. case "$prev" in
  1479. --format|-f)
  1480. return
  1481. ;;
  1482. esac
  1483. case "$cur" in
  1484. -*)
  1485. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  1486. ;;
  1487. *)
  1488. __docker_complete_services
  1489. esac
  1490. }
  1491. _docker_service_list() {
  1492. _docker_service_ls
  1493. }
  1494. _docker_service_ls() {
  1495. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1496. case "$key" in
  1497. id)
  1498. __docker_complete_services --cur "${cur##*=}" --id
  1499. return
  1500. ;;
  1501. name)
  1502. __docker_complete_services --cur "${cur##*=}" --name
  1503. return
  1504. ;;
  1505. esac
  1506. case "$prev" in
  1507. --filter|-f)
  1508. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  1509. __docker_nospace
  1510. return
  1511. ;;
  1512. esac
  1513. case "$cur" in
  1514. -*)
  1515. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1516. ;;
  1517. esac
  1518. }
  1519. _docker_service_remove() {
  1520. _docker_service_rm
  1521. }
  1522. _docker_service_rm() {
  1523. case "$cur" in
  1524. -*)
  1525. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1526. ;;
  1527. *)
  1528. __docker_complete_services
  1529. esac
  1530. }
  1531. _docker_service_scale() {
  1532. case "$cur" in
  1533. -*)
  1534. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1535. ;;
  1536. *)
  1537. __docker_complete_services
  1538. __docker_append_to_completions "="
  1539. __docker_nospace
  1540. ;;
  1541. esac
  1542. }
  1543. _docker_service_ps() {
  1544. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1545. case "$key" in
  1546. desired-state)
  1547. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  1548. return
  1549. ;;
  1550. name)
  1551. __docker_complete_services --cur "${cur##*=}" --name
  1552. return
  1553. ;;
  1554. esac
  1555. case "$prev" in
  1556. --filter|-f)
  1557. COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) )
  1558. __docker_nospace
  1559. return
  1560. ;;
  1561. esac
  1562. case "$cur" in
  1563. -*)
  1564. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  1565. ;;
  1566. *)
  1567. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  1568. if [ $cword -eq $counter ]; then
  1569. __docker_complete_services
  1570. fi
  1571. ;;
  1572. esac
  1573. }
  1574. _docker_service_update() {
  1575. local $subcommand="${words[$subcommand_pos]}"
  1576. local options_with_args="
  1577. --constraint
  1578. --endpoint-mode
  1579. --env -e
  1580. --label -l
  1581. --limit-cpu
  1582. --limit-memory
  1583. --log-driver
  1584. --log-opt
  1585. --mount
  1586. --name
  1587. --network
  1588. --publish -p
  1589. --replicas
  1590. --reserve-cpu
  1591. --reserve-memory
  1592. --restart-condition
  1593. --restart-delay
  1594. --restart-max-attempts
  1595. --restart-window
  1596. --stop-grace-period
  1597. --update-delay
  1598. --update-failure-action
  1599. --update-parallelism
  1600. --user -u
  1601. --workdir -w
  1602. "
  1603. local boolean_options="
  1604. --help
  1605. --with-registry-auth
  1606. "
  1607. __docker_complete_log_driver_options && return
  1608. if [ "$subcommand" = "create" ] ; then
  1609. options_with_args="$options_with_args
  1610. --container-label
  1611. --mode
  1612. "
  1613. case "$prev" in
  1614. --mode)
  1615. COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) )
  1616. return
  1617. ;;
  1618. esac
  1619. fi
  1620. if [ "$subcommand" = "update" ] ; then
  1621. options_with_args="$options_with_args
  1622. --arg
  1623. --container-label-add
  1624. --container-label-rm
  1625. --image
  1626. "
  1627. case "$prev" in
  1628. --image)
  1629. __docker_complete_image_repos_and_tags
  1630. return
  1631. ;;
  1632. esac
  1633. fi
  1634. case "$prev" in
  1635. --endpoint-mode)
  1636. COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) )
  1637. return
  1638. ;;
  1639. --env|-e)
  1640. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  1641. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1642. __docker_nospace
  1643. return
  1644. ;;
  1645. --log-driver)
  1646. __docker_complete_log_drivers
  1647. return
  1648. ;;
  1649. --log-opt)
  1650. __docker_complete_log_options
  1651. return
  1652. ;;
  1653. --network)
  1654. __docker_complete_networks
  1655. return
  1656. ;;
  1657. --restart-condition)
  1658. COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) )
  1659. return
  1660. ;;
  1661. --user|-u)
  1662. __docker_complete_user_group
  1663. return
  1664. ;;
  1665. $(__docker_to_extglob "$options_with_args") )
  1666. return
  1667. ;;
  1668. esac
  1669. case "$cur" in
  1670. -*)
  1671. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1672. ;;
  1673. *)
  1674. if [ "$subcommand" = "update" ] ; then
  1675. __docker_complete_services
  1676. fi
  1677. esac
  1678. }
  1679. _docker_swarm() {
  1680. local subcommands="
  1681. init
  1682. join
  1683. join-token
  1684. leave
  1685. update
  1686. "
  1687. __docker_subcommands "$subcommands" && return
  1688. case "$cur" in
  1689. -*)
  1690. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1691. ;;
  1692. *)
  1693. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1694. ;;
  1695. esac
  1696. }
  1697. _docker_swarm_init() {
  1698. case "$prev" in
  1699. --advertise-addr)
  1700. if [[ $cur == *: ]] ; then
  1701. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1702. else
  1703. __docker_complete_local_interfaces
  1704. __docker_nospace
  1705. fi
  1706. return
  1707. ;;
  1708. --listen-addr)
  1709. if [[ $cur == *: ]] ; then
  1710. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1711. else
  1712. __docker_complete_local_interfaces --add 0.0.0.0
  1713. __docker_nospace
  1714. fi
  1715. return
  1716. ;;
  1717. esac
  1718. case "$cur" in
  1719. -*)
  1720. COMPREPLY=( $( compgen -W "--advertise-addr --force-new-cluster --help --listen-addr" -- "$cur" ) )
  1721. ;;
  1722. esac
  1723. }
  1724. _docker_swarm_join() {
  1725. case "$prev" in
  1726. --advertise-addr)
  1727. if [[ $cur == *: ]] ; then
  1728. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1729. else
  1730. __docker_complete_local_interfaces
  1731. __docker_nospace
  1732. fi
  1733. return
  1734. ;;
  1735. --listen-addr)
  1736. if [[ $cur == *: ]] ; then
  1737. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1738. else
  1739. __docker_complete_local_interfaces --add 0.0.0.0
  1740. __docker_nospace
  1741. fi
  1742. return
  1743. ;;
  1744. --token)
  1745. return
  1746. ;;
  1747. esac
  1748. case "$cur" in
  1749. -*)
  1750. COMPREPLY=( $( compgen -W "--advertise-addr --help --listen-addr --token" -- "$cur" ) )
  1751. ;;
  1752. *:)
  1753. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1754. ;;
  1755. esac
  1756. }
  1757. _docker_swarm_join-token() {
  1758. case "$cur" in
  1759. -*)
  1760. COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) )
  1761. ;;
  1762. *)
  1763. local counter=$( __docker_pos_first_nonflag )
  1764. if [ $cword -eq $counter ]; then
  1765. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  1766. fi
  1767. ;;
  1768. esac
  1769. }
  1770. _docker_swarm_leave() {
  1771. case "$cur" in
  1772. -*)
  1773. COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) )
  1774. ;;
  1775. esac
  1776. }
  1777. _docker_swarm_update() {
  1778. case "$prev" in
  1779. --cert-expiry|--dispatcher-heartbeat|--task-history-limit)
  1780. return
  1781. ;;
  1782. esac
  1783. case "$cur" in
  1784. -*)
  1785. COMPREPLY=( $( compgen -W "--cert-expiry --dispatcher-heartbeat --help --task-history-limit" -- "$cur" ) )
  1786. ;;
  1787. esac
  1788. }
  1789. _docker_node() {
  1790. local subcommands="
  1791. demote
  1792. inspect
  1793. ls list
  1794. promote
  1795. rm remove
  1796. ps
  1797. update
  1798. "
  1799. __docker_subcommands "$subcommands" && return
  1800. case "$cur" in
  1801. -*)
  1802. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1803. ;;
  1804. *)
  1805. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1806. ;;
  1807. esac
  1808. }
  1809. _docker_node_demote() {
  1810. case "$cur" in
  1811. -*)
  1812. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1813. ;;
  1814. *)
  1815. __docker_complete_nodes --filter role=manager
  1816. esac
  1817. }
  1818. _docker_node_inspect() {
  1819. case "$prev" in
  1820. --format|-f)
  1821. return
  1822. ;;
  1823. esac
  1824. case "$cur" in
  1825. -*)
  1826. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  1827. ;;
  1828. *)
  1829. __docker_complete_nodes_plus_self
  1830. esac
  1831. }
  1832. _docker_node_list() {
  1833. _docker_node_ls
  1834. }
  1835. _docker_node_ls() {
  1836. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1837. case "$key" in
  1838. id)
  1839. __docker_complete_nodes --cur "${cur##*=}" --id
  1840. return
  1841. ;;
  1842. name)
  1843. __docker_complete_nodes --cur "${cur##*=}" --name
  1844. return
  1845. ;;
  1846. esac
  1847. case "$prev" in
  1848. --filter|-f)
  1849. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  1850. __docker_nospace
  1851. return
  1852. ;;
  1853. esac
  1854. case "$cur" in
  1855. -*)
  1856. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1857. ;;
  1858. esac
  1859. }
  1860. _docker_node_promote() {
  1861. case "$cur" in
  1862. -*)
  1863. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1864. ;;
  1865. *)
  1866. __docker_complete_nodes --filter role=worker
  1867. esac
  1868. }
  1869. _docker_node_remove() {
  1870. _docker_node_rm
  1871. }
  1872. _docker_node_rm() {
  1873. case "$cur" in
  1874. -*)
  1875. COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) )
  1876. ;;
  1877. *)
  1878. __docker_complete_nodes
  1879. esac
  1880. }
  1881. _docker_node_ps() {
  1882. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1883. case "$key" in
  1884. desired-state)
  1885. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  1886. return
  1887. ;;
  1888. name)
  1889. __docker_complete_services --cur "${cur##*=}" --name
  1890. return
  1891. ;;
  1892. esac
  1893. case "$prev" in
  1894. --filter|-f)
  1895. COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) )
  1896. __docker_nospace
  1897. return
  1898. ;;
  1899. esac
  1900. case "$cur" in
  1901. -*)
  1902. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  1903. ;;
  1904. *)
  1905. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  1906. if [ $cword -eq $counter ]; then
  1907. __docker_complete_nodes_plus_self
  1908. fi
  1909. ;;
  1910. esac
  1911. }
  1912. _docker_node_update() {
  1913. case "$prev" in
  1914. --availability)
  1915. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  1916. return
  1917. ;;
  1918. --role)
  1919. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  1920. return
  1921. ;;
  1922. --label-add|--label-rm)
  1923. return
  1924. ;;
  1925. esac
  1926. case "$cur" in
  1927. -*)
  1928. COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) )
  1929. ;;
  1930. *)
  1931. __docker_complete_nodes
  1932. esac
  1933. }
  1934. _docker_pause() {
  1935. case "$cur" in
  1936. -*)
  1937. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1938. ;;
  1939. *)
  1940. local counter=$(__docker_pos_first_nonflag)
  1941. if [ $cword -eq $counter ]; then
  1942. __docker_complete_containers_pauseable
  1943. fi
  1944. ;;
  1945. esac
  1946. }
  1947. _docker_port() {
  1948. case "$cur" in
  1949. -*)
  1950. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1951. ;;
  1952. *)
  1953. local counter=$(__docker_pos_first_nonflag)
  1954. if [ $cword -eq $counter ]; then
  1955. __docker_complete_containers_all
  1956. fi
  1957. ;;
  1958. esac
  1959. }
  1960. _docker_ps() {
  1961. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1962. case "$key" in
  1963. ancestor)
  1964. cur="${cur##*=}"
  1965. __docker_complete_images
  1966. return
  1967. ;;
  1968. before)
  1969. cur="${cur##*=}"
  1970. __docker_complete_containers_all
  1971. return
  1972. ;;
  1973. id)
  1974. cur="${cur##*=}"
  1975. __docker_complete_container_ids
  1976. return
  1977. ;;
  1978. name)
  1979. cur="${cur##*=}"
  1980. __docker_complete_container_names
  1981. return
  1982. ;;
  1983. network)
  1984. cur="${cur##*=}"
  1985. __docker_complete_networks
  1986. return
  1987. ;;
  1988. since)
  1989. cur="${cur##*=}"
  1990. __docker_complete_containers_all
  1991. return
  1992. ;;
  1993. status)
  1994. COMPREPLY=( $( compgen -W "created dead exited paused restarting running removing" -- "${cur##*=}" ) )
  1995. return
  1996. ;;
  1997. volume)
  1998. cur="${cur##*=}"
  1999. __docker_complete_volumes
  2000. return
  2001. ;;
  2002. esac
  2003. case "$prev" in
  2004. --filter|-f)
  2005. COMPREPLY=( $( compgen -S = -W "ancestor before exited id label name network since status volume" -- "$cur" ) )
  2006. __docker_nospace
  2007. return
  2008. ;;
  2009. --format|--last|-n)
  2010. return
  2011. ;;
  2012. esac
  2013. case "$cur" in
  2014. -*)
  2015. COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) )
  2016. ;;
  2017. esac
  2018. }
  2019. _docker_pull() {
  2020. case "$cur" in
  2021. -*)
  2022. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  2023. ;;
  2024. *)
  2025. local counter=$(__docker_pos_first_nonflag)
  2026. if [ $cword -eq $counter ]; then
  2027. for arg in "${COMP_WORDS[@]}"; do
  2028. case "$arg" in
  2029. --all-tags|-a)
  2030. __docker_complete_image_repos
  2031. return
  2032. ;;
  2033. esac
  2034. done
  2035. __docker_complete_image_repos_and_tags
  2036. fi
  2037. ;;
  2038. esac
  2039. }
  2040. _docker_push() {
  2041. case "$cur" in
  2042. -*)
  2043. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  2044. ;;
  2045. *)
  2046. local counter=$(__docker_pos_first_nonflag)
  2047. if [ $cword -eq $counter ]; then
  2048. __docker_complete_image_repos_and_tags
  2049. fi
  2050. ;;
  2051. esac
  2052. }
  2053. _docker_rename() {
  2054. case "$cur" in
  2055. -*)
  2056. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2057. ;;
  2058. *)
  2059. local counter=$(__docker_pos_first_nonflag)
  2060. if [ $cword -eq $counter ]; then
  2061. __docker_complete_containers_all
  2062. fi
  2063. ;;
  2064. esac
  2065. }
  2066. _docker_restart() {
  2067. case "$prev" in
  2068. --time|-t)
  2069. return
  2070. ;;
  2071. esac
  2072. case "$cur" in
  2073. -*)
  2074. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2075. ;;
  2076. *)
  2077. __docker_complete_containers_all
  2078. ;;
  2079. esac
  2080. }
  2081. _docker_rm() {
  2082. case "$cur" in
  2083. -*)
  2084. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  2085. ;;
  2086. *)
  2087. for arg in "${COMP_WORDS[@]}"; do
  2088. case "$arg" in
  2089. --force|-f)
  2090. __docker_complete_containers_all
  2091. return
  2092. ;;
  2093. esac
  2094. done
  2095. __docker_complete_containers_stopped
  2096. ;;
  2097. esac
  2098. }
  2099. _docker_rmi() {
  2100. case "$cur" in
  2101. -*)
  2102. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  2103. ;;
  2104. *)
  2105. __docker_complete_images
  2106. ;;
  2107. esac
  2108. }
  2109. _docker_run() {
  2110. local options_with_args="
  2111. --add-host
  2112. --attach -a
  2113. --blkio-weight
  2114. --blkio-weight-device
  2115. --cap-add
  2116. --cap-drop
  2117. --cgroup-parent
  2118. --cidfile
  2119. --cpu-period
  2120. --cpu-quota
  2121. --cpuset-cpus
  2122. --cpuset-mems
  2123. --cpu-shares -c
  2124. --device
  2125. --device-read-bps
  2126. --device-read-iops
  2127. --device-write-bps
  2128. --device-write-iops
  2129. --dns
  2130. --dns-opt
  2131. --dns-search
  2132. --entrypoint
  2133. --env -e
  2134. --env-file
  2135. --expose
  2136. --group-add
  2137. --hostname -h
  2138. --ip
  2139. --ip6
  2140. --ipc
  2141. --isolation
  2142. --kernel-memory
  2143. --label-file
  2144. --label -l
  2145. --link
  2146. --link-local-ip
  2147. --log-driver
  2148. --log-opt
  2149. --mac-address
  2150. --memory -m
  2151. --memory-swap
  2152. --memory-swappiness
  2153. --memory-reservation
  2154. --name
  2155. --network
  2156. --network-alias
  2157. --oom-score-adj
  2158. --pid
  2159. --pids-limit
  2160. --publish -p
  2161. --restart
  2162. --runtime
  2163. --security-opt
  2164. --shm-size
  2165. --stop-signal
  2166. --storage-opt
  2167. --tmpfs
  2168. --sysctl
  2169. --ulimit
  2170. --user -u
  2171. --userns
  2172. --uts
  2173. --volume-driver
  2174. --volumes-from
  2175. --volume -v
  2176. --workdir -w
  2177. "
  2178. local boolean_options="
  2179. --disable-content-trust=false
  2180. --help
  2181. --interactive -i
  2182. --oom-kill-disable
  2183. --privileged
  2184. --publish-all -P
  2185. --read-only
  2186. --tty -t
  2187. "
  2188. if [ "$command" = "run" ] ; then
  2189. options_with_args="$options_with_args
  2190. --detach-keys
  2191. --health-cmd
  2192. --health-interval
  2193. --health-retries
  2194. --health-timeout
  2195. "
  2196. boolean_options="$boolean_options
  2197. --detach -d
  2198. --no-healthcheck
  2199. --rm
  2200. --sig-proxy=false
  2201. "
  2202. __docker_complete_detach-keys && return
  2203. fi
  2204. local all_options="$options_with_args $boolean_options"
  2205. __docker_complete_log_driver_options && return
  2206. __docker_complete_restart && return
  2207. local key=$(__docker_map_key_of_current_option '--security-opt')
  2208. case "$key" in
  2209. label)
  2210. [[ $cur == *: ]] && return
  2211. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  2212. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  2213. __docker_nospace
  2214. fi
  2215. return
  2216. ;;
  2217. seccomp)
  2218. local cur=${cur##*=}
  2219. _filedir
  2220. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  2221. return
  2222. ;;
  2223. esac
  2224. case "$prev" in
  2225. --add-host)
  2226. case "$cur" in
  2227. *:)
  2228. __docker_complete_resolved_hostname
  2229. return
  2230. ;;
  2231. esac
  2232. ;;
  2233. --attach|-a)
  2234. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  2235. return
  2236. ;;
  2237. --cap-add|--cap-drop)
  2238. __docker_complete_capabilities
  2239. return
  2240. ;;
  2241. --cidfile|--env-file|--label-file)
  2242. _filedir
  2243. return
  2244. ;;
  2245. --device|--tmpfs|--volume|-v)
  2246. case "$cur" in
  2247. *:*)
  2248. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  2249. ;;
  2250. '')
  2251. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  2252. __docker_nospace
  2253. ;;
  2254. /*)
  2255. _filedir
  2256. __docker_nospace
  2257. ;;
  2258. esac
  2259. return
  2260. ;;
  2261. --env|-e)
  2262. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  2263. COMPREPLY=( $( compgen -e -- "$cur" ) )
  2264. __docker_nospace
  2265. return
  2266. ;;
  2267. --ipc)
  2268. case "$cur" in
  2269. *:*)
  2270. cur="${cur#*:}"
  2271. __docker_complete_containers_running
  2272. ;;
  2273. *)
  2274. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  2275. if [ "$COMPREPLY" = "container:" ]; then
  2276. __docker_nospace
  2277. fi
  2278. ;;
  2279. esac
  2280. return
  2281. ;;
  2282. --isolation)
  2283. __docker_complete_isolation
  2284. return
  2285. ;;
  2286. --link)
  2287. case "$cur" in
  2288. *:*)
  2289. ;;
  2290. *)
  2291. __docker_complete_containers_running
  2292. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  2293. __docker_nospace
  2294. ;;
  2295. esac
  2296. return
  2297. ;;
  2298. --log-driver)
  2299. __docker_complete_log_drivers
  2300. return
  2301. ;;
  2302. --log-opt)
  2303. __docker_complete_log_options
  2304. return
  2305. ;;
  2306. --network)
  2307. case "$cur" in
  2308. container:*)
  2309. local cur=${cur#*:}
  2310. __docker_complete_containers_all
  2311. ;;
  2312. *)
  2313. COMPREPLY=( $( compgen -W "$(__docker_plugins Network) $(__docker_networks) container:" -- "$cur") )
  2314. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  2315. __docker_nospace
  2316. fi
  2317. ;;
  2318. esac
  2319. return
  2320. ;;
  2321. --pid)
  2322. case "$cur" in
  2323. *:*)
  2324. cur="${cur#*:}"
  2325. __docker_complete_containers_running
  2326. ;;
  2327. *)
  2328. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  2329. if [ "$COMPREPLY" = "container:" ]; then
  2330. __docker_nospace
  2331. fi
  2332. ;;
  2333. esac
  2334. return
  2335. ;;
  2336. --runtime)
  2337. __docker_complete_runtimes
  2338. return
  2339. ;;
  2340. --security-opt)
  2341. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  2342. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  2343. __docker_nospace
  2344. fi
  2345. return
  2346. ;;
  2347. --storage-opt)
  2348. COMPREPLY=( $( compgen -W "size" -S = -- "$cur") )
  2349. __docker_nospace
  2350. return
  2351. ;;
  2352. --user|-u)
  2353. __docker_complete_user_group
  2354. return
  2355. ;;
  2356. --userns)
  2357. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  2358. return
  2359. ;;
  2360. --volume-driver)
  2361. __docker_complete_plugins Volume
  2362. return
  2363. ;;
  2364. --volumes-from)
  2365. __docker_complete_containers_all
  2366. return
  2367. ;;
  2368. $(__docker_to_extglob "$options_with_args") )
  2369. return
  2370. ;;
  2371. esac
  2372. case "$cur" in
  2373. -*)
  2374. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2375. ;;
  2376. *)
  2377. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2378. if [ $cword -eq $counter ]; then
  2379. __docker_complete_images
  2380. fi
  2381. ;;
  2382. esac
  2383. }
  2384. _docker_save() {
  2385. case "$prev" in
  2386. --output|-o)
  2387. _filedir
  2388. return
  2389. ;;
  2390. esac
  2391. case "$cur" in
  2392. -*)
  2393. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  2394. ;;
  2395. *)
  2396. __docker_complete_images
  2397. ;;
  2398. esac
  2399. }
  2400. _docker_search() {
  2401. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2402. case "$key" in
  2403. is-automated)
  2404. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2405. return
  2406. ;;
  2407. is-official)
  2408. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2409. return
  2410. ;;
  2411. esac
  2412. case "$prev" in
  2413. --filter|-f)
  2414. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  2415. __docker_nospace
  2416. return
  2417. ;;
  2418. --limit)
  2419. return
  2420. ;;
  2421. esac
  2422. case "$cur" in
  2423. -*)
  2424. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  2425. ;;
  2426. esac
  2427. }
  2428. _docker_start() {
  2429. __docker_complete_detach-keys && return
  2430. case "$cur" in
  2431. -*)
  2432. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  2433. ;;
  2434. *)
  2435. __docker_complete_containers_stopped
  2436. ;;
  2437. esac
  2438. }
  2439. _docker_stats() {
  2440. case "$cur" in
  2441. -*)
  2442. COMPREPLY=( $( compgen -W "--all -a --help --no-stream" -- "$cur" ) )
  2443. ;;
  2444. *)
  2445. __docker_complete_containers_running
  2446. ;;
  2447. esac
  2448. }
  2449. _docker_stop() {
  2450. case "$prev" in
  2451. --time|-t)
  2452. return
  2453. ;;
  2454. esac
  2455. case "$cur" in
  2456. -*)
  2457. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2458. ;;
  2459. *)
  2460. __docker_complete_containers_running
  2461. ;;
  2462. esac
  2463. }
  2464. _docker_tag() {
  2465. case "$cur" in
  2466. -*)
  2467. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2468. ;;
  2469. *)
  2470. local counter=$(__docker_pos_first_nonflag)
  2471. if [ $cword -eq $counter ]; then
  2472. __docker_complete_image_repos_and_tags
  2473. return
  2474. fi
  2475. (( counter++ ))
  2476. if [ $cword -eq $counter ]; then
  2477. __docker_complete_image_repos_and_tags
  2478. return
  2479. fi
  2480. ;;
  2481. esac
  2482. }
  2483. _docker_unpause() {
  2484. case "$cur" in
  2485. -*)
  2486. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2487. ;;
  2488. *)
  2489. local counter=$(__docker_pos_first_nonflag)
  2490. if [ $cword -eq $counter ]; then
  2491. __docker_complete_containers_unpauseable
  2492. fi
  2493. ;;
  2494. esac
  2495. }
  2496. _docker_update() {
  2497. local options_with_args="
  2498. --blkio-weight
  2499. --cpu-period
  2500. --cpu-quota
  2501. --cpuset-cpus
  2502. --cpuset-mems
  2503. --cpu-shares -c
  2504. --kernel-memory
  2505. --memory -m
  2506. --memory-reservation
  2507. --memory-swap
  2508. --restart
  2509. "
  2510. local boolean_options="
  2511. --help
  2512. "
  2513. local all_options="$options_with_args $boolean_options"
  2514. __docker_complete_restart && return
  2515. case "$prev" in
  2516. $(__docker_to_extglob "$options_with_args") )
  2517. return
  2518. ;;
  2519. esac
  2520. case "$cur" in
  2521. -*)
  2522. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2523. ;;
  2524. *)
  2525. __docker_complete_containers_all
  2526. ;;
  2527. esac
  2528. }
  2529. _docker_top() {
  2530. case "$cur" in
  2531. -*)
  2532. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2533. ;;
  2534. *)
  2535. local counter=$(__docker_pos_first_nonflag)
  2536. if [ $cword -eq $counter ]; then
  2537. __docker_complete_containers_running
  2538. fi
  2539. ;;
  2540. esac
  2541. }
  2542. _docker_version() {
  2543. case "$cur" in
  2544. -*)
  2545. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2546. ;;
  2547. esac
  2548. }
  2549. _docker_volume_create() {
  2550. case "$prev" in
  2551. --driver|-d)
  2552. __docker_complete_plugins Volume
  2553. return
  2554. ;;
  2555. --label|--opt|-o)
  2556. return
  2557. ;;
  2558. esac
  2559. case "$cur" in
  2560. -*)
  2561. COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) )
  2562. ;;
  2563. esac
  2564. }
  2565. _docker_volume_inspect() {
  2566. case "$prev" in
  2567. --format|-f)
  2568. return
  2569. ;;
  2570. esac
  2571. case "$cur" in
  2572. -*)
  2573. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2574. ;;
  2575. *)
  2576. __docker_complete_volumes
  2577. ;;
  2578. esac
  2579. }
  2580. _docker_volume_ls() {
  2581. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2582. case "$key" in
  2583. dangling)
  2584. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  2585. return
  2586. ;;
  2587. driver)
  2588. cur=${cur##*=}
  2589. __docker_complete_plugins Volume
  2590. return
  2591. ;;
  2592. name)
  2593. cur=${cur##*=}
  2594. __docker_complete_volumes
  2595. return
  2596. ;;
  2597. esac
  2598. case "$prev" in
  2599. --filter|-f)
  2600. COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) )
  2601. __docker_nospace
  2602. return
  2603. ;;
  2604. --format)
  2605. return
  2606. ;;
  2607. esac
  2608. case "$cur" in
  2609. -*)
  2610. COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
  2611. ;;
  2612. esac
  2613. }
  2614. _docker_volume_rm() {
  2615. case "$cur" in
  2616. -*)
  2617. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2618. ;;
  2619. *)
  2620. __docker_complete_volumes
  2621. ;;
  2622. esac
  2623. }
  2624. _docker_volume() {
  2625. local subcommands="
  2626. create
  2627. inspect
  2628. ls
  2629. rm
  2630. "
  2631. __docker_subcommands "$subcommands" && return
  2632. case "$cur" in
  2633. -*)
  2634. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2635. ;;
  2636. *)
  2637. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2638. ;;
  2639. esac
  2640. }
  2641. _docker_wait() {
  2642. case "$cur" in
  2643. -*)
  2644. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2645. ;;
  2646. *)
  2647. __docker_complete_containers_all
  2648. ;;
  2649. esac
  2650. }
  2651. _docker() {
  2652. local previous_extglob_setting=$(shopt -p extglob)
  2653. shopt -s extglob
  2654. local commands=(
  2655. attach
  2656. build
  2657. commit
  2658. cp
  2659. create
  2660. daemon
  2661. diff
  2662. events
  2663. exec
  2664. export
  2665. history
  2666. images
  2667. import
  2668. info
  2669. inspect
  2670. kill
  2671. load
  2672. login
  2673. logout
  2674. logs
  2675. network
  2676. node
  2677. pause
  2678. port
  2679. ps
  2680. pull
  2681. push
  2682. rename
  2683. restart
  2684. rm
  2685. rmi
  2686. run
  2687. save
  2688. search
  2689. service
  2690. start
  2691. stats
  2692. stop
  2693. swarm
  2694. tag
  2695. top
  2696. unpause
  2697. update
  2698. version
  2699. volume
  2700. wait
  2701. )
  2702. # These options are valid as global options for all client commands
  2703. # and valid as command options for `docker daemon`
  2704. local global_boolean_options="
  2705. --debug -D
  2706. --tls
  2707. --tlsverify
  2708. "
  2709. local global_options_with_args="
  2710. --config
  2711. --host -H
  2712. --log-level -l
  2713. --tlscacert
  2714. --tlscert
  2715. --tlskey
  2716. "
  2717. local host config
  2718. COMPREPLY=()
  2719. local cur prev words cword
  2720. _get_comp_words_by_ref -n : cur prev words cword
  2721. local command='docker' command_pos=0 subcommand_pos
  2722. local counter=1
  2723. while [ $counter -lt $cword ]; do
  2724. case "${words[$counter]}" in
  2725. # save host so that completion can use custom daemon
  2726. --host|-H)
  2727. (( counter++ ))
  2728. host="${words[$counter]}"
  2729. ;;
  2730. # save config so that completion can use custom configuration directories
  2731. --config)
  2732. (( counter++ ))
  2733. config="${words[$counter]}"
  2734. ;;
  2735. $(__docker_to_extglob "$global_options_with_args") )
  2736. (( counter++ ))
  2737. ;;
  2738. -*)
  2739. ;;
  2740. =)
  2741. (( counter++ ))
  2742. ;;
  2743. *)
  2744. command="${words[$counter]}"
  2745. command_pos=$counter
  2746. break
  2747. ;;
  2748. esac
  2749. (( counter++ ))
  2750. done
  2751. local binary="${words[0]}"
  2752. if [[ $binary == ?(*/)dockerd ]] ; then
  2753. # for the dockerd binary, we reuse completion of `docker daemon`.
  2754. # dockerd does not have subcommands and global options.
  2755. command=daemon
  2756. command_pos=0
  2757. fi
  2758. local completions_func=_docker_${command}
  2759. declare -F $completions_func >/dev/null && $completions_func
  2760. eval "$previous_extglob_setting"
  2761. return 0
  2762. }
  2763. eval "$__docker_previous_extglob_setting"
  2764. unset __docker_previous_extglob_setting
  2765. complete -F _docker docker dockerd