docker 59 KB

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