docker 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012
  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-index splunk-insecureskipverify splunk-source splunk-sourcetype splunk-token splunk-url 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)
  567. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  568. return
  569. ;;
  570. esac
  571. return 1
  572. }
  573. __docker_complete_log_levels() {
  574. COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) )
  575. }
  576. __docker_complete_restart() {
  577. case "$prev" in
  578. --restart)
  579. case "$cur" in
  580. on-failure:*)
  581. ;;
  582. *)
  583. COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") )
  584. ;;
  585. esac
  586. return
  587. ;;
  588. esac
  589. return 1
  590. }
  591. # a selection of the available signals that is most likely of interest in the
  592. # context of docker containers.
  593. __docker_complete_signals() {
  594. local signals=(
  595. SIGCONT
  596. SIGHUP
  597. SIGINT
  598. SIGKILL
  599. SIGQUIT
  600. SIGSTOP
  601. SIGTERM
  602. SIGUSR1
  603. SIGUSR2
  604. )
  605. COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) )
  606. }
  607. __docker_complete_user_group() {
  608. if [[ $cur == *:* ]] ; then
  609. COMPREPLY=( $(compgen -g -- "${cur#*:}") )
  610. else
  611. COMPREPLY=( $(compgen -u -S : -- "$cur") )
  612. __docker_nospace
  613. fi
  614. }
  615. # global options that may appear after the docker command
  616. _docker_docker() {
  617. local boolean_options="
  618. $global_boolean_options
  619. --help
  620. --version -v
  621. "
  622. case "$prev" in
  623. --config)
  624. _filedir -d
  625. return
  626. ;;
  627. --log-level|-l)
  628. __docker_complete_log_levels
  629. return
  630. ;;
  631. $(__docker_to_extglob "$global_options_with_args") )
  632. return
  633. ;;
  634. esac
  635. case "$cur" in
  636. -*)
  637. COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) )
  638. ;;
  639. *)
  640. local counter=$( __docker_pos_first_nonflag "$(__docker_to_extglob "$global_options_with_args")" )
  641. if [ $cword -eq $counter ]; then
  642. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  643. fi
  644. ;;
  645. esac
  646. }
  647. _docker_attach() {
  648. __docker_complete_detach-keys && return
  649. case "$cur" in
  650. -*)
  651. COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) )
  652. ;;
  653. *)
  654. local counter=$(__docker_pos_first_nonflag '--detach-keys')
  655. if [ $cword -eq $counter ]; then
  656. __docker_complete_containers_running
  657. fi
  658. ;;
  659. esac
  660. }
  661. _docker_build() {
  662. local options_with_args="
  663. --build-arg
  664. --cgroup-parent
  665. --cpuset-cpus
  666. --cpuset-mems
  667. --cpu-shares -c
  668. --cpu-period
  669. --cpu-quota
  670. --file -f
  671. --isolation
  672. --label
  673. --memory -m
  674. --memory-swap
  675. --shm-size
  676. --tag -t
  677. --ulimit
  678. "
  679. local boolean_options="
  680. --disable-content-trust=false
  681. --force-rm
  682. --help
  683. --no-cache
  684. --pull
  685. --quiet -q
  686. --rm
  687. "
  688. local all_options="$options_with_args $boolean_options"
  689. case "$prev" in
  690. --build-arg)
  691. COMPREPLY=( $( compgen -e -- "$cur" ) )
  692. __docker_nospace
  693. return
  694. ;;
  695. --file|-f)
  696. _filedir
  697. return
  698. ;;
  699. --isolation)
  700. __docker_complete_isolation
  701. return
  702. ;;
  703. --tag|-t)
  704. __docker_complete_image_repos_and_tags
  705. return
  706. ;;
  707. $(__docker_to_extglob "$options_with_args") )
  708. return
  709. ;;
  710. esac
  711. case "$cur" in
  712. -*)
  713. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  714. ;;
  715. *)
  716. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  717. if [ $cword -eq $counter ]; then
  718. _filedir -d
  719. fi
  720. ;;
  721. esac
  722. }
  723. _docker_commit() {
  724. case "$prev" in
  725. --author|-a|--change|-c|--message|-m)
  726. return
  727. ;;
  728. esac
  729. case "$cur" in
  730. -*)
  731. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) )
  732. ;;
  733. *)
  734. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  735. if [ $cword -eq $counter ]; then
  736. __docker_complete_containers_all
  737. return
  738. fi
  739. (( counter++ ))
  740. if [ $cword -eq $counter ]; then
  741. __docker_complete_image_repos_and_tags
  742. return
  743. fi
  744. ;;
  745. esac
  746. }
  747. _docker_cp() {
  748. case "$cur" in
  749. -*)
  750. COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) )
  751. ;;
  752. *)
  753. local counter=$(__docker_pos_first_nonflag)
  754. if [ $cword -eq $counter ]; then
  755. case "$cur" in
  756. *:)
  757. return
  758. ;;
  759. *)
  760. # combined container and filename completion
  761. _filedir
  762. local files=( ${COMPREPLY[@]} )
  763. __docker_complete_containers_all
  764. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  765. local containers=( ${COMPREPLY[@]} )
  766. COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) )
  767. if [[ "$COMPREPLY" == *: ]]; then
  768. __docker_nospace
  769. fi
  770. return
  771. ;;
  772. esac
  773. fi
  774. (( counter++ ))
  775. if [ $cword -eq $counter ]; then
  776. if [ -e "$prev" ]; then
  777. __docker_complete_containers_all
  778. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  779. __docker_nospace
  780. else
  781. _filedir
  782. fi
  783. return
  784. fi
  785. ;;
  786. esac
  787. }
  788. _docker_create() {
  789. _docker_run
  790. }
  791. _docker_daemon() {
  792. local boolean_options="
  793. $global_boolean_options
  794. --disable-legacy-registry
  795. --help
  796. --icc=false
  797. --ip-forward=false
  798. --ip-masq=false
  799. --iptables=false
  800. --ipv6
  801. --live-restore
  802. --raw-logs
  803. --selinux-enabled
  804. --userland-proxy=false
  805. "
  806. local options_with_args="
  807. $global_options_with_args
  808. --add-runtime
  809. --api-cors-header
  810. --authorization-plugin
  811. --bip
  812. --bridge -b
  813. --cgroup-parent
  814. --cluster-advertise
  815. --cluster-store
  816. --cluster-store-opt
  817. --config-file
  818. --containerd
  819. --default-gateway
  820. --default-gateway-v6
  821. --default-ulimit
  822. --dns
  823. --dns-search
  824. --dns-opt
  825. --exec-opt
  826. --exec-root
  827. --fixed-cidr
  828. --fixed-cidr-v6
  829. --graph -g
  830. --group -G
  831. --insecure-registry
  832. --ip
  833. --label
  834. --log-driver
  835. --log-opt
  836. --max-concurrent-downloads
  837. --max-concurrent-uploads
  838. --mtu
  839. --oom-score-adjust
  840. --pidfile -p
  841. --registry-mirror
  842. --storage-driver -s
  843. --storage-opt
  844. --userns-remap
  845. "
  846. __docker_complete_log_driver_options && return
  847. key=$(__docker_map_key_of_current_option '--cluster-store-opt')
  848. case "$key" in
  849. kv.*file)
  850. cur=${cur##*=}
  851. _filedir
  852. return
  853. ;;
  854. esac
  855. local key=$(__docker_map_key_of_current_option '--storage-opt')
  856. case "$key" in
  857. dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion)
  858. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  859. return
  860. ;;
  861. dm.fs)
  862. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) )
  863. return
  864. ;;
  865. dm.thinpooldev)
  866. cur=${cur##*=}
  867. _filedir
  868. return
  869. ;;
  870. esac
  871. case "$prev" in
  872. --authorization-plugin)
  873. __docker_complete_plugins Authorization
  874. return
  875. ;;
  876. --cluster-store)
  877. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  878. __docker_nospace
  879. return
  880. ;;
  881. --cluster-store-opt)
  882. COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) )
  883. __docker_nospace
  884. return
  885. ;;
  886. --exec-root|--graph|-g)
  887. _filedir -d
  888. return
  889. ;;
  890. --log-driver)
  891. __docker_complete_log_drivers
  892. return
  893. ;;
  894. --config-file|--containerd|--pidfile|-p|--tlscacert|--tlscert|--tlskey)
  895. _filedir
  896. return
  897. ;;
  898. --storage-driver|-s)
  899. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  900. return
  901. ;;
  902. --storage-opt)
  903. local btrfs_options="btrfs.min_space"
  904. local devicemapper_options="
  905. dm.basesize
  906. dm.blkdiscard
  907. dm.blocksize
  908. dm.fs
  909. dm.loopdatasize
  910. dm.loopmetadatasize
  911. dm.min_free_space
  912. dm.mkfsarg
  913. dm.mountopt
  914. dm.override_udev_sync_check
  915. dm.thinpooldev
  916. dm.use_deferred_deletion
  917. dm.use_deferred_removal
  918. "
  919. local zfs_options="zfs.fsname"
  920. case $(__docker_value_of_option '--storage-driver|-s') in
  921. '')
  922. COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) )
  923. ;;
  924. btrfs)
  925. COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) )
  926. ;;
  927. devicemapper)
  928. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  929. ;;
  930. zfs)
  931. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  932. ;;
  933. *)
  934. return
  935. ;;
  936. esac
  937. __docker_nospace
  938. return
  939. ;;
  940. --log-level|-l)
  941. __docker_complete_log_levels
  942. return
  943. ;;
  944. --log-opt)
  945. __docker_complete_log_options
  946. return
  947. ;;
  948. --userns-remap)
  949. __docker_complete_user_group
  950. return
  951. ;;
  952. $(__docker_to_extglob "$options_with_args") )
  953. return
  954. ;;
  955. esac
  956. case "$cur" in
  957. -*)
  958. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  959. ;;
  960. esac
  961. }
  962. _docker_diff() {
  963. case "$cur" in
  964. -*)
  965. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  966. ;;
  967. *)
  968. local counter=$(__docker_pos_first_nonflag)
  969. if [ $cword -eq $counter ]; then
  970. __docker_complete_containers_all
  971. fi
  972. ;;
  973. esac
  974. }
  975. _docker_events() {
  976. local key=$(__docker_map_key_of_current_option '-f|--filter')
  977. case "$key" in
  978. container)
  979. cur="${cur##*=}"
  980. __docker_complete_containers_all
  981. return
  982. ;;
  983. daemon)
  984. local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
  985. COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
  986. return
  987. ;;
  988. event)
  989. COMPREPLY=( $( compgen -W "
  990. attach
  991. commit
  992. connect
  993. copy
  994. create
  995. delete
  996. destroy
  997. detach
  998. die
  999. disconnect
  1000. exec_create
  1001. exec_detach
  1002. exec_start
  1003. export
  1004. import
  1005. kill
  1006. load
  1007. mount
  1008. oom
  1009. pause
  1010. pull
  1011. push
  1012. reload
  1013. rename
  1014. resize
  1015. restart
  1016. save
  1017. start
  1018. stop
  1019. tag
  1020. top
  1021. unmount
  1022. unpause
  1023. untag
  1024. update
  1025. " -- "${cur##*=}" ) )
  1026. return
  1027. ;;
  1028. image)
  1029. cur="${cur##*=}"
  1030. __docker_complete_images
  1031. return
  1032. ;;
  1033. network)
  1034. cur="${cur##*=}"
  1035. __docker_complete_networks
  1036. return
  1037. ;;
  1038. type)
  1039. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  1040. return
  1041. ;;
  1042. volume)
  1043. cur="${cur##*=}"
  1044. __docker_complete_volumes
  1045. return
  1046. ;;
  1047. esac
  1048. case "$prev" in
  1049. --filter|-f)
  1050. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  1051. __docker_nospace
  1052. return
  1053. ;;
  1054. --since|--until)
  1055. return
  1056. ;;
  1057. esac
  1058. case "$cur" in
  1059. -*)
  1060. COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) )
  1061. ;;
  1062. esac
  1063. }
  1064. _docker_exec() {
  1065. __docker_complete_detach-keys && return
  1066. case "$prev" in
  1067. --user|-u)
  1068. __docker_complete_user_group
  1069. return
  1070. ;;
  1071. esac
  1072. case "$cur" in
  1073. -*)
  1074. COMPREPLY=( $( compgen -W "--detach -d --detach-keys --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  1075. ;;
  1076. *)
  1077. __docker_complete_containers_running
  1078. ;;
  1079. esac
  1080. }
  1081. _docker_export() {
  1082. case "$cur" in
  1083. -*)
  1084. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1085. ;;
  1086. *)
  1087. local counter=$(__docker_pos_first_nonflag)
  1088. if [ $cword -eq $counter ]; then
  1089. __docker_complete_containers_all
  1090. fi
  1091. ;;
  1092. esac
  1093. }
  1094. _docker_help() {
  1095. local counter=$(__docker_pos_first_nonflag)
  1096. if [ $cword -eq $counter ]; then
  1097. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  1098. fi
  1099. }
  1100. _docker_history() {
  1101. case "$cur" in
  1102. -*)
  1103. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  1104. ;;
  1105. *)
  1106. local counter=$(__docker_pos_first_nonflag)
  1107. if [ $cword -eq $counter ]; then
  1108. __docker_complete_images
  1109. fi
  1110. ;;
  1111. esac
  1112. }
  1113. _docker_images() {
  1114. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1115. case "$key" in
  1116. before)
  1117. cur="${cur##*=}"
  1118. __docker_complete_images
  1119. return
  1120. ;;
  1121. dangling)
  1122. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1123. return
  1124. ;;
  1125. label)
  1126. return
  1127. ;;
  1128. since)
  1129. cur="${cur##*=}"
  1130. __docker_complete_images
  1131. return
  1132. ;;
  1133. esac
  1134. case "$prev" in
  1135. --filter|-f)
  1136. COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) )
  1137. __docker_nospace
  1138. return
  1139. ;;
  1140. --format)
  1141. return
  1142. ;;
  1143. esac
  1144. case "$cur" in
  1145. -*)
  1146. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1147. ;;
  1148. =)
  1149. return
  1150. ;;
  1151. *)
  1152. __docker_complete_image_repos
  1153. ;;
  1154. esac
  1155. }
  1156. _docker_import() {
  1157. case "$prev" in
  1158. --change|-c|--message|-m)
  1159. return
  1160. ;;
  1161. esac
  1162. case "$cur" in
  1163. -*)
  1164. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1165. ;;
  1166. *)
  1167. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1168. if [ $cword -eq $counter ]; then
  1169. return
  1170. fi
  1171. (( counter++ ))
  1172. if [ $cword -eq $counter ]; then
  1173. __docker_complete_image_repos_and_tags
  1174. return
  1175. fi
  1176. ;;
  1177. esac
  1178. }
  1179. _docker_info() {
  1180. case "$prev" in
  1181. --format|-f)
  1182. return
  1183. ;;
  1184. esac
  1185. case "$cur" in
  1186. -*)
  1187. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1188. ;;
  1189. esac
  1190. }
  1191. _docker_inspect() {
  1192. case "$prev" in
  1193. --format|-f)
  1194. return
  1195. ;;
  1196. --type)
  1197. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  1198. return
  1199. ;;
  1200. esac
  1201. case "$cur" in
  1202. -*)
  1203. COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) )
  1204. ;;
  1205. *)
  1206. case $(__docker_value_of_option --type) in
  1207. '')
  1208. __docker_complete_containers_and_images
  1209. ;;
  1210. container)
  1211. __docker_complete_containers_all
  1212. ;;
  1213. image)
  1214. __docker_complete_images
  1215. ;;
  1216. esac
  1217. esac
  1218. }
  1219. _docker_kill() {
  1220. case "$prev" in
  1221. --signal|-s)
  1222. __docker_complete_signals
  1223. return
  1224. ;;
  1225. esac
  1226. case "$cur" in
  1227. -*)
  1228. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  1229. ;;
  1230. *)
  1231. __docker_complete_containers_running
  1232. ;;
  1233. esac
  1234. }
  1235. _docker_load() {
  1236. case "$prev" in
  1237. --input|-i)
  1238. _filedir
  1239. return
  1240. ;;
  1241. esac
  1242. case "$cur" in
  1243. -*)
  1244. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1245. ;;
  1246. esac
  1247. }
  1248. _docker_login() {
  1249. case "$prev" in
  1250. --password|-p|--username|-u)
  1251. return
  1252. ;;
  1253. esac
  1254. case "$cur" in
  1255. -*)
  1256. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  1257. ;;
  1258. esac
  1259. }
  1260. _docker_logout() {
  1261. case "$cur" in
  1262. -*)
  1263. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1264. ;;
  1265. esac
  1266. }
  1267. _docker_logs() {
  1268. case "$prev" in
  1269. --since|--tail)
  1270. return
  1271. ;;
  1272. esac
  1273. case "$cur" in
  1274. -*)
  1275. COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  1276. ;;
  1277. *)
  1278. local counter=$(__docker_pos_first_nonflag '--tail')
  1279. if [ $cword -eq $counter ]; then
  1280. __docker_complete_containers_all
  1281. fi
  1282. ;;
  1283. esac
  1284. }
  1285. _docker_network_connect() {
  1286. local options_with_args="
  1287. --alias
  1288. --ip
  1289. --ip6
  1290. --link
  1291. --link-local-ip
  1292. "
  1293. local boolean_options="
  1294. --help
  1295. "
  1296. case "$prev" in
  1297. --link)
  1298. case "$cur" in
  1299. *:*)
  1300. ;;
  1301. *)
  1302. __docker_complete_containers_running
  1303. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1304. __docker_nospace
  1305. ;;
  1306. esac
  1307. return
  1308. ;;
  1309. $(__docker_to_extglob "$options_with_args") )
  1310. return
  1311. ;;
  1312. esac
  1313. case "$cur" in
  1314. -*)
  1315. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1316. ;;
  1317. *)
  1318. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1319. if [ $cword -eq $counter ]; then
  1320. __docker_complete_networks
  1321. elif [ $cword -eq $(($counter + 1)) ]; then
  1322. __docker_complete_containers_all
  1323. fi
  1324. ;;
  1325. esac
  1326. }
  1327. _docker_network_create() {
  1328. case "$prev" in
  1329. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  1330. return
  1331. ;;
  1332. --ipam-driver)
  1333. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  1334. return
  1335. ;;
  1336. --driver|-d)
  1337. local plugins="$(__docker_plugins Network) macvlan"
  1338. # remove drivers that allow one instance only
  1339. plugins=${plugins/ host / }
  1340. plugins=${plugins/ null / }
  1341. COMPREPLY=( $(compgen -W "$plugins" -- "$cur") )
  1342. return
  1343. ;;
  1344. --label)
  1345. return
  1346. ;;
  1347. esac
  1348. case "$cur" in
  1349. -*)
  1350. COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  1351. ;;
  1352. esac
  1353. }
  1354. _docker_network_disconnect() {
  1355. case "$cur" in
  1356. -*)
  1357. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1358. ;;
  1359. *)
  1360. local counter=$(__docker_pos_first_nonflag)
  1361. if [ $cword -eq $counter ]; then
  1362. __docker_complete_networks
  1363. elif [ $cword -eq $(($counter + 1)) ]; then
  1364. __docker_complete_containers_in_network "$prev"
  1365. fi
  1366. ;;
  1367. esac
  1368. }
  1369. _docker_network_inspect() {
  1370. case "$prev" in
  1371. --format|-f)
  1372. return
  1373. ;;
  1374. esac
  1375. case "$cur" in
  1376. -*)
  1377. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1378. ;;
  1379. *)
  1380. __docker_complete_networks
  1381. esac
  1382. }
  1383. _docker_network_ls() {
  1384. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1385. case "$key" in
  1386. driver)
  1387. local plugins=" $(__docker_plugins Network) "
  1388. COMPREPLY=( $(compgen -W "$plugins" -- "${cur##*=}") )
  1389. return
  1390. ;;
  1391. id)
  1392. cur="${cur##*=}"
  1393. __docker_complete_network_ids
  1394. return
  1395. ;;
  1396. name)
  1397. cur="${cur##*=}"
  1398. __docker_complete_network_names
  1399. return
  1400. ;;
  1401. type)
  1402. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  1403. return
  1404. ;;
  1405. esac
  1406. case "$prev" in
  1407. --filter|-f)
  1408. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  1409. __docker_nospace
  1410. return
  1411. ;;
  1412. esac
  1413. case "$cur" in
  1414. -*)
  1415. COMPREPLY=( $( compgen -W "--filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
  1416. ;;
  1417. esac
  1418. }
  1419. _docker_network_rm() {
  1420. case "$cur" in
  1421. -*)
  1422. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1423. ;;
  1424. *)
  1425. __docker_complete_networks type=custom
  1426. esac
  1427. }
  1428. _docker_network() {
  1429. local subcommands="
  1430. connect
  1431. create
  1432. disconnect
  1433. inspect
  1434. ls
  1435. rm
  1436. "
  1437. __docker_subcommands "$subcommands" && return
  1438. case "$cur" in
  1439. -*)
  1440. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1441. ;;
  1442. *)
  1443. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1444. ;;
  1445. esac
  1446. }
  1447. _docker_service() {
  1448. local subcommands="
  1449. create
  1450. inspect
  1451. ls list
  1452. rm remove
  1453. scale
  1454. ps
  1455. update
  1456. "
  1457. __docker_subcommands "$subcommands" && return
  1458. case "$cur" in
  1459. -*)
  1460. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1461. ;;
  1462. *)
  1463. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1464. ;;
  1465. esac
  1466. }
  1467. _docker_service_create() {
  1468. _docker_service_update
  1469. }
  1470. _docker_service_inspect() {
  1471. case "$prev" in
  1472. --format|-f)
  1473. return
  1474. ;;
  1475. esac
  1476. case "$cur" in
  1477. -*)
  1478. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  1479. ;;
  1480. *)
  1481. __docker_complete_services
  1482. esac
  1483. }
  1484. _docker_service_list() {
  1485. _docker_service_ls
  1486. }
  1487. _docker_service_ls() {
  1488. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1489. case "$key" in
  1490. id)
  1491. __docker_complete_services --cur "${cur##*=}" --id
  1492. return
  1493. ;;
  1494. name)
  1495. __docker_complete_services --cur "${cur##*=}" --name
  1496. return
  1497. ;;
  1498. esac
  1499. case "$prev" in
  1500. --filter|-f)
  1501. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  1502. __docker_nospace
  1503. return
  1504. ;;
  1505. esac
  1506. case "$cur" in
  1507. -*)
  1508. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1509. ;;
  1510. esac
  1511. }
  1512. _docker_service_remove() {
  1513. _docker_service_rm
  1514. }
  1515. _docker_service_rm() {
  1516. case "$cur" in
  1517. -*)
  1518. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1519. ;;
  1520. *)
  1521. __docker_complete_services
  1522. esac
  1523. }
  1524. _docker_service_scale() {
  1525. case "$cur" in
  1526. -*)
  1527. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1528. ;;
  1529. *)
  1530. __docker_complete_services
  1531. __docker_append_to_completions "="
  1532. __docker_nospace
  1533. ;;
  1534. esac
  1535. }
  1536. _docker_service_ps() {
  1537. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1538. case "$key" in
  1539. desired-state)
  1540. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  1541. return
  1542. ;;
  1543. name)
  1544. __docker_complete_services --cur "${cur##*=}" --name
  1545. return
  1546. ;;
  1547. esac
  1548. case "$prev" in
  1549. --filter|-f)
  1550. COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) )
  1551. __docker_nospace
  1552. return
  1553. ;;
  1554. esac
  1555. case "$cur" in
  1556. -*)
  1557. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve" -- "$cur" ) )
  1558. ;;
  1559. *)
  1560. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  1561. if [ $cword -eq $counter ]; then
  1562. __docker_complete_services
  1563. fi
  1564. ;;
  1565. esac
  1566. }
  1567. _docker_service_update() {
  1568. local $subcommand="${words[$subcommand_pos]}"
  1569. local options_with_args="
  1570. --constraint
  1571. --endpoint-mode
  1572. --env -e
  1573. --label -l
  1574. --limit-cpu
  1575. --limit-memory
  1576. --log-driver
  1577. --log-opt
  1578. --mount
  1579. --name
  1580. --network
  1581. --publish -p
  1582. --replicas
  1583. --reserve-cpu
  1584. --reserve-memory
  1585. --restart-condition
  1586. --restart-delay
  1587. --restart-max-attempts
  1588. --restart-window
  1589. --stop-grace-period
  1590. --update-delay
  1591. --update-failure-action
  1592. --update-parallelism
  1593. --user -u
  1594. --workdir -w
  1595. "
  1596. local boolean_options="
  1597. --help
  1598. --with-registry-auth
  1599. "
  1600. __docker_complete_log_driver_options && return
  1601. if [ "$subcommand" = "create" ] ; then
  1602. options_with_args="$options_with_args
  1603. --container-label
  1604. --mode
  1605. "
  1606. case "$prev" in
  1607. --mode)
  1608. COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) )
  1609. return
  1610. ;;
  1611. esac
  1612. fi
  1613. if [ "$subcommand" = "update" ] ; then
  1614. options_with_args="$options_with_args
  1615. --arg
  1616. --container-label-add
  1617. --container-label-rm
  1618. --image
  1619. "
  1620. case "$prev" in
  1621. --image)
  1622. __docker_complete_image_repos_and_tags
  1623. return
  1624. ;;
  1625. esac
  1626. fi
  1627. case "$prev" in
  1628. --endpoint-mode)
  1629. COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) )
  1630. return
  1631. ;;
  1632. --env|-e)
  1633. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  1634. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1635. __docker_nospace
  1636. return
  1637. ;;
  1638. --log-driver)
  1639. __docker_complete_log_drivers
  1640. return
  1641. ;;
  1642. --log-opt)
  1643. __docker_complete_log_options
  1644. return
  1645. ;;
  1646. --network)
  1647. __docker_complete_networks
  1648. return
  1649. ;;
  1650. --restart-condition)
  1651. COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) )
  1652. return
  1653. ;;
  1654. --user|-u)
  1655. __docker_complete_user_group
  1656. return
  1657. ;;
  1658. $(__docker_to_extglob "$options_with_args") )
  1659. return
  1660. ;;
  1661. esac
  1662. case "$cur" in
  1663. -*)
  1664. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1665. ;;
  1666. *)
  1667. if [ "$subcommand" = "update" ] ; then
  1668. __docker_complete_services
  1669. fi
  1670. esac
  1671. }
  1672. _docker_swarm() {
  1673. local subcommands="
  1674. init
  1675. join
  1676. join-token
  1677. leave
  1678. update
  1679. "
  1680. __docker_subcommands "$subcommands" && return
  1681. case "$cur" in
  1682. -*)
  1683. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1684. ;;
  1685. *)
  1686. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1687. ;;
  1688. esac
  1689. }
  1690. _docker_swarm_init() {
  1691. case "$prev" in
  1692. --advertise-addr)
  1693. if [[ $cur == *: ]] ; then
  1694. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1695. else
  1696. __docker_complete_local_interfaces
  1697. __docker_nospace
  1698. fi
  1699. return
  1700. ;;
  1701. --listen-addr)
  1702. if [[ $cur == *: ]] ; then
  1703. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1704. else
  1705. __docker_complete_local_interfaces --add 0.0.0.0
  1706. __docker_nospace
  1707. fi
  1708. return
  1709. ;;
  1710. esac
  1711. case "$cur" in
  1712. -*)
  1713. COMPREPLY=( $( compgen -W "--advertise-addr --force-new-cluster --help --listen-addr" -- "$cur" ) )
  1714. ;;
  1715. esac
  1716. }
  1717. _docker_swarm_join() {
  1718. case "$prev" in
  1719. --advertise-addr)
  1720. if [[ $cur == *: ]] ; then
  1721. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1722. else
  1723. __docker_complete_local_interfaces
  1724. __docker_nospace
  1725. fi
  1726. return
  1727. ;;
  1728. --listen-addr)
  1729. if [[ $cur == *: ]] ; then
  1730. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1731. else
  1732. __docker_complete_local_interfaces --add 0.0.0.0
  1733. __docker_nospace
  1734. fi
  1735. return
  1736. ;;
  1737. --token)
  1738. return
  1739. ;;
  1740. esac
  1741. case "$cur" in
  1742. -*)
  1743. COMPREPLY=( $( compgen -W "--advertise-addr --help --listen-addr --token" -- "$cur" ) )
  1744. ;;
  1745. *:)
  1746. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1747. ;;
  1748. esac
  1749. }
  1750. _docker_swarm_join-token() {
  1751. case "$cur" in
  1752. -*)
  1753. COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) )
  1754. ;;
  1755. *)
  1756. local counter=$( __docker_pos_first_nonflag )
  1757. if [ $cword -eq $counter ]; then
  1758. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  1759. fi
  1760. ;;
  1761. esac
  1762. }
  1763. _docker_swarm_leave() {
  1764. case "$cur" in
  1765. -*)
  1766. COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) )
  1767. ;;
  1768. esac
  1769. }
  1770. _docker_swarm_update() {
  1771. case "$prev" in
  1772. --cert-expiry|--dispatcher-heartbeat|--task-history-limit)
  1773. return
  1774. ;;
  1775. esac
  1776. case "$cur" in
  1777. -*)
  1778. COMPREPLY=( $( compgen -W "--cert-expiry --dispatcher-heartbeat --help --task-history-limit" -- "$cur" ) )
  1779. ;;
  1780. esac
  1781. }
  1782. _docker_node() {
  1783. local subcommands="
  1784. demote
  1785. inspect
  1786. ls list
  1787. promote
  1788. rm remove
  1789. ps
  1790. update
  1791. "
  1792. __docker_subcommands "$subcommands" && return
  1793. case "$cur" in
  1794. -*)
  1795. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1796. ;;
  1797. *)
  1798. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1799. ;;
  1800. esac
  1801. }
  1802. _docker_node_demote() {
  1803. case "$cur" in
  1804. -*)
  1805. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1806. ;;
  1807. *)
  1808. __docker_complete_nodes --filter role=manager
  1809. esac
  1810. }
  1811. _docker_node_inspect() {
  1812. case "$prev" in
  1813. --format|-f)
  1814. return
  1815. ;;
  1816. esac
  1817. case "$cur" in
  1818. -*)
  1819. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  1820. ;;
  1821. *)
  1822. __docker_complete_nodes_plus_self
  1823. esac
  1824. }
  1825. _docker_node_list() {
  1826. _docker_node_ls
  1827. }
  1828. _docker_node_ls() {
  1829. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1830. case "$key" in
  1831. id)
  1832. __docker_complete_nodes --cur "${cur##*=}" --id
  1833. return
  1834. ;;
  1835. name)
  1836. __docker_complete_nodes --cur "${cur##*=}" --name
  1837. return
  1838. ;;
  1839. esac
  1840. case "$prev" in
  1841. --filter|-f)
  1842. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  1843. __docker_nospace
  1844. return
  1845. ;;
  1846. esac
  1847. case "$cur" in
  1848. -*)
  1849. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1850. ;;
  1851. esac
  1852. }
  1853. _docker_node_promote() {
  1854. case "$cur" in
  1855. -*)
  1856. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1857. ;;
  1858. *)
  1859. __docker_complete_nodes --filter role=worker
  1860. esac
  1861. }
  1862. _docker_node_remove() {
  1863. _docker_node_rm
  1864. }
  1865. _docker_node_rm() {
  1866. case "$cur" in
  1867. -*)
  1868. COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) )
  1869. ;;
  1870. *)
  1871. __docker_complete_nodes
  1872. esac
  1873. }
  1874. _docker_node_ps() {
  1875. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1876. case "$key" in
  1877. desired-state)
  1878. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  1879. return
  1880. ;;
  1881. name)
  1882. __docker_complete_services --cur "${cur##*=}" --name
  1883. return
  1884. ;;
  1885. esac
  1886. case "$prev" in
  1887. --filter|-f)
  1888. COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) )
  1889. __docker_nospace
  1890. return
  1891. ;;
  1892. esac
  1893. case "$cur" in
  1894. -*)
  1895. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve" -- "$cur" ) )
  1896. ;;
  1897. *)
  1898. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  1899. if [ $cword -eq $counter ]; then
  1900. __docker_complete_nodes_plus_self
  1901. fi
  1902. ;;
  1903. esac
  1904. }
  1905. _docker_node_update() {
  1906. case "$prev" in
  1907. --availability)
  1908. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  1909. return
  1910. ;;
  1911. --role)
  1912. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  1913. return
  1914. ;;
  1915. --label-add|--label-rm)
  1916. return
  1917. ;;
  1918. esac
  1919. case "$cur" in
  1920. -*)
  1921. COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) )
  1922. ;;
  1923. *)
  1924. __docker_complete_nodes
  1925. esac
  1926. }
  1927. _docker_pause() {
  1928. case "$cur" in
  1929. -*)
  1930. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1931. ;;
  1932. *)
  1933. local counter=$(__docker_pos_first_nonflag)
  1934. if [ $cword -eq $counter ]; then
  1935. __docker_complete_containers_pauseable
  1936. fi
  1937. ;;
  1938. esac
  1939. }
  1940. _docker_port() {
  1941. case "$cur" in
  1942. -*)
  1943. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1944. ;;
  1945. *)
  1946. local counter=$(__docker_pos_first_nonflag)
  1947. if [ $cword -eq $counter ]; then
  1948. __docker_complete_containers_all
  1949. fi
  1950. ;;
  1951. esac
  1952. }
  1953. _docker_ps() {
  1954. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1955. case "$key" in
  1956. ancestor)
  1957. cur="${cur##*=}"
  1958. __docker_complete_images
  1959. return
  1960. ;;
  1961. before)
  1962. cur="${cur##*=}"
  1963. __docker_complete_containers_all
  1964. return
  1965. ;;
  1966. id)
  1967. cur="${cur##*=}"
  1968. __docker_complete_container_ids
  1969. return
  1970. ;;
  1971. name)
  1972. cur="${cur##*=}"
  1973. __docker_complete_container_names
  1974. return
  1975. ;;
  1976. network)
  1977. cur="${cur##*=}"
  1978. __docker_complete_networks
  1979. return
  1980. ;;
  1981. since)
  1982. cur="${cur##*=}"
  1983. __docker_complete_containers_all
  1984. return
  1985. ;;
  1986. status)
  1987. COMPREPLY=( $( compgen -W "created dead exited paused restarting running" -- "${cur##*=}" ) )
  1988. return
  1989. ;;
  1990. volume)
  1991. cur="${cur##*=}"
  1992. __docker_complete_volumes
  1993. return
  1994. ;;
  1995. esac
  1996. case "$prev" in
  1997. --filter|-f)
  1998. COMPREPLY=( $( compgen -S = -W "ancestor before exited id label name network since status volume" -- "$cur" ) )
  1999. __docker_nospace
  2000. return
  2001. ;;
  2002. --format|--last|-n)
  2003. return
  2004. ;;
  2005. esac
  2006. case "$cur" in
  2007. -*)
  2008. COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) )
  2009. ;;
  2010. esac
  2011. }
  2012. _docker_pull() {
  2013. case "$cur" in
  2014. -*)
  2015. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  2016. ;;
  2017. *)
  2018. local counter=$(__docker_pos_first_nonflag)
  2019. if [ $cword -eq $counter ]; then
  2020. for arg in "${COMP_WORDS[@]}"; do
  2021. case "$arg" in
  2022. --all-tags|-a)
  2023. __docker_complete_image_repos
  2024. return
  2025. ;;
  2026. esac
  2027. done
  2028. __docker_complete_image_repos_and_tags
  2029. fi
  2030. ;;
  2031. esac
  2032. }
  2033. _docker_push() {
  2034. case "$cur" in
  2035. -*)
  2036. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  2037. ;;
  2038. *)
  2039. local counter=$(__docker_pos_first_nonflag)
  2040. if [ $cword -eq $counter ]; then
  2041. __docker_complete_image_repos_and_tags
  2042. fi
  2043. ;;
  2044. esac
  2045. }
  2046. _docker_rename() {
  2047. case "$cur" in
  2048. -*)
  2049. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2050. ;;
  2051. *)
  2052. local counter=$(__docker_pos_first_nonflag)
  2053. if [ $cword -eq $counter ]; then
  2054. __docker_complete_containers_all
  2055. fi
  2056. ;;
  2057. esac
  2058. }
  2059. _docker_restart() {
  2060. case "$prev" in
  2061. --time|-t)
  2062. return
  2063. ;;
  2064. esac
  2065. case "$cur" in
  2066. -*)
  2067. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2068. ;;
  2069. *)
  2070. __docker_complete_containers_all
  2071. ;;
  2072. esac
  2073. }
  2074. _docker_rm() {
  2075. case "$cur" in
  2076. -*)
  2077. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  2078. ;;
  2079. *)
  2080. for arg in "${COMP_WORDS[@]}"; do
  2081. case "$arg" in
  2082. --force|-f)
  2083. __docker_complete_containers_all
  2084. return
  2085. ;;
  2086. esac
  2087. done
  2088. __docker_complete_containers_stopped
  2089. ;;
  2090. esac
  2091. }
  2092. _docker_rmi() {
  2093. case "$cur" in
  2094. -*)
  2095. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  2096. ;;
  2097. *)
  2098. __docker_complete_images
  2099. ;;
  2100. esac
  2101. }
  2102. _docker_run() {
  2103. local options_with_args="
  2104. --add-host
  2105. --attach -a
  2106. --blkio-weight
  2107. --blkio-weight-device
  2108. --cap-add
  2109. --cap-drop
  2110. --cgroup-parent
  2111. --cidfile
  2112. --cpu-period
  2113. --cpu-quota
  2114. --cpuset-cpus
  2115. --cpuset-mems
  2116. --cpu-shares -c
  2117. --device
  2118. --device-read-bps
  2119. --device-read-iops
  2120. --device-write-bps
  2121. --device-write-iops
  2122. --dns
  2123. --dns-opt
  2124. --dns-search
  2125. --entrypoint
  2126. --env -e
  2127. --env-file
  2128. --expose
  2129. --group-add
  2130. --hostname -h
  2131. --ip
  2132. --ip6
  2133. --ipc
  2134. --isolation
  2135. --kernel-memory
  2136. --label-file
  2137. --label -l
  2138. --link
  2139. --link-local-ip
  2140. --log-driver
  2141. --log-opt
  2142. --mac-address
  2143. --memory -m
  2144. --memory-swap
  2145. --memory-swappiness
  2146. --memory-reservation
  2147. --name
  2148. --network
  2149. --network-alias
  2150. --oom-score-adj
  2151. --pid
  2152. --pids-limit
  2153. --publish -p
  2154. --restart
  2155. --runtime
  2156. --security-opt
  2157. --shm-size
  2158. --stop-signal
  2159. --storage-opt
  2160. --tmpfs
  2161. --sysctl
  2162. --ulimit
  2163. --user -u
  2164. --userns
  2165. --uts
  2166. --volume-driver
  2167. --volumes-from
  2168. --volume -v
  2169. --workdir -w
  2170. "
  2171. local boolean_options="
  2172. --disable-content-trust=false
  2173. --help
  2174. --interactive -i
  2175. --oom-kill-disable
  2176. --privileged
  2177. --publish-all -P
  2178. --read-only
  2179. --tty -t
  2180. "
  2181. if [ "$command" = "run" ] ; then
  2182. options_with_args="$options_with_args
  2183. --detach-keys
  2184. --health-cmd
  2185. --health-interval
  2186. --health-retries
  2187. --health-timeout
  2188. "
  2189. boolean_options="$boolean_options
  2190. --detach -d
  2191. --no-healthcheck
  2192. --rm
  2193. --sig-proxy=false
  2194. "
  2195. __docker_complete_detach-keys && return
  2196. fi
  2197. local all_options="$options_with_args $boolean_options"
  2198. __docker_complete_log_driver_options && return
  2199. __docker_complete_restart && return
  2200. local key=$(__docker_map_key_of_current_option '--security-opt')
  2201. case "$key" in
  2202. label)
  2203. [[ $cur == *: ]] && return
  2204. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  2205. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  2206. __docker_nospace
  2207. fi
  2208. return
  2209. ;;
  2210. seccomp)
  2211. local cur=${cur##*=}
  2212. _filedir
  2213. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  2214. return
  2215. ;;
  2216. esac
  2217. case "$prev" in
  2218. --add-host)
  2219. case "$cur" in
  2220. *:)
  2221. __docker_complete_resolved_hostname
  2222. return
  2223. ;;
  2224. esac
  2225. ;;
  2226. --attach|-a)
  2227. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  2228. return
  2229. ;;
  2230. --cap-add|--cap-drop)
  2231. __docker_complete_capabilities
  2232. return
  2233. ;;
  2234. --cidfile|--env-file|--label-file)
  2235. _filedir
  2236. return
  2237. ;;
  2238. --device|--tmpfs|--volume|-v)
  2239. case "$cur" in
  2240. *:*)
  2241. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  2242. ;;
  2243. '')
  2244. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  2245. __docker_nospace
  2246. ;;
  2247. /*)
  2248. _filedir
  2249. __docker_nospace
  2250. ;;
  2251. esac
  2252. return
  2253. ;;
  2254. --env|-e)
  2255. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  2256. COMPREPLY=( $( compgen -e -- "$cur" ) )
  2257. __docker_nospace
  2258. return
  2259. ;;
  2260. --ipc)
  2261. case "$cur" in
  2262. *:*)
  2263. cur="${cur#*:}"
  2264. __docker_complete_containers_running
  2265. ;;
  2266. *)
  2267. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  2268. if [ "$COMPREPLY" = "container:" ]; then
  2269. __docker_nospace
  2270. fi
  2271. ;;
  2272. esac
  2273. return
  2274. ;;
  2275. --isolation)
  2276. __docker_complete_isolation
  2277. return
  2278. ;;
  2279. --link)
  2280. case "$cur" in
  2281. *:*)
  2282. ;;
  2283. *)
  2284. __docker_complete_containers_running
  2285. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  2286. __docker_nospace
  2287. ;;
  2288. esac
  2289. return
  2290. ;;
  2291. --log-driver)
  2292. __docker_complete_log_drivers
  2293. return
  2294. ;;
  2295. --log-opt)
  2296. __docker_complete_log_options
  2297. return
  2298. ;;
  2299. --network)
  2300. case "$cur" in
  2301. container:*)
  2302. local cur=${cur#*:}
  2303. __docker_complete_containers_all
  2304. ;;
  2305. *)
  2306. COMPREPLY=( $( compgen -W "$(__docker_plugins Network) $(__docker_networks) container:" -- "$cur") )
  2307. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  2308. __docker_nospace
  2309. fi
  2310. ;;
  2311. esac
  2312. return
  2313. ;;
  2314. --pid)
  2315. case "$cur" in
  2316. *:*)
  2317. cur="${cur#*:}"
  2318. __docker_complete_containers_running
  2319. ;;
  2320. *)
  2321. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  2322. if [ "$COMPREPLY" = "container:" ]; then
  2323. __docker_nospace
  2324. fi
  2325. ;;
  2326. esac
  2327. return
  2328. ;;
  2329. --runtime)
  2330. __docker_complete_runtimes
  2331. return
  2332. ;;
  2333. --security-opt)
  2334. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  2335. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  2336. __docker_nospace
  2337. fi
  2338. return
  2339. ;;
  2340. --storage-opt)
  2341. COMPREPLY=( $( compgen -W "size" -S = -- "$cur") )
  2342. __docker_nospace
  2343. return
  2344. ;;
  2345. --user|-u)
  2346. __docker_complete_user_group
  2347. return
  2348. ;;
  2349. --userns)
  2350. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  2351. return
  2352. ;;
  2353. --volume-driver)
  2354. __docker_complete_plugins Volume
  2355. return
  2356. ;;
  2357. --volumes-from)
  2358. __docker_complete_containers_all
  2359. return
  2360. ;;
  2361. $(__docker_to_extglob "$options_with_args") )
  2362. return
  2363. ;;
  2364. esac
  2365. case "$cur" in
  2366. -*)
  2367. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2368. ;;
  2369. *)
  2370. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2371. if [ $cword -eq $counter ]; then
  2372. __docker_complete_images
  2373. fi
  2374. ;;
  2375. esac
  2376. }
  2377. _docker_save() {
  2378. case "$prev" in
  2379. --output|-o)
  2380. _filedir
  2381. return
  2382. ;;
  2383. esac
  2384. case "$cur" in
  2385. -*)
  2386. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  2387. ;;
  2388. *)
  2389. __docker_complete_images
  2390. ;;
  2391. esac
  2392. }
  2393. _docker_search() {
  2394. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2395. case "$key" in
  2396. is-automated)
  2397. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2398. return
  2399. ;;
  2400. is-official)
  2401. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2402. return
  2403. ;;
  2404. esac
  2405. case "$prev" in
  2406. --filter|-f)
  2407. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  2408. __docker_nospace
  2409. return
  2410. ;;
  2411. --limit)
  2412. return
  2413. ;;
  2414. esac
  2415. case "$cur" in
  2416. -*)
  2417. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  2418. ;;
  2419. esac
  2420. }
  2421. _docker_start() {
  2422. __docker_complete_detach-keys && return
  2423. case "$cur" in
  2424. -*)
  2425. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  2426. ;;
  2427. *)
  2428. __docker_complete_containers_stopped
  2429. ;;
  2430. esac
  2431. }
  2432. _docker_stats() {
  2433. case "$cur" in
  2434. -*)
  2435. COMPREPLY=( $( compgen -W "--all -a --help --no-stream" -- "$cur" ) )
  2436. ;;
  2437. *)
  2438. __docker_complete_containers_running
  2439. ;;
  2440. esac
  2441. }
  2442. _docker_stop() {
  2443. case "$prev" in
  2444. --time|-t)
  2445. return
  2446. ;;
  2447. esac
  2448. case "$cur" in
  2449. -*)
  2450. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2451. ;;
  2452. *)
  2453. __docker_complete_containers_running
  2454. ;;
  2455. esac
  2456. }
  2457. _docker_tag() {
  2458. case "$cur" in
  2459. -*)
  2460. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2461. ;;
  2462. *)
  2463. local counter=$(__docker_pos_first_nonflag)
  2464. if [ $cword -eq $counter ]; then
  2465. __docker_complete_image_repos_and_tags
  2466. return
  2467. fi
  2468. (( counter++ ))
  2469. if [ $cword -eq $counter ]; then
  2470. __docker_complete_image_repos_and_tags
  2471. return
  2472. fi
  2473. ;;
  2474. esac
  2475. }
  2476. _docker_unpause() {
  2477. case "$cur" in
  2478. -*)
  2479. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2480. ;;
  2481. *)
  2482. local counter=$(__docker_pos_first_nonflag)
  2483. if [ $cword -eq $counter ]; then
  2484. __docker_complete_containers_unpauseable
  2485. fi
  2486. ;;
  2487. esac
  2488. }
  2489. _docker_update() {
  2490. local options_with_args="
  2491. --blkio-weight
  2492. --cpu-period
  2493. --cpu-quota
  2494. --cpuset-cpus
  2495. --cpuset-mems
  2496. --cpu-shares -c
  2497. --kernel-memory
  2498. --memory -m
  2499. --memory-reservation
  2500. --memory-swap
  2501. --restart
  2502. "
  2503. local boolean_options="
  2504. --help
  2505. "
  2506. local all_options="$options_with_args $boolean_options"
  2507. __docker_complete_restart && return
  2508. case "$prev" in
  2509. $(__docker_to_extglob "$options_with_args") )
  2510. return
  2511. ;;
  2512. esac
  2513. case "$cur" in
  2514. -*)
  2515. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2516. ;;
  2517. *)
  2518. __docker_complete_containers_all
  2519. ;;
  2520. esac
  2521. }
  2522. _docker_top() {
  2523. case "$cur" in
  2524. -*)
  2525. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2526. ;;
  2527. *)
  2528. local counter=$(__docker_pos_first_nonflag)
  2529. if [ $cword -eq $counter ]; then
  2530. __docker_complete_containers_running
  2531. fi
  2532. ;;
  2533. esac
  2534. }
  2535. _docker_version() {
  2536. case "$cur" in
  2537. -*)
  2538. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2539. ;;
  2540. esac
  2541. }
  2542. _docker_volume_create() {
  2543. case "$prev" in
  2544. --driver|-d)
  2545. __docker_complete_plugins Volume
  2546. return
  2547. ;;
  2548. --label|--name|--opt|-o)
  2549. return
  2550. ;;
  2551. esac
  2552. case "$cur" in
  2553. -*)
  2554. COMPREPLY=( $( compgen -W "--driver -d --help --label --name --opt -o" -- "$cur" ) )
  2555. ;;
  2556. esac
  2557. }
  2558. _docker_volume_inspect() {
  2559. case "$prev" in
  2560. --format|-f)
  2561. return
  2562. ;;
  2563. esac
  2564. case "$cur" in
  2565. -*)
  2566. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2567. ;;
  2568. *)
  2569. __docker_complete_volumes
  2570. ;;
  2571. esac
  2572. }
  2573. _docker_volume_ls() {
  2574. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2575. case "$key" in
  2576. dangling)
  2577. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  2578. return
  2579. ;;
  2580. driver)
  2581. cur=${cur##*=}
  2582. __docker_complete_plugins Volume
  2583. return
  2584. ;;
  2585. name)
  2586. cur=${cur##*=}
  2587. __docker_complete_volumes
  2588. return
  2589. ;;
  2590. esac
  2591. case "$prev" in
  2592. --filter|-f)
  2593. COMPREPLY=( $( compgen -S = -W "dangling driver name" -- "$cur" ) )
  2594. __docker_nospace
  2595. return
  2596. ;;
  2597. esac
  2598. case "$cur" in
  2599. -*)
  2600. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  2601. ;;
  2602. esac
  2603. }
  2604. _docker_volume_rm() {
  2605. case "$cur" in
  2606. -*)
  2607. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2608. ;;
  2609. *)
  2610. __docker_complete_volumes
  2611. ;;
  2612. esac
  2613. }
  2614. _docker_volume() {
  2615. local subcommands="
  2616. create
  2617. inspect
  2618. ls
  2619. rm
  2620. "
  2621. __docker_subcommands "$subcommands" && return
  2622. case "$cur" in
  2623. -*)
  2624. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2625. ;;
  2626. *)
  2627. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2628. ;;
  2629. esac
  2630. }
  2631. _docker_wait() {
  2632. case "$cur" in
  2633. -*)
  2634. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2635. ;;
  2636. *)
  2637. __docker_complete_containers_all
  2638. ;;
  2639. esac
  2640. }
  2641. _docker() {
  2642. local previous_extglob_setting=$(shopt -p extglob)
  2643. shopt -s extglob
  2644. local commands=(
  2645. attach
  2646. build
  2647. commit
  2648. cp
  2649. create
  2650. daemon
  2651. diff
  2652. events
  2653. exec
  2654. export
  2655. history
  2656. images
  2657. import
  2658. info
  2659. inspect
  2660. kill
  2661. load
  2662. login
  2663. logout
  2664. logs
  2665. network
  2666. node
  2667. pause
  2668. port
  2669. ps
  2670. pull
  2671. push
  2672. rename
  2673. restart
  2674. rm
  2675. rmi
  2676. run
  2677. save
  2678. search
  2679. service
  2680. start
  2681. stats
  2682. stop
  2683. swarm
  2684. tag
  2685. top
  2686. unpause
  2687. update
  2688. version
  2689. volume
  2690. wait
  2691. )
  2692. # These options are valid as global options for all client commands
  2693. # and valid as command options for `docker daemon`
  2694. local global_boolean_options="
  2695. --debug -D
  2696. --tls
  2697. --tlsverify
  2698. "
  2699. local global_options_with_args="
  2700. --config
  2701. --host -H
  2702. --log-level -l
  2703. --tlscacert
  2704. --tlscert
  2705. --tlskey
  2706. "
  2707. local host config
  2708. COMPREPLY=()
  2709. local cur prev words cword
  2710. _get_comp_words_by_ref -n : cur prev words cword
  2711. local command='docker' command_pos=0 subcommand_pos
  2712. local counter=1
  2713. while [ $counter -lt $cword ]; do
  2714. case "${words[$counter]}" in
  2715. # save host so that completion can use custom daemon
  2716. --host|-H)
  2717. (( counter++ ))
  2718. host="${words[$counter]}"
  2719. ;;
  2720. # save config so that completion can use custom configuration directories
  2721. --config)
  2722. (( counter++ ))
  2723. config="${words[$counter]}"
  2724. ;;
  2725. $(__docker_to_extglob "$global_options_with_args") )
  2726. (( counter++ ))
  2727. ;;
  2728. -*)
  2729. ;;
  2730. =)
  2731. (( counter++ ))
  2732. ;;
  2733. *)
  2734. command="${words[$counter]}"
  2735. command_pos=$counter
  2736. break
  2737. ;;
  2738. esac
  2739. (( counter++ ))
  2740. done
  2741. local binary="${words[0]}"
  2742. if [[ $binary == ?(*/)dockerd ]] ; then
  2743. # for the dockerd binary, we reuse completion of `docker daemon`.
  2744. # dockerd does not have subcommands and global options.
  2745. command=daemon
  2746. command_pos=0
  2747. fi
  2748. local completions_func=_docker_${command}
  2749. declare -F $completions_func >/dev/null && $completions_func
  2750. eval "$previous_extglob_setting"
  2751. return 0
  2752. }
  2753. eval "$__docker_previous_extglob_setting"
  2754. unset __docker_previous_extglob_setting
  2755. complete -F _docker docker dockerd