docker 68 KB

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