docker 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479
  1. #!/usr/bin/env 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_PLUGIN_IDS
  27. # DOCKER_COMPLETION_SHOW_SECRET_IDS
  28. # DOCKER_COMPLETION_SHOW_SERVICE_IDS
  29. # "no" - Show names only (default)
  30. # "yes" - Show names and ids
  31. #
  32. # You can tailor completion for the "events", "history", "inspect", "run",
  33. # "rmi" and "save" commands by settings the following environment
  34. # variables:
  35. #
  36. # DOCKER_COMPLETION_SHOW_IMAGE_IDS
  37. # "none" - Show names only (default)
  38. # "non-intermediate" - Show names and ids, but omit intermediate image IDs
  39. # "all" - Show names and ids, including intermediate image IDs
  40. #
  41. # DOCKER_COMPLETION_SHOW_TAGS
  42. # "yes" - include tags in completion options (default)
  43. # "no" - don't include tags in completion options
  44. #
  45. # Note:
  46. # Currently, the completions will not work if the docker daemon is not
  47. # bound to the default communication port/socket
  48. # If the docker daemon is using a unix socket for communication your user
  49. # must have access to the socket for the completions to function correctly
  50. #
  51. # Note for developers:
  52. # Please arrange options sorted alphabetically by long name with the short
  53. # options immediately following their corresponding long form.
  54. # This order should be applied to lists, alternatives and code blocks.
  55. __docker_previous_extglob_setting=$(shopt -p extglob)
  56. shopt -s extglob
  57. __docker_q() {
  58. docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@"
  59. }
  60. # __docker_containers returns a list of containers. Additional options to
  61. # `docker ps` may be specified in order to filter the list, e.g.
  62. # `__docker_containers --filter status=running`
  63. # By default, only names are returned.
  64. # Set DOCKER_COMPLETION_SHOW_CONTAINER_IDS=yes to also complete IDs.
  65. # An optional first option `--id|--name` may be used to limit the
  66. # output to the IDs or names of matching items. This setting takes
  67. # precedence over the environment setting.
  68. __docker_containers() {
  69. local format
  70. if [ "$1" = "--id" ] ; then
  71. format='{{.ID}}'
  72. shift
  73. elif [ "$1" = "--name" ] ; then
  74. format='{{.Names}}'
  75. shift
  76. elif [ "${DOCKER_COMPLETION_SHOW_CONTAINER_IDS}" = yes ] ; then
  77. format='{{.ID}} {{.Names}}'
  78. else
  79. format='{{.Names}}'
  80. fi
  81. __docker_q ps --format "$format" "$@"
  82. }
  83. # __docker_complete_containers applies completion of containers based on the current
  84. # value of `$cur` or the value of the optional first option `--cur`, if given.
  85. # Additional filters may be appended, see `__docker_containers`.
  86. __docker_complete_containers() {
  87. local current="$cur"
  88. if [ "$1" = "--cur" ] ; then
  89. current="$2"
  90. shift 2
  91. fi
  92. COMPREPLY=( $(compgen -W "$(__docker_containers "$@")" -- "$current") )
  93. }
  94. __docker_complete_containers_all() {
  95. __docker_complete_containers "$@" --all
  96. }
  97. __docker_complete_containers_running() {
  98. __docker_complete_containers "$@" --filter status=running
  99. }
  100. __docker_complete_containers_stopped() {
  101. __docker_complete_containers "$@" --filter status=exited
  102. }
  103. __docker_complete_containers_unpauseable() {
  104. __docker_complete_containers "$@" --filter status=paused
  105. }
  106. __docker_complete_container_names() {
  107. local containers=( $(__docker_q ps -aq --no-trunc) )
  108. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  109. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  110. COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") )
  111. }
  112. __docker_complete_container_ids() {
  113. local containers=( $(__docker_q ps -aq) )
  114. COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") )
  115. }
  116. __docker_images() {
  117. local images_args=""
  118. case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
  119. all)
  120. images_args="--no-trunc -a"
  121. ;;
  122. non-intermediate)
  123. images_args="--no-trunc"
  124. ;;
  125. esac
  126. local repo_print_command
  127. if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then
  128. repo_print_command='print $1; print $1":"$2'
  129. else
  130. repo_print_command='print $1'
  131. fi
  132. local awk_script
  133. case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
  134. all|non-intermediate)
  135. awk_script='NR>1 { print $3; if ($1 != "<none>") { '"$repo_print_command"' } }'
  136. ;;
  137. none|*)
  138. awk_script='NR>1 && $1 != "<none>" { '"$repo_print_command"' }'
  139. ;;
  140. esac
  141. __docker_q images $images_args | awk "$awk_script" | grep -v '<none>$'
  142. }
  143. __docker_complete_images() {
  144. COMPREPLY=( $(compgen -W "$(__docker_images)" -- "$cur") )
  145. __ltrim_colon_completions "$cur"
  146. }
  147. __docker_complete_image_repos() {
  148. local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')"
  149. COMPREPLY=( $(compgen -W "$repos" -- "$cur") )
  150. }
  151. __docker_complete_image_repos_and_tags() {
  152. local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')"
  153. COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") )
  154. __ltrim_colon_completions "$cur"
  155. }
  156. # __docker_networks returns a list of all networks. Additional options to
  157. # `docker network ls` may be specified in order to filter the list, e.g.
  158. # `__docker_networks --filter type=custom`
  159. # By default, only names are returned.
  160. # Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete IDs.
  161. # An optional first option `--id|--name` may be used to limit the
  162. # output to the IDs or names of matching items. This setting takes
  163. # precedence over the environment setting.
  164. __docker_networks() {
  165. local format
  166. if [ "$1" = "--id" ] ; then
  167. format='{{.ID}}'
  168. shift
  169. elif [ "$1" = "--name" ] ; then
  170. format='{{.Name}}'
  171. shift
  172. elif [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] ; then
  173. format='{{.ID}} {{.Name}}'
  174. else
  175. format='{{.Name}}'
  176. fi
  177. __docker_q network ls --format "$format" "$@"
  178. }
  179. # __docker_complete_networks applies completion of networks based on the current
  180. # value of `$cur` or the value of the optional first option `--cur`, if given.
  181. # Additional filters may be appended, see `__docker_networks`.
  182. __docker_complete_networks() {
  183. local current="$cur"
  184. if [ "$1" = "--cur" ] ; then
  185. current="$2"
  186. shift 2
  187. fi
  188. COMPREPLY=( $(compgen -W "$(__docker_networks "$@")" -- "$current") )
  189. }
  190. __docker_complete_containers_in_network() {
  191. local containers=$(__docker_q network inspect -f '{{range $i, $c := .Containers}}{{$i}} {{$c.Name}} {{end}}' "$1")
  192. COMPREPLY=( $(compgen -W "$containers" -- "$cur") )
  193. }
  194. # __docker_volumes returns a list of all volumes. Additional options to
  195. # `docker volume ls` may be specified in order to filter the list, e.g.
  196. # `__docker_volumes --filter dangling=true`
  197. # Because volumes do not have IDs, this function does not distinguish between
  198. # IDs and names.
  199. __docker_volumes() {
  200. __docker_q volume ls -q "$@"
  201. }
  202. # __docker_complete_volumes applies completion of volumes based on the current
  203. # value of `$cur` or the value of the optional first option `--cur`, if given.
  204. # Additional filters may be appended, see `__docker_volumes`.
  205. __docker_complete_volumes() {
  206. local current="$cur"
  207. if [ "$1" = "--cur" ] ; then
  208. current="$2"
  209. shift 2
  210. fi
  211. COMPREPLY=( $(compgen -W "$(__docker_volumes "$@")" -- "$current") )
  212. }
  213. # __docker_plugins_bundled returns a list of all plugins of a given type.
  214. # The type has to be specified with the mandatory option `--type`.
  215. # Valid types are: Network, Volume, Authorization.
  216. # Completions may be added or removed with `--add` and `--remove`
  217. # This function only deals with plugins that come bundled with Docker.
  218. # For plugins managed by `docker plugin`, see `__docker_plugins_installed`.
  219. __docker_plugins_bundled() {
  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 --format "{{range \$i, \$p := .Plugins.$type}}{{.}} {{end}}"))
  241. for del in "${remove[@]}" ; do
  242. plugins=(${plugins[@]/$del/})
  243. done
  244. echo "${plugins[@]} ${add[@]}"
  245. }
  246. # __docker_complete_plugins_bundled 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. # This function only deals with plugins that come bundled with Docker.
  250. # For completion of plugins managed by `docker plugin`, see
  251. # `__docker_complete_plugins_installed`.
  252. __docker_complete_plugins_bundled() {
  253. local current="$cur"
  254. if [ "$1" = "--cur" ] ; then
  255. current="$2"
  256. shift 2
  257. fi
  258. COMPREPLY=( $(compgen -W "$(__docker_plugins_bundled "$@")" -- "$current") )
  259. }
  260. # __docker_plugins_installed returns a list of all plugins that were installed with
  261. # the Docker plugin API.
  262. # By default, only names are returned.
  263. # Set DOCKER_COMPLETION_SHOW_PLUGIN_IDS=yes to also complete IDs.
  264. # Additional options to `docker plugin ls` may be specified in order to filter the list,
  265. # e.g. `__docker_plugins_installed --filter enabled=true`
  266. # For built-in pugins, see `__docker_plugins_bundled`.
  267. __docker_plugins_installed() {
  268. local format
  269. if [ "$DOCKER_COMPLETION_SHOW_PLUGIN_IDS" = yes ] ; then
  270. format='{{.ID}} {{.Name}}'
  271. else
  272. format='{{.Name}}'
  273. fi
  274. __docker_q plugin ls --format "$format" "$@"
  275. }
  276. # __docker_complete_plugins_installed applies completion of plugins that were installed
  277. # with the Docker plugin API, based on the current value of `$cur` or the value of
  278. # the optional first option `--cur`, if given.
  279. # Additional filters may be appended, see `__docker_plugins_installed`.
  280. # For completion of built-in pugins, see `__docker_complete_plugins_bundled`.
  281. __docker_complete_plugins_installed() {
  282. local current="$cur"
  283. if [ "$1" = "--cur" ] ; then
  284. current="$2"
  285. shift 2
  286. fi
  287. COMPREPLY=( $(compgen -W "$(__docker_plugins_installed "$@")" -- "$current") )
  288. }
  289. __docker_runtimes() {
  290. __docker_q info | sed -n 's/^Runtimes: \(.*\)/\1/p'
  291. }
  292. __docker_complete_runtimes() {
  293. COMPREPLY=( $(compgen -W "$(__docker_runtimes)" -- "$cur") )
  294. }
  295. # __docker_secrets returns a list of all secrets.
  296. # By default, only names of secrets are returned.
  297. # Set DOCKER_COMPLETION_SHOW_SECRET_IDS=yes to also complete IDs of secrets.
  298. __docker_secrets() {
  299. local fields='$2' # default: name only
  300. [ "${DOCKER_COMPLETION_SHOW_SECRET_IDS}" = yes ] && fields='$1,$2' # ID and name
  301. __docker_q secret ls | awk "NR>1 {print $fields}"
  302. }
  303. # __docker_complete_secrets applies completion of secrets based on the current value
  304. # of `$cur`.
  305. __docker_complete_secrets() {
  306. COMPREPLY=( $(compgen -W "$(__docker_secrets)" -- "$cur") )
  307. }
  308. # __docker_stacks returns a list of all stacks.
  309. __docker_stacks() {
  310. __docker_q stack ls | awk 'NR>1 {print $1}'
  311. }
  312. # __docker_complete_stacks applies completion of stacks based on the current value
  313. # of `$cur` or the value of the optional first option `--cur`, if given.
  314. __docker_complete_stacks() {
  315. local current="$cur"
  316. if [ "$1" = "--cur" ] ; then
  317. current="$2"
  318. shift 2
  319. fi
  320. COMPREPLY=( $(compgen -W "$(__docker_stacks "$@")" -- "$current") )
  321. }
  322. # __docker_nodes returns a list of all nodes. Additional options to
  323. # `docker node ls` may be specified in order to filter the list, e.g.
  324. # `__docker_nodes --filter role=manager`
  325. # By default, only node names are returned.
  326. # Set DOCKER_COMPLETION_SHOW_NODE_IDS=yes to also complete node IDs.
  327. # An optional first option `--id|--name` may be used to limit the
  328. # output to the IDs or names of matching items. This setting takes
  329. # precedence over the environment setting.
  330. # Completions may be added with `--add`, e.g. `--add self`.
  331. __docker_nodes() {
  332. local add=()
  333. local fields='$2' # default: node name only
  334. [ "${DOCKER_COMPLETION_SHOW_NODE_IDS}" = yes ] && fields='$1,$2' # ID and name
  335. while true ; do
  336. case "$1" in
  337. --id)
  338. fields='$1' # IDs only
  339. shift
  340. ;;
  341. --name)
  342. fields='$2' # names only
  343. shift
  344. ;;
  345. --add)
  346. add+=("$2")
  347. shift 2
  348. ;;
  349. *)
  350. break
  351. ;;
  352. esac
  353. done
  354. echo $(__docker_q node ls "$@" | tr -d '*' | awk "NR>1 {print $fields}") "${add[@]}"
  355. }
  356. # __docker_complete_nodes applies completion of nodes based on the current
  357. # value of `$cur` or the value of the optional first option `--cur`, if given.
  358. # Additional filters may be appended, see `__docker_nodes`.
  359. __docker_complete_nodes() {
  360. local current="$cur"
  361. if [ "$1" = "--cur" ] ; then
  362. current="$2"
  363. shift 2
  364. fi
  365. COMPREPLY=( $(compgen -W "$(__docker_nodes "$@")" -- "$current") )
  366. }
  367. # __docker_services returns a list of all services. Additional options to
  368. # `docker service ls` may be specified in order to filter the list, e.g.
  369. # `__docker_services --filter name=xxx`
  370. # By default, only node names are returned.
  371. # Set DOCKER_COMPLETION_SHOW_SERVICE_IDS=yes to also complete IDs.
  372. # An optional first option `--id|--name` may be used to limit the
  373. # output to the IDs or names of matching items. This setting takes
  374. # precedence over the environment setting.
  375. __docker_services() {
  376. local fields='$2' # default: service name only
  377. [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name
  378. if [ "$1" = "--id" ] ; then
  379. fields='$1' # IDs only
  380. shift
  381. elif [ "$1" = "--name" ] ; then
  382. fields='$2' # names only
  383. shift
  384. fi
  385. __docker_q service ls "$@" | awk "NR>1 {print $fields}"
  386. }
  387. # __docker_complete_services applies completion of services based on the current
  388. # value of `$cur` or the value of the optional first option `--cur`, if given.
  389. # Additional filters may be appended, see `__docker_services`.
  390. __docker_complete_services() {
  391. local current="$cur"
  392. if [ "$1" = "--cur" ] ; then
  393. current="$2"
  394. shift 2
  395. fi
  396. COMPREPLY=( $(compgen -W "$(__docker_services "$@")" -- "$current") )
  397. }
  398. # __docker_append_to_completions appends the word passed as an argument to every
  399. # word in `$COMPREPLY`.
  400. # Normally you do this with `compgen -S` while generating the completions.
  401. # This function allows you to append a suffix later. It allows you to use
  402. # the __docker_complete_XXX functions in cases where you need a suffix.
  403. __docker_append_to_completions() {
  404. COMPREPLY=( ${COMPREPLY[@]/%/"$1"} )
  405. }
  406. # __docker_daemon_is_experimental tests whether the currently configured Docker
  407. # daemon runs in experimental mode. If so, the function exits with 0 (true).
  408. # Otherwise, or if the result cannot be determined, the exit value is 1 (false).
  409. __docker_daemon_is_experimental() {
  410. [ "$(__docker_q version -f '{{.Server.Experimental}}')" = "true" ]
  411. }
  412. # __docker_daemon_os_is tests whether the currently configured Docker daemon runs
  413. # on the operating system passed in as the first argument.
  414. # It does so by querying the daemon for its OS. The result is cached for the duration
  415. # of one invocation of bash completion so that this function can be used to test for
  416. # several different operating systems without additional costs.
  417. # Known operating systems: linux, windows.
  418. __docker_daemon_os_is() {
  419. local expected_os="$1"
  420. local actual_os=${daemon_os=$(__docker_q version -f '{{.Server.Os}}')}
  421. [ "$actual_os" = "$expected_os" ]
  422. }
  423. # __docker_pos_first_nonflag finds the position of the first word that is neither
  424. # option nor an option's argument. If there are options that require arguments,
  425. # you should pass a glob describing those options, e.g. "--option1|-o|--option2"
  426. # Use this function to restrict completions to exact positions after the argument list.
  427. __docker_pos_first_nonflag() {
  428. local argument_flags=$1
  429. local counter=$((${subcommand_pos:-${command_pos}} + 1))
  430. while [ $counter -le $cword ]; do
  431. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  432. (( counter++ ))
  433. # eat "=" in case of --option=arg syntax
  434. [ "${words[$counter]}" = "=" ] && (( counter++ ))
  435. else
  436. case "${words[$counter]}" in
  437. -*)
  438. ;;
  439. *)
  440. break
  441. ;;
  442. esac
  443. fi
  444. # Bash splits words at "=", retaining "=" as a word, examples:
  445. # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
  446. while [ "${words[$counter + 1]}" = "=" ] ; do
  447. counter=$(( counter + 2))
  448. done
  449. (( counter++ ))
  450. done
  451. echo $counter
  452. }
  453. # __docker_map_key_of_current_option returns `key` if we are currently completing the
  454. # value of a map option (`key=value`) which matches the extglob given as an argument.
  455. # This function is needed for key-specific completions.
  456. __docker_map_key_of_current_option() {
  457. local glob="$1"
  458. local key glob_pos
  459. if [ "$cur" = "=" ] ; then # key= case
  460. key="$prev"
  461. glob_pos=$((cword - 2))
  462. elif [[ $cur == *=* ]] ; then # key=value case (OSX)
  463. key=${cur%=*}
  464. glob_pos=$((cword - 1))
  465. elif [ "$prev" = "=" ] ; then
  466. key=${words[$cword - 2]} # key=value case
  467. glob_pos=$((cword - 3))
  468. else
  469. return
  470. fi
  471. [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax
  472. [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key"
  473. }
  474. # __docker_value_of_option returns the value of the first option matching `option_glob`.
  475. # Valid values for `option_glob` are option names like `--log-level` and globs like
  476. # `--log-level|-l`
  477. # Only positions between the command and the current word are considered.
  478. __docker_value_of_option() {
  479. local option_extglob=$(__docker_to_extglob "$1")
  480. local counter=$((command_pos + 1))
  481. while [ $counter -lt $cword ]; do
  482. case ${words[$counter]} in
  483. $option_extglob )
  484. echo ${words[$counter + 1]}
  485. break
  486. ;;
  487. esac
  488. (( counter++ ))
  489. done
  490. }
  491. # __docker_to_alternatives transforms a multiline list of strings into a single line
  492. # string with the words separated by `|`.
  493. # This is used to prepare arguments to __docker_pos_first_nonflag().
  494. __docker_to_alternatives() {
  495. local parts=( $1 )
  496. local IFS='|'
  497. echo "${parts[*]}"
  498. }
  499. # __docker_to_extglob transforms a multiline list of options into an extglob pattern
  500. # suitable for use in case statements.
  501. __docker_to_extglob() {
  502. local extglob=$( __docker_to_alternatives "$1" )
  503. echo "@($extglob)"
  504. }
  505. # __docker_subcommands processes subcommands
  506. # Locates the first occurrence of any of the subcommands contained in the
  507. # first argument. In case of a match, calls the corresponding completion
  508. # function and returns 0.
  509. # If no match is found, 1 is returned. The calling function can then
  510. # continue processing its completion.
  511. #
  512. # TODO if the preceding command has options that accept arguments and an
  513. # argument is equal ot one of the subcommands, this is falsely detected as
  514. # a match.
  515. __docker_subcommands() {
  516. local subcommands="$1"
  517. local counter=$(($command_pos + 1))
  518. while [ $counter -lt $cword ]; do
  519. case "${words[$counter]}" in
  520. $(__docker_to_extglob "$subcommands") )
  521. subcommand_pos=$counter
  522. local subcommand=${words[$counter]}
  523. local completions_func=_docker_${command}_${subcommand//-/_}
  524. declare -F $completions_func >/dev/null && $completions_func
  525. return 0
  526. ;;
  527. esac
  528. (( counter++ ))
  529. done
  530. return 1
  531. }
  532. # __docker_nospace suppresses trailing whitespace
  533. __docker_nospace() {
  534. # compopt is not available in ancient bash versions
  535. type compopt &>/dev/null && compopt -o nospace
  536. }
  537. __docker_complete_resolved_hostname() {
  538. command -v host >/dev/null 2>&1 || return
  539. COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
  540. }
  541. __docker_local_interfaces() {
  542. command -v ip >/dev/null 2>&1 || return
  543. ip addr show scope global 2>/dev/null | sed -n 's| \+inet \([0-9.]\+\).* \([^ ]\+\)|\1 \2|p'
  544. }
  545. __docker_complete_local_interfaces() {
  546. local additional_interface
  547. if [ "$1" = "--add" ] ; then
  548. additional_interface="$2"
  549. fi
  550. COMPREPLY=( $( compgen -W "$(__docker_local_interfaces) $additional_interface" -- "$cur" ) )
  551. }
  552. # __docker_complete_capabilities_addable completes Linux capabilities which are
  553. # not granted by default and may be added.
  554. # see https://docs.docker.com/engine/reference/run/#/runtime-privilege-and-linux-capabilities
  555. __docker_complete_capabilities_addable() {
  556. COMPREPLY=( $( compgen -W "
  557. ALL
  558. AUDIT_CONTROL
  559. BLOCK_SUSPEND
  560. DAC_READ_SEARCH
  561. IPC_LOCK
  562. IPC_OWNER
  563. LEASE
  564. LINUX_IMMUTABLE
  565. MAC_ADMIN
  566. MAC_OVERRIDE
  567. NET_ADMIN
  568. NET_BROADCAST
  569. SYS_ADMIN
  570. SYS_BOOT
  571. SYSLOG
  572. SYS_MODULE
  573. SYS_NICE
  574. SYS_PACCT
  575. SYS_PTRACE
  576. SYS_RAWIO
  577. SYS_RESOURCE
  578. SYS_TIME
  579. SYS_TTY_CONFIG
  580. WAKE_ALARM
  581. " -- "$cur" ) )
  582. }
  583. # __docker_complete_capabilities_droppable completes Linux capability options which are
  584. # allowed by default and can be dropped.
  585. # see https://docs.docker.com/engine/reference/run/#/runtime-privilege-and-linux-capabilities
  586. __docker_complete_capabilities_droppable() {
  587. COMPREPLY=( $( compgen -W "
  588. ALL
  589. AUDIT_WRITE
  590. CHOWN
  591. DAC_OVERRIDE
  592. FOWNER
  593. FSETID
  594. KILL
  595. MKNOD
  596. NET_BIND_SERVICE
  597. NET_RAW
  598. SETFCAP
  599. SETGID
  600. SETPCAP
  601. SETUID
  602. SYS_CHROOT
  603. " -- "$cur" ) )
  604. }
  605. __docker_complete_detach_keys() {
  606. case "$prev" in
  607. --detach-keys)
  608. case "$cur" in
  609. *,)
  610. COMPREPLY=( $( compgen -W "${cur}ctrl-" -- "$cur" ) )
  611. ;;
  612. *)
  613. COMPREPLY=( $( compgen -W "ctrl-" -- "$cur" ) )
  614. ;;
  615. esac
  616. __docker_nospace
  617. return
  618. ;;
  619. esac
  620. return 1
  621. }
  622. __docker_complete_isolation() {
  623. COMPREPLY=( $( compgen -W "default hyperv process" -- "$cur" ) )
  624. }
  625. __docker_complete_log_drivers() {
  626. COMPREPLY=( $( compgen -W "
  627. awslogs
  628. etwlogs
  629. fluentd
  630. gcplogs
  631. gelf
  632. journald
  633. json-file
  634. logentries
  635. none
  636. splunk
  637. syslog
  638. " -- "$cur" ) )
  639. }
  640. __docker_complete_log_options() {
  641. # see repository docker/docker.github.io/engine/admin/logging/
  642. local common_options="max-buffer-size mode"
  643. local awslogs_options="$common_options awslogs-region awslogs-group awslogs-stream awslogs-create-group"
  644. local fluentd_options="$common_options env fluentd-address fluentd-async-connect fluentd-buffer-limit fluentd-retry-wait fluentd-max-retries labels tag"
  645. local gcplogs_options="$common_options env gcp-log-cmd gcp-project labels"
  646. local gelf_options="$common_options env gelf-address gelf-compression-level gelf-compression-type labels tag"
  647. local journald_options="$common_options env labels tag"
  648. local json_file_options="$common_options env labels max-file max-size"
  649. local logentries_options="$common_options logentries-token"
  650. local syslog_options="$common_options env labels syslog-address syslog-facility syslog-format syslog-tls-ca-cert syslog-tls-cert syslog-tls-key syslog-tls-skip-verify tag"
  651. local splunk_options="$common_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"
  652. local all_options="$fluentd_options $gcplogs_options $gelf_options $journald_options $logentries_options $json_file_options $syslog_options $splunk_options"
  653. case $(__docker_value_of_option --log-driver) in
  654. '')
  655. COMPREPLY=( $( compgen -W "$all_options" -S = -- "$cur" ) )
  656. ;;
  657. awslogs)
  658. COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) )
  659. ;;
  660. fluentd)
  661. COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) )
  662. ;;
  663. gcplogs)
  664. COMPREPLY=( $( compgen -W "$gcplogs_options" -S = -- "$cur" ) )
  665. ;;
  666. gelf)
  667. COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) )
  668. ;;
  669. journald)
  670. COMPREPLY=( $( compgen -W "$journald_options" -S = -- "$cur" ) )
  671. ;;
  672. json-file)
  673. COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) )
  674. ;;
  675. logentries)
  676. COMPREPLY=( $( compgen -W "$logentries_options" -S = -- "$cur" ) )
  677. ;;
  678. syslog)
  679. COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) )
  680. ;;
  681. splunk)
  682. COMPREPLY=( $( compgen -W "$splunk_options" -S = -- "$cur" ) )
  683. ;;
  684. *)
  685. return
  686. ;;
  687. esac
  688. __docker_nospace
  689. }
  690. __docker_complete_log_driver_options() {
  691. local key=$(__docker_map_key_of_current_option '--log-opt')
  692. case "$key" in
  693. fluentd-async-connect)
  694. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  695. return
  696. ;;
  697. gelf-address)
  698. COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur##*=}" ) )
  699. __docker_nospace
  700. return
  701. ;;
  702. gelf-compression-level)
  703. COMPREPLY=( $( compgen -W "1 2 3 4 5 6 7 8 9" -- "${cur##*=}" ) )
  704. return
  705. ;;
  706. gelf-compression-type)
  707. COMPREPLY=( $( compgen -W "gzip none zlib" -- "${cur##*=}" ) )
  708. return
  709. ;;
  710. mode)
  711. COMPREPLY=( $( compgen -W "blocking non-blocking" -- "${cur##*=}" ) )
  712. return
  713. ;;
  714. syslog-address)
  715. COMPREPLY=( $( compgen -W "tcp:// tcp+tls:// udp:// unix://" -- "${cur##*=}" ) )
  716. __docker_nospace
  717. __ltrim_colon_completions "${cur}"
  718. return
  719. ;;
  720. syslog-facility)
  721. COMPREPLY=( $( compgen -W "
  722. auth
  723. authpriv
  724. cron
  725. daemon
  726. ftp
  727. kern
  728. local0
  729. local1
  730. local2
  731. local3
  732. local4
  733. local5
  734. local6
  735. local7
  736. lpr
  737. mail
  738. news
  739. syslog
  740. user
  741. uucp
  742. " -- "${cur##*=}" ) )
  743. return
  744. ;;
  745. syslog-format)
  746. COMPREPLY=( $( compgen -W "rfc3164 rfc5424 rfc5424micro" -- "${cur##*=}" ) )
  747. return
  748. ;;
  749. syslog-tls-ca-cert|syslog-tls-cert|syslog-tls-key)
  750. _filedir
  751. return
  752. ;;
  753. syslog-tls-skip-verify)
  754. COMPREPLY=( $( compgen -W "true" -- "${cur##*=}" ) )
  755. return
  756. ;;
  757. splunk-url)
  758. COMPREPLY=( $( compgen -W "http:// https://" -- "${cur##*=}" ) )
  759. __docker_nospace
  760. __ltrim_colon_completions "${cur}"
  761. return
  762. ;;
  763. splunk-gzip|splunk-insecureskipverify|splunk-verify-connection)
  764. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  765. return
  766. ;;
  767. splunk-format)
  768. COMPREPLY=( $( compgen -W "inline json raw" -- "${cur##*=}" ) )
  769. return
  770. ;;
  771. esac
  772. return 1
  773. }
  774. __docker_complete_log_levels() {
  775. COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) )
  776. }
  777. __docker_complete_restart() {
  778. case "$prev" in
  779. --restart)
  780. case "$cur" in
  781. on-failure:*)
  782. ;;
  783. *)
  784. COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") )
  785. ;;
  786. esac
  787. return
  788. ;;
  789. esac
  790. return 1
  791. }
  792. # __docker_complete_signals returns a subset of the available signals that is most likely
  793. # relevant in the context of docker containers
  794. __docker_complete_signals() {
  795. local signals=(
  796. SIGCONT
  797. SIGHUP
  798. SIGINT
  799. SIGKILL
  800. SIGQUIT
  801. SIGSTOP
  802. SIGTERM
  803. SIGUSR1
  804. SIGUSR2
  805. )
  806. COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) )
  807. }
  808. __docker_complete_user_group() {
  809. if [[ $cur == *:* ]] ; then
  810. COMPREPLY=( $(compgen -g -- "${cur#*:}") )
  811. else
  812. COMPREPLY=( $(compgen -u -S : -- "$cur") )
  813. __docker_nospace
  814. fi
  815. }
  816. _docker_docker() {
  817. # global options that may appear after the docker command
  818. local boolean_options="
  819. $global_boolean_options
  820. --help
  821. --version -v
  822. "
  823. case "$prev" in
  824. --config)
  825. _filedir -d
  826. return
  827. ;;
  828. --log-level|-l)
  829. __docker_complete_log_levels
  830. return
  831. ;;
  832. $(__docker_to_extglob "$global_options_with_args") )
  833. return
  834. ;;
  835. esac
  836. case "$cur" in
  837. -*)
  838. COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) )
  839. ;;
  840. *)
  841. local counter=$( __docker_pos_first_nonflag "$(__docker_to_extglob "$global_options_with_args")" )
  842. if [ $cword -eq $counter ]; then
  843. __docker_daemon_is_experimental && commands+=(${experimental_commands[*]})
  844. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  845. fi
  846. ;;
  847. esac
  848. }
  849. _docker_attach() {
  850. _docker_container_attach
  851. }
  852. _docker_build() {
  853. _docker_image_build
  854. }
  855. _docker_checkpoint() {
  856. local subcommands="
  857. create
  858. ls
  859. rm
  860. "
  861. local aliases="
  862. list
  863. remove
  864. "
  865. __docker_subcommands "$subcommands $aliases" && return
  866. case "$cur" in
  867. -*)
  868. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  869. ;;
  870. *)
  871. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  872. ;;
  873. esac
  874. }
  875. _docker_checkpoint_create() {
  876. case "$prev" in
  877. --checkpoint-dir)
  878. _filedir -d
  879. return
  880. ;;
  881. esac
  882. case "$cur" in
  883. -*)
  884. COMPREPLY=( $( compgen -W "--checkpoint-dir --help --leave-running" -- "$cur" ) )
  885. ;;
  886. *)
  887. local counter=$(__docker_pos_first_nonflag '--checkpoint-dir')
  888. if [ $cword -eq $counter ]; then
  889. __docker_complete_containers_running
  890. fi
  891. ;;
  892. esac
  893. }
  894. _docker_checkpoint_ls() {
  895. case "$prev" in
  896. --checkpoint-dir)
  897. _filedir -d
  898. return
  899. ;;
  900. esac
  901. case "$cur" in
  902. -*)
  903. COMPREPLY=( $( compgen -W "--checkpoint-dir --help" -- "$cur" ) )
  904. ;;
  905. *)
  906. local counter=$(__docker_pos_first_nonflag '--checkpoint-dir')
  907. if [ $cword -eq $counter ]; then
  908. __docker_complete_containers_all
  909. fi
  910. ;;
  911. esac
  912. }
  913. _docker_checkpoint_rm() {
  914. case "$prev" in
  915. --checkpoint-dir)
  916. _filedir -d
  917. return
  918. ;;
  919. esac
  920. case "$cur" in
  921. -*)
  922. COMPREPLY=( $( compgen -W "--checkpoint-dir --help" -- "$cur" ) )
  923. ;;
  924. *)
  925. local counter=$(__docker_pos_first_nonflag '--checkpoint-dir')
  926. if [ $cword -eq $counter ]; then
  927. __docker_complete_containers_all
  928. elif [ $cword -eq $(($counter + 1)) ]; then
  929. COMPREPLY=( $( compgen -W "$(__docker_q checkpoint ls "$prev" | sed 1d)" -- "$cur" ) )
  930. fi
  931. ;;
  932. esac
  933. }
  934. _docker_container() {
  935. local subcommands="
  936. attach
  937. commit
  938. cp
  939. create
  940. diff
  941. exec
  942. export
  943. inspect
  944. kill
  945. logs
  946. ls
  947. pause
  948. port
  949. prune
  950. rename
  951. restart
  952. rm
  953. run
  954. start
  955. stats
  956. stop
  957. top
  958. unpause
  959. update
  960. wait
  961. "
  962. local aliases="
  963. list
  964. ps
  965. "
  966. __docker_subcommands "$subcommands $aliases" && return
  967. case "$cur" in
  968. -*)
  969. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  970. ;;
  971. *)
  972. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  973. ;;
  974. esac
  975. }
  976. _docker_container_attach() {
  977. __docker_complete_detach_keys && return
  978. case "$cur" in
  979. -*)
  980. COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) )
  981. ;;
  982. *)
  983. local counter=$(__docker_pos_first_nonflag '--detach-keys')
  984. if [ $cword -eq $counter ]; then
  985. __docker_complete_containers_running
  986. fi
  987. ;;
  988. esac
  989. }
  990. _docker_container_commit() {
  991. case "$prev" in
  992. --author|-a|--change|-c|--message|-m)
  993. return
  994. ;;
  995. esac
  996. case "$cur" in
  997. -*)
  998. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) )
  999. ;;
  1000. *)
  1001. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  1002. if [ $cword -eq $counter ]; then
  1003. __docker_complete_containers_all
  1004. return
  1005. fi
  1006. (( counter++ ))
  1007. if [ $cword -eq $counter ]; then
  1008. __docker_complete_image_repos_and_tags
  1009. return
  1010. fi
  1011. ;;
  1012. esac
  1013. }
  1014. _docker_container_cp() {
  1015. case "$cur" in
  1016. -*)
  1017. COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) )
  1018. ;;
  1019. *)
  1020. local counter=$(__docker_pos_first_nonflag)
  1021. if [ $cword -eq $counter ]; then
  1022. case "$cur" in
  1023. *:)
  1024. return
  1025. ;;
  1026. *)
  1027. # combined container and filename completion
  1028. _filedir
  1029. local files=( ${COMPREPLY[@]} )
  1030. __docker_complete_containers_all
  1031. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1032. local containers=( ${COMPREPLY[@]} )
  1033. COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) )
  1034. if [[ "$COMPREPLY" == *: ]]; then
  1035. __docker_nospace
  1036. fi
  1037. return
  1038. ;;
  1039. esac
  1040. fi
  1041. (( counter++ ))
  1042. if [ $cword -eq $counter ]; then
  1043. if [ -e "$prev" ]; then
  1044. __docker_complete_containers_all
  1045. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1046. __docker_nospace
  1047. else
  1048. _filedir
  1049. fi
  1050. return
  1051. fi
  1052. ;;
  1053. esac
  1054. }
  1055. _docker_container_create() {
  1056. _docker_container_run_and_create
  1057. }
  1058. _docker_container_diff() {
  1059. case "$cur" in
  1060. -*)
  1061. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1062. ;;
  1063. *)
  1064. local counter=$(__docker_pos_first_nonflag)
  1065. if [ $cword -eq $counter ]; then
  1066. __docker_complete_containers_all
  1067. fi
  1068. ;;
  1069. esac
  1070. }
  1071. _docker_container_exec() {
  1072. __docker_complete_detach_keys && return
  1073. case "$prev" in
  1074. --env|-e)
  1075. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  1076. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1077. __docker_nospace
  1078. return
  1079. ;;
  1080. --user|-u)
  1081. __docker_complete_user_group
  1082. return
  1083. ;;
  1084. esac
  1085. case "$cur" in
  1086. -*)
  1087. COMPREPLY=( $( compgen -W "--detach -d --detach-keys --env -e --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  1088. ;;
  1089. *)
  1090. __docker_complete_containers_running
  1091. ;;
  1092. esac
  1093. }
  1094. _docker_container_export() {
  1095. case "$prev" in
  1096. --output|-o)
  1097. _filedir
  1098. return
  1099. ;;
  1100. esac
  1101. case "$cur" in
  1102. -*)
  1103. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  1104. ;;
  1105. *)
  1106. local counter=$(__docker_pos_first_nonflag)
  1107. if [ $cword -eq $counter ]; then
  1108. __docker_complete_containers_all
  1109. fi
  1110. ;;
  1111. esac
  1112. }
  1113. _docker_container_inspect() {
  1114. _docker_inspect --type container
  1115. }
  1116. _docker_container_kill() {
  1117. case "$prev" in
  1118. --signal|-s)
  1119. __docker_complete_signals
  1120. return
  1121. ;;
  1122. esac
  1123. case "$cur" in
  1124. -*)
  1125. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  1126. ;;
  1127. *)
  1128. __docker_complete_containers_running
  1129. ;;
  1130. esac
  1131. }
  1132. _docker_container_logs() {
  1133. case "$prev" in
  1134. --since|--tail)
  1135. return
  1136. ;;
  1137. esac
  1138. case "$cur" in
  1139. -*)
  1140. COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  1141. ;;
  1142. *)
  1143. local counter=$(__docker_pos_first_nonflag '--since|--tail')
  1144. if [ $cword -eq $counter ]; then
  1145. __docker_complete_containers_all
  1146. fi
  1147. ;;
  1148. esac
  1149. }
  1150. _docker_container_list() {
  1151. _docker_container_ls
  1152. }
  1153. _docker_container_ls() {
  1154. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1155. case "$key" in
  1156. ancestor)
  1157. cur="${cur##*=}"
  1158. __docker_complete_images
  1159. return
  1160. ;;
  1161. before)
  1162. __docker_complete_containers_all --cur "${cur##*=}"
  1163. return
  1164. ;;
  1165. expose|publish)
  1166. return
  1167. ;;
  1168. id)
  1169. __docker_complete_containers_all --cur "${cur##*=}" --id
  1170. return
  1171. ;;
  1172. health)
  1173. COMPREPLY=( $( compgen -W "healthy starting none unhealthy" -- "${cur##*=}" ) )
  1174. return
  1175. ;;
  1176. is-task)
  1177. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  1178. return
  1179. ;;
  1180. name)
  1181. __docker_complete_containers_all --cur "${cur##*=}" --name
  1182. return
  1183. ;;
  1184. network)
  1185. __docker_complete_networks --cur "${cur##*=}"
  1186. return
  1187. ;;
  1188. since)
  1189. __docker_complete_containers_all --cur "${cur##*=}"
  1190. return
  1191. ;;
  1192. status)
  1193. COMPREPLY=( $( compgen -W "created dead exited paused restarting running removing" -- "${cur##*=}" ) )
  1194. return
  1195. ;;
  1196. volume)
  1197. __docker_complete_volumes --cur "${cur##*=}"
  1198. return
  1199. ;;
  1200. esac
  1201. case "$prev" in
  1202. --filter|-f)
  1203. COMPREPLY=( $( compgen -S = -W "ancestor before exited expose health id is-task label name network publish since status volume" -- "$cur" ) )
  1204. __docker_nospace
  1205. return
  1206. ;;
  1207. --format|--last|-n)
  1208. return
  1209. ;;
  1210. esac
  1211. case "$cur" in
  1212. -*)
  1213. COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) )
  1214. ;;
  1215. esac
  1216. }
  1217. _docker_container_pause() {
  1218. case "$cur" in
  1219. -*)
  1220. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1221. ;;
  1222. *)
  1223. __docker_complete_containers_running
  1224. ;;
  1225. esac
  1226. }
  1227. _docker_container_port() {
  1228. case "$cur" in
  1229. -*)
  1230. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1231. ;;
  1232. *)
  1233. local counter=$(__docker_pos_first_nonflag)
  1234. if [ $cword -eq $counter ]; then
  1235. __docker_complete_containers_all
  1236. fi
  1237. ;;
  1238. esac
  1239. }
  1240. _docker_container_prune() {
  1241. case "$prev" in
  1242. --filter)
  1243. COMPREPLY=( $( compgen -W "until" -S = -- "$cur" ) )
  1244. __docker_nospace
  1245. return
  1246. ;;
  1247. esac
  1248. case "$cur" in
  1249. -*)
  1250. COMPREPLY=( $( compgen -W "--force -f --filter --help" -- "$cur" ) )
  1251. ;;
  1252. esac
  1253. }
  1254. _docker_container_ps() {
  1255. _docker_container_ls
  1256. }
  1257. _docker_container_rename() {
  1258. case "$cur" in
  1259. -*)
  1260. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1261. ;;
  1262. *)
  1263. local counter=$(__docker_pos_first_nonflag)
  1264. if [ $cword -eq $counter ]; then
  1265. __docker_complete_containers_all
  1266. fi
  1267. ;;
  1268. esac
  1269. }
  1270. _docker_container_restart() {
  1271. case "$prev" in
  1272. --time|-t)
  1273. return
  1274. ;;
  1275. esac
  1276. case "$cur" in
  1277. -*)
  1278. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1279. ;;
  1280. *)
  1281. __docker_complete_containers_all
  1282. ;;
  1283. esac
  1284. }
  1285. _docker_container_rm() {
  1286. case "$cur" in
  1287. -*)
  1288. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  1289. ;;
  1290. *)
  1291. for arg in "${COMP_WORDS[@]}"; do
  1292. case "$arg" in
  1293. --force|-f)
  1294. __docker_complete_containers_all
  1295. return
  1296. ;;
  1297. esac
  1298. done
  1299. __docker_complete_containers_stopped
  1300. ;;
  1301. esac
  1302. }
  1303. _docker_container_run() {
  1304. _docker_container_run_and_create
  1305. }
  1306. # _docker_container_run_and_create is the combined completion for `_docker_container_run`
  1307. # and `_docker_container_create`
  1308. _docker_container_run_and_create() {
  1309. local options_with_args="
  1310. --add-host
  1311. --attach -a
  1312. --blkio-weight
  1313. --blkio-weight-device
  1314. --cap-add
  1315. --cap-drop
  1316. --cgroup-parent
  1317. --cidfile
  1318. --cpu-period
  1319. --cpu-quota
  1320. --cpu-rt-period
  1321. --cpu-rt-runtime
  1322. --cpuset-cpus
  1323. --cpus
  1324. --cpuset-mems
  1325. --cpu-shares -c
  1326. --device
  1327. --device-cgroup-rule
  1328. --device-read-bps
  1329. --device-read-iops
  1330. --device-write-bps
  1331. --device-write-iops
  1332. --dns
  1333. --dns-option
  1334. --dns-search
  1335. --entrypoint
  1336. --env -e
  1337. --env-file
  1338. --expose
  1339. --group-add
  1340. --hostname -h
  1341. --init-path
  1342. --ip
  1343. --ip6
  1344. --ipc
  1345. --kernel-memory
  1346. --label-file
  1347. --label -l
  1348. --link
  1349. --link-local-ip
  1350. --log-driver
  1351. --log-opt
  1352. --mac-address
  1353. --memory -m
  1354. --memory-swap
  1355. --memory-swappiness
  1356. --memory-reservation
  1357. --name
  1358. --network
  1359. --network-alias
  1360. --oom-score-adj
  1361. --pid
  1362. --pids-limit
  1363. --publish -p
  1364. --restart
  1365. --runtime
  1366. --security-opt
  1367. --shm-size
  1368. --stop-signal
  1369. --stop-timeout
  1370. --storage-opt
  1371. --tmpfs
  1372. --sysctl
  1373. --ulimit
  1374. --user -u
  1375. --userns
  1376. --uts
  1377. --volume-driver
  1378. --volumes-from
  1379. --volume -v
  1380. --workdir -w
  1381. "
  1382. __docker_daemon_os_is windows && options_with_args+="
  1383. --cpu-count
  1384. --cpu-percent
  1385. --credentialspec
  1386. --io-maxbandwidth
  1387. --io-maxiops
  1388. --isolation
  1389. "
  1390. local boolean_options="
  1391. --disable-content-trust=false
  1392. --help
  1393. --init
  1394. --interactive -i
  1395. --oom-kill-disable
  1396. --privileged
  1397. --publish-all -P
  1398. --read-only
  1399. --tty -t
  1400. "
  1401. if [ "$command" = "run" -o "$subcommand" = "run" ] ; then
  1402. options_with_args="$options_with_args
  1403. --detach-keys
  1404. --health-cmd
  1405. --health-interval
  1406. --health-retries
  1407. --health-timeout
  1408. "
  1409. boolean_options="$boolean_options
  1410. --detach -d
  1411. --no-healthcheck
  1412. --rm
  1413. --sig-proxy=false
  1414. "
  1415. __docker_complete_detach_keys && return
  1416. fi
  1417. local all_options="$options_with_args $boolean_options"
  1418. __docker_complete_log_driver_options && return
  1419. __docker_complete_restart && return
  1420. local key=$(__docker_map_key_of_current_option '--security-opt')
  1421. case "$key" in
  1422. label)
  1423. [[ $cur == *: ]] && return
  1424. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  1425. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  1426. __docker_nospace
  1427. fi
  1428. return
  1429. ;;
  1430. seccomp)
  1431. local cur=${cur##*=}
  1432. _filedir
  1433. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  1434. return
  1435. ;;
  1436. esac
  1437. case "$prev" in
  1438. --add-host)
  1439. case "$cur" in
  1440. *:)
  1441. __docker_complete_resolved_hostname
  1442. return
  1443. ;;
  1444. esac
  1445. ;;
  1446. --attach|-a)
  1447. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  1448. return
  1449. ;;
  1450. --cap-add)
  1451. __docker_complete_capabilities_addable
  1452. return
  1453. ;;
  1454. --cap-drop)
  1455. __docker_complete_capabilities_droppable
  1456. return
  1457. ;;
  1458. --cidfile|--env-file|--init-path|--label-file)
  1459. _filedir
  1460. return
  1461. ;;
  1462. --device|--tmpfs|--volume|-v)
  1463. case "$cur" in
  1464. *:*)
  1465. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  1466. ;;
  1467. '')
  1468. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  1469. __docker_nospace
  1470. ;;
  1471. /*)
  1472. _filedir
  1473. __docker_nospace
  1474. ;;
  1475. esac
  1476. return
  1477. ;;
  1478. --env|-e)
  1479. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  1480. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1481. __docker_nospace
  1482. return
  1483. ;;
  1484. --ipc)
  1485. case "$cur" in
  1486. *:*)
  1487. cur="${cur#*:}"
  1488. __docker_complete_containers_running
  1489. ;;
  1490. *)
  1491. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1492. if [ "$COMPREPLY" = "container:" ]; then
  1493. __docker_nospace
  1494. fi
  1495. ;;
  1496. esac
  1497. return
  1498. ;;
  1499. --isolation)
  1500. if __docker_daemon_os_is windows ; then
  1501. __docker_complete_isolation
  1502. return
  1503. fi
  1504. ;;
  1505. --link)
  1506. case "$cur" in
  1507. *:*)
  1508. ;;
  1509. *)
  1510. __docker_complete_containers_running
  1511. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1512. __docker_nospace
  1513. ;;
  1514. esac
  1515. return
  1516. ;;
  1517. --log-driver)
  1518. __docker_complete_log_drivers
  1519. return
  1520. ;;
  1521. --log-opt)
  1522. __docker_complete_log_options
  1523. return
  1524. ;;
  1525. --network)
  1526. case "$cur" in
  1527. container:*)
  1528. __docker_complete_containers_all --cur "${cur#*:}"
  1529. ;;
  1530. *)
  1531. COMPREPLY=( $( compgen -W "$(__docker_plugins_bundled --type Network) $(__docker_networks) container:" -- "$cur") )
  1532. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1533. __docker_nospace
  1534. fi
  1535. ;;
  1536. esac
  1537. return
  1538. ;;
  1539. --pid)
  1540. case "$cur" in
  1541. *:*)
  1542. __docker_complete_containers_running --cur "${cur#*:}"
  1543. ;;
  1544. *)
  1545. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1546. if [ "$COMPREPLY" = "container:" ]; then
  1547. __docker_nospace
  1548. fi
  1549. ;;
  1550. esac
  1551. return
  1552. ;;
  1553. --runtime)
  1554. __docker_complete_runtimes
  1555. return
  1556. ;;
  1557. --security-opt)
  1558. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  1559. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  1560. __docker_nospace
  1561. fi
  1562. return
  1563. ;;
  1564. --storage-opt)
  1565. COMPREPLY=( $( compgen -W "size" -S = -- "$cur") )
  1566. __docker_nospace
  1567. return
  1568. ;;
  1569. --user|-u)
  1570. __docker_complete_user_group
  1571. return
  1572. ;;
  1573. --userns)
  1574. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  1575. return
  1576. ;;
  1577. --volume-driver)
  1578. __docker_complete_plugins_bundled --type Volume
  1579. return
  1580. ;;
  1581. --volumes-from)
  1582. __docker_complete_containers_all
  1583. return
  1584. ;;
  1585. $(__docker_to_extglob "$options_with_args") )
  1586. return
  1587. ;;
  1588. esac
  1589. case "$cur" in
  1590. -*)
  1591. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1592. ;;
  1593. *)
  1594. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1595. if [ $cword -eq $counter ]; then
  1596. __docker_complete_images
  1597. fi
  1598. ;;
  1599. esac
  1600. }
  1601. _docker_container_start() {
  1602. __docker_complete_detach_keys && return
  1603. case "$prev" in
  1604. --checkpoint)
  1605. if [ __docker_daemon_is_experimental ] ; then
  1606. return
  1607. fi
  1608. ;;
  1609. --checkpoint-dir)
  1610. if [ __docker_daemon_is_experimental ] ; then
  1611. _filedir -d
  1612. return
  1613. fi
  1614. ;;
  1615. esac
  1616. case "$cur" in
  1617. -*)
  1618. local options="--attach -a --detach-keys --help --interactive -i"
  1619. __docker_daemon_is_experimental && options+=" --checkpoint --checkpoint-dir"
  1620. COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
  1621. ;;
  1622. *)
  1623. __docker_complete_containers_stopped
  1624. ;;
  1625. esac
  1626. }
  1627. _docker_container_stats() {
  1628. case "$prev" in
  1629. --format)
  1630. return
  1631. ;;
  1632. esac
  1633. case "$cur" in
  1634. -*)
  1635. COMPREPLY=( $( compgen -W "--all -a --format --help --no-stream" -- "$cur" ) )
  1636. ;;
  1637. *)
  1638. __docker_complete_containers_running
  1639. ;;
  1640. esac
  1641. }
  1642. _docker_container_stop() {
  1643. case "$prev" in
  1644. --time|-t)
  1645. return
  1646. ;;
  1647. esac
  1648. case "$cur" in
  1649. -*)
  1650. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1651. ;;
  1652. *)
  1653. __docker_complete_containers_running
  1654. ;;
  1655. esac
  1656. }
  1657. _docker_container_top() {
  1658. case "$cur" in
  1659. -*)
  1660. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1661. ;;
  1662. *)
  1663. local counter=$(__docker_pos_first_nonflag)
  1664. if [ $cword -eq $counter ]; then
  1665. __docker_complete_containers_running
  1666. fi
  1667. ;;
  1668. esac
  1669. }
  1670. _docker_container_unpause() {
  1671. case "$cur" in
  1672. -*)
  1673. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1674. ;;
  1675. *)
  1676. local counter=$(__docker_pos_first_nonflag)
  1677. if [ $cword -eq $counter ]; then
  1678. __docker_complete_containers_unpauseable
  1679. fi
  1680. ;;
  1681. esac
  1682. }
  1683. _docker_container_update() {
  1684. local options_with_args="
  1685. --blkio-weight
  1686. --cpu-period
  1687. --cpu-quota
  1688. --cpu-rt-period
  1689. --cpu-rt-runtime
  1690. --cpuset-cpus
  1691. --cpuset-mems
  1692. --cpu-shares -c
  1693. --kernel-memory
  1694. --memory -m
  1695. --memory-reservation
  1696. --memory-swap
  1697. --restart
  1698. "
  1699. local boolean_options="
  1700. --help
  1701. "
  1702. local all_options="$options_with_args $boolean_options"
  1703. __docker_complete_restart && return
  1704. case "$prev" in
  1705. $(__docker_to_extglob "$options_with_args") )
  1706. return
  1707. ;;
  1708. esac
  1709. case "$cur" in
  1710. -*)
  1711. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1712. ;;
  1713. *)
  1714. __docker_complete_containers_all
  1715. ;;
  1716. esac
  1717. }
  1718. _docker_container_wait() {
  1719. case "$cur" in
  1720. -*)
  1721. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1722. ;;
  1723. *)
  1724. __docker_complete_containers_all
  1725. ;;
  1726. esac
  1727. }
  1728. _docker_commit() {
  1729. _docker_container_commit
  1730. }
  1731. _docker_cp() {
  1732. _docker_container_cp
  1733. }
  1734. _docker_create() {
  1735. _docker_container_create
  1736. }
  1737. _docker_daemon() {
  1738. local boolean_options="
  1739. $global_boolean_options
  1740. --disable-legacy-registry
  1741. --experimental
  1742. --help
  1743. --icc=false
  1744. --init
  1745. --ip-forward=false
  1746. --ip-masq=false
  1747. --iptables=false
  1748. --ipv6
  1749. --live-restore
  1750. --raw-logs
  1751. --selinux-enabled
  1752. --userland-proxy=false
  1753. "
  1754. local options_with_args="
  1755. $global_options_with_args
  1756. --add-runtime
  1757. --api-cors-header
  1758. --authorization-plugin
  1759. --bip
  1760. --bridge -b
  1761. --cgroup-parent
  1762. --cluster-advertise
  1763. --cluster-store
  1764. --cluster-store-opt
  1765. --config-file
  1766. --containerd
  1767. --default-gateway
  1768. --default-gateway-v6
  1769. --default-shm-size
  1770. --default-ulimit
  1771. --dns
  1772. --dns-search
  1773. --dns-opt
  1774. --exec-opt
  1775. --exec-root
  1776. --fixed-cidr
  1777. --fixed-cidr-v6
  1778. --graph -g
  1779. --group -G
  1780. --init-path
  1781. --insecure-registry
  1782. --ip
  1783. --label
  1784. --log-driver
  1785. --log-opt
  1786. --max-concurrent-downloads
  1787. --max-concurrent-uploads
  1788. --mtu
  1789. --oom-score-adjust
  1790. --pidfile -p
  1791. --registry-mirror
  1792. --seccomp-profile
  1793. --shutdown-timeout
  1794. --storage-driver -s
  1795. --storage-opt
  1796. --userland-proxy-path
  1797. --userns-remap
  1798. "
  1799. __docker_complete_log_driver_options && return
  1800. key=$(__docker_map_key_of_current_option '--cluster-store-opt')
  1801. case "$key" in
  1802. kv.*file)
  1803. cur=${cur##*=}
  1804. _filedir
  1805. return
  1806. ;;
  1807. esac
  1808. local key=$(__docker_map_key_of_current_option '--storage-opt')
  1809. case "$key" in
  1810. dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion)
  1811. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1812. return
  1813. ;;
  1814. dm.fs)
  1815. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) )
  1816. return
  1817. ;;
  1818. dm.thinpooldev)
  1819. cur=${cur##*=}
  1820. _filedir
  1821. return
  1822. ;;
  1823. esac
  1824. case "$prev" in
  1825. --authorization-plugin)
  1826. __docker_complete_plugins_bundled --type Authorization
  1827. return
  1828. ;;
  1829. --cluster-store)
  1830. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  1831. __docker_nospace
  1832. return
  1833. ;;
  1834. --cluster-store-opt)
  1835. COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) )
  1836. __docker_nospace
  1837. return
  1838. ;;
  1839. --config-file|--containerd|--init-path|--pidfile|-p|--tlscacert|--tlscert|--tlskey|--userland-proxy-path)
  1840. _filedir
  1841. return
  1842. ;;
  1843. --exec-root|--graph|-g)
  1844. _filedir -d
  1845. return
  1846. ;;
  1847. --log-driver)
  1848. __docker_complete_log_drivers
  1849. return
  1850. ;;
  1851. --storage-driver|-s)
  1852. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  1853. return
  1854. ;;
  1855. --storage-opt)
  1856. local btrfs_options="btrfs.min_space"
  1857. local devicemapper_options="
  1858. dm.basesize
  1859. dm.blkdiscard
  1860. dm.blocksize
  1861. dm.fs
  1862. dm.loopdatasize
  1863. dm.loopmetadatasize
  1864. dm.min_free_space
  1865. dm.mkfsarg
  1866. dm.mountopt
  1867. dm.override_udev_sync_check
  1868. dm.thinpooldev
  1869. dm.use_deferred_deletion
  1870. dm.use_deferred_removal
  1871. "
  1872. local zfs_options="zfs.fsname"
  1873. case $(__docker_value_of_option '--storage-driver|-s') in
  1874. '')
  1875. COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) )
  1876. ;;
  1877. btrfs)
  1878. COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) )
  1879. ;;
  1880. devicemapper)
  1881. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  1882. ;;
  1883. zfs)
  1884. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  1885. ;;
  1886. *)
  1887. return
  1888. ;;
  1889. esac
  1890. __docker_nospace
  1891. return
  1892. ;;
  1893. --log-level|-l)
  1894. __docker_complete_log_levels
  1895. return
  1896. ;;
  1897. --log-opt)
  1898. __docker_complete_log_options
  1899. return
  1900. ;;
  1901. --seccomp-profile)
  1902. _filedir json
  1903. return
  1904. ;;
  1905. --userns-remap)
  1906. __docker_complete_user_group
  1907. return
  1908. ;;
  1909. $(__docker_to_extglob "$options_with_args") )
  1910. return
  1911. ;;
  1912. esac
  1913. case "$cur" in
  1914. -*)
  1915. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1916. ;;
  1917. esac
  1918. }
  1919. _docker_deploy() {
  1920. __docker_daemon_is_experimental && _docker_stack_deploy
  1921. }
  1922. _docker_diff() {
  1923. _docker_container_diff
  1924. }
  1925. _docker_events() {
  1926. _docker_system_events
  1927. }
  1928. _docker_exec() {
  1929. _docker_container_exec
  1930. }
  1931. _docker_export() {
  1932. _docker_container_export
  1933. }
  1934. _docker_help() {
  1935. local counter=$(__docker_pos_first_nonflag)
  1936. if [ $cword -eq $counter ]; then
  1937. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  1938. fi
  1939. }
  1940. _docker_history() {
  1941. _docker_image_history
  1942. }
  1943. _docker_image() {
  1944. local subcommands="
  1945. build
  1946. history
  1947. import
  1948. inspect
  1949. load
  1950. ls
  1951. prune
  1952. pull
  1953. push
  1954. rm
  1955. save
  1956. tag
  1957. "
  1958. local aliases="
  1959. images
  1960. list
  1961. remove
  1962. rmi
  1963. "
  1964. __docker_subcommands "$subcommands $aliases" && return
  1965. case "$cur" in
  1966. -*)
  1967. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1968. ;;
  1969. *)
  1970. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1971. ;;
  1972. esac
  1973. }
  1974. _docker_image_build() {
  1975. local options_with_args="
  1976. --add-host
  1977. --build-arg
  1978. --cache-from
  1979. --cgroup-parent
  1980. --cpuset-cpus
  1981. --cpuset-mems
  1982. --cpu-shares -c
  1983. --cpu-period
  1984. --cpu-quota
  1985. --file -f
  1986. --label
  1987. --memory -m
  1988. --memory-swap
  1989. --network
  1990. --shm-size
  1991. --tag -t
  1992. --ulimit
  1993. "
  1994. __docker_daemon_os_is windows && options_with_args+="
  1995. --isolation
  1996. "
  1997. local boolean_options="
  1998. --compress
  1999. --disable-content-trust=false
  2000. --force-rm
  2001. --help
  2002. --no-cache
  2003. --pull
  2004. --quiet -q
  2005. --rm
  2006. "
  2007. __docker_daemon_is_experimental && boolean_options+="--squash"
  2008. local all_options="$options_with_args $boolean_options"
  2009. case "$prev" in
  2010. --add-host)
  2011. case "$cur" in
  2012. *:)
  2013. __docker_complete_resolved_hostname
  2014. return
  2015. ;;
  2016. esac
  2017. ;;
  2018. --build-arg)
  2019. COMPREPLY=( $( compgen -e -- "$cur" ) )
  2020. __docker_nospace
  2021. return
  2022. ;;
  2023. --cache-from)
  2024. __docker_complete_image_repos_and_tags
  2025. return
  2026. ;;
  2027. --file|-f)
  2028. _filedir
  2029. return
  2030. ;;
  2031. --isolation)
  2032. if __docker_daemon_os_is windows ; then
  2033. __docker_complete_isolation
  2034. return
  2035. fi
  2036. ;;
  2037. --network)
  2038. case "$cur" in
  2039. container:*)
  2040. __docker_complete_containers_all --cur "${cur#*:}"
  2041. ;;
  2042. *)
  2043. COMPREPLY=( $( compgen -W "$(__docker_plugins --type Network) $(__docker_networks) container:" -- "$cur") )
  2044. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  2045. __docker_nospace
  2046. fi
  2047. ;;
  2048. esac
  2049. return
  2050. ;;
  2051. --tag|-t)
  2052. __docker_complete_image_repos_and_tags
  2053. return
  2054. ;;
  2055. $(__docker_to_extglob "$options_with_args") )
  2056. return
  2057. ;;
  2058. esac
  2059. case "$cur" in
  2060. -*)
  2061. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2062. ;;
  2063. *)
  2064. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2065. if [ $cword -eq $counter ]; then
  2066. _filedir -d
  2067. fi
  2068. ;;
  2069. esac
  2070. }
  2071. _docker_image_history() {
  2072. case "$cur" in
  2073. -*)
  2074. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  2075. ;;
  2076. *)
  2077. local counter=$(__docker_pos_first_nonflag)
  2078. if [ $cword -eq $counter ]; then
  2079. __docker_complete_images
  2080. fi
  2081. ;;
  2082. esac
  2083. }
  2084. _docker_image_images() {
  2085. _docker_image_ls
  2086. }
  2087. _docker_image_import() {
  2088. case "$prev" in
  2089. --change|-c|--message|-m)
  2090. return
  2091. ;;
  2092. esac
  2093. case "$cur" in
  2094. -*)
  2095. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  2096. ;;
  2097. *)
  2098. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  2099. if [ $cword -eq $counter ]; then
  2100. return
  2101. fi
  2102. (( counter++ ))
  2103. if [ $cword -eq $counter ]; then
  2104. __docker_complete_image_repos_and_tags
  2105. return
  2106. fi
  2107. ;;
  2108. esac
  2109. }
  2110. _docker_image_inspect() {
  2111. _docker_inspect --type image
  2112. }
  2113. _docker_image_load() {
  2114. case "$prev" in
  2115. --input|-i)
  2116. _filedir
  2117. return
  2118. ;;
  2119. esac
  2120. case "$cur" in
  2121. -*)
  2122. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  2123. ;;
  2124. esac
  2125. }
  2126. _docker_image_list() {
  2127. _docker_image_ls
  2128. }
  2129. _docker_image_ls() {
  2130. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2131. case "$key" in
  2132. before|since|reference)
  2133. cur="${cur##*=}"
  2134. __docker_complete_images
  2135. return
  2136. ;;
  2137. dangling)
  2138. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2139. return
  2140. ;;
  2141. label)
  2142. return
  2143. ;;
  2144. esac
  2145. case "$prev" in
  2146. --filter|-f)
  2147. COMPREPLY=( $( compgen -S = -W "before dangling label reference since" -- "$cur" ) )
  2148. __docker_nospace
  2149. return
  2150. ;;
  2151. --format)
  2152. return
  2153. ;;
  2154. esac
  2155. case "$cur" in
  2156. -*)
  2157. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  2158. ;;
  2159. =)
  2160. return
  2161. ;;
  2162. *)
  2163. __docker_complete_image_repos
  2164. ;;
  2165. esac
  2166. }
  2167. _docker_image_prune() {
  2168. case "$prev" in
  2169. --filter)
  2170. COMPREPLY=( $( compgen -W "until" -S = -- "$cur" ) )
  2171. __docker_nospace
  2172. return
  2173. ;;
  2174. esac
  2175. case "$cur" in
  2176. -*)
  2177. COMPREPLY=( $( compgen -W "--all -a --force -f --filter --help" -- "$cur" ) )
  2178. ;;
  2179. esac
  2180. }
  2181. _docker_image_pull() {
  2182. case "$cur" in
  2183. -*)
  2184. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  2185. ;;
  2186. *)
  2187. local counter=$(__docker_pos_first_nonflag)
  2188. if [ $cword -eq $counter ]; then
  2189. for arg in "${COMP_WORDS[@]}"; do
  2190. case "$arg" in
  2191. --all-tags|-a)
  2192. __docker_complete_image_repos
  2193. return
  2194. ;;
  2195. esac
  2196. done
  2197. __docker_complete_image_repos_and_tags
  2198. fi
  2199. ;;
  2200. esac
  2201. }
  2202. _docker_image_push() {
  2203. case "$cur" in
  2204. -*)
  2205. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  2206. ;;
  2207. *)
  2208. local counter=$(__docker_pos_first_nonflag)
  2209. if [ $cword -eq $counter ]; then
  2210. __docker_complete_image_repos_and_tags
  2211. fi
  2212. ;;
  2213. esac
  2214. }
  2215. _docker_image_remove() {
  2216. _docker_image_rm
  2217. }
  2218. _docker_image_rm() {
  2219. case "$cur" in
  2220. -*)
  2221. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  2222. ;;
  2223. *)
  2224. __docker_complete_images
  2225. ;;
  2226. esac
  2227. }
  2228. _docker_image_rmi() {
  2229. _docker_image_rm
  2230. }
  2231. _docker_image_save() {
  2232. case "$prev" in
  2233. --output|-o)
  2234. _filedir
  2235. return
  2236. ;;
  2237. esac
  2238. case "$cur" in
  2239. -*)
  2240. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  2241. ;;
  2242. *)
  2243. __docker_complete_images
  2244. ;;
  2245. esac
  2246. }
  2247. _docker_image_tag() {
  2248. case "$cur" in
  2249. -*)
  2250. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2251. ;;
  2252. *)
  2253. local counter=$(__docker_pos_first_nonflag)
  2254. if [ $cword -eq $counter ]; then
  2255. __docker_complete_image_repos_and_tags
  2256. return
  2257. fi
  2258. (( counter++ ))
  2259. if [ $cword -eq $counter ]; then
  2260. __docker_complete_image_repos_and_tags
  2261. return
  2262. fi
  2263. ;;
  2264. esac
  2265. }
  2266. _docker_images() {
  2267. _docker_image_ls
  2268. }
  2269. _docker_import() {
  2270. _docker_image_import
  2271. }
  2272. _docker_info() {
  2273. _docker_system_info
  2274. }
  2275. _docker_inspect() {
  2276. local preselected_type
  2277. local type
  2278. if [ "$1" = "--type" ] ; then
  2279. preselected_type=yes
  2280. type="$2"
  2281. else
  2282. type=$(__docker_value_of_option --type)
  2283. fi
  2284. case "$prev" in
  2285. --format|-f)
  2286. return
  2287. ;;
  2288. --type)
  2289. if [ -z "$preselected_type" ] ; then
  2290. COMPREPLY=( $( compgen -W "container image network node plugin service volume" -- "$cur" ) )
  2291. return
  2292. fi
  2293. ;;
  2294. esac
  2295. case "$cur" in
  2296. -*)
  2297. local options="--format -f --help --size -s"
  2298. if [ -z "$preselected_type" ] ; then
  2299. options+=" --type"
  2300. fi
  2301. COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
  2302. ;;
  2303. *)
  2304. case "$type" in
  2305. '')
  2306. COMPREPLY=( $( compgen -W "
  2307. $(__docker_containers --all)
  2308. $(__docker_images)
  2309. $(__docker_networks)
  2310. $(__docker_nodes)
  2311. $(__docker_plugins_installed)
  2312. $(__docker_services)
  2313. $(__docker_volumes)
  2314. " -- "$cur" ) )
  2315. ;;
  2316. container)
  2317. __docker_complete_containers_all
  2318. ;;
  2319. image)
  2320. __docker_complete_images
  2321. ;;
  2322. network)
  2323. __docker_complete_networks
  2324. ;;
  2325. node)
  2326. __docker_complete_nodes
  2327. ;;
  2328. plugin)
  2329. __docker_complete_plugins_installed
  2330. ;;
  2331. service)
  2332. __docker_complete_services
  2333. ;;
  2334. volume)
  2335. __docker_complete_volumes
  2336. ;;
  2337. esac
  2338. esac
  2339. }
  2340. _docker_kill() {
  2341. _docker_container_kill
  2342. }
  2343. _docker_load() {
  2344. _docker_image_load
  2345. }
  2346. _docker_login() {
  2347. case "$prev" in
  2348. --password|-p|--username|-u)
  2349. return
  2350. ;;
  2351. esac
  2352. case "$cur" in
  2353. -*)
  2354. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  2355. ;;
  2356. esac
  2357. }
  2358. _docker_logout() {
  2359. case "$cur" in
  2360. -*)
  2361. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2362. ;;
  2363. esac
  2364. }
  2365. _docker_logs() {
  2366. _docker_container_logs
  2367. }
  2368. _docker_network_connect() {
  2369. local options_with_args="
  2370. --alias
  2371. --ip
  2372. --ip6
  2373. --link
  2374. --link-local-ip
  2375. "
  2376. local boolean_options="
  2377. --help
  2378. "
  2379. case "$prev" in
  2380. --link)
  2381. case "$cur" in
  2382. *:*)
  2383. ;;
  2384. *)
  2385. __docker_complete_containers_running
  2386. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  2387. __docker_nospace
  2388. ;;
  2389. esac
  2390. return
  2391. ;;
  2392. $(__docker_to_extglob "$options_with_args") )
  2393. return
  2394. ;;
  2395. esac
  2396. case "$cur" in
  2397. -*)
  2398. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  2399. ;;
  2400. *)
  2401. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2402. if [ $cword -eq $counter ]; then
  2403. __docker_complete_networks
  2404. elif [ $cword -eq $(($counter + 1)) ]; then
  2405. __docker_complete_containers_all
  2406. fi
  2407. ;;
  2408. esac
  2409. }
  2410. _docker_network_create() {
  2411. case "$prev" in
  2412. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  2413. return
  2414. ;;
  2415. --ipam-driver)
  2416. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  2417. return
  2418. ;;
  2419. --driver|-d)
  2420. # remove drivers that allow one instance only, add drivers missing in `docker info`
  2421. __docker_complete_plugins_bundled --type Network --remove host --remove null --add macvlan
  2422. return
  2423. ;;
  2424. --label)
  2425. return
  2426. ;;
  2427. esac
  2428. case "$cur" in
  2429. -*)
  2430. COMPREPLY=( $( compgen -W "--attachable --aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  2431. ;;
  2432. esac
  2433. }
  2434. _docker_network_disconnect() {
  2435. case "$cur" in
  2436. -*)
  2437. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2438. ;;
  2439. *)
  2440. local counter=$(__docker_pos_first_nonflag)
  2441. if [ $cword -eq $counter ]; then
  2442. __docker_complete_networks
  2443. elif [ $cword -eq $(($counter + 1)) ]; then
  2444. __docker_complete_containers_in_network "$prev"
  2445. fi
  2446. ;;
  2447. esac
  2448. }
  2449. _docker_network_inspect() {
  2450. case "$prev" in
  2451. --format|-f)
  2452. return
  2453. ;;
  2454. esac
  2455. case "$cur" in
  2456. -*)
  2457. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2458. ;;
  2459. *)
  2460. __docker_complete_networks
  2461. esac
  2462. }
  2463. _docker_network_ls() {
  2464. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2465. case "$key" in
  2466. driver)
  2467. __docker_complete_plugins_bundled --cur "${cur##*=}" --type Network --add macvlan
  2468. return
  2469. ;;
  2470. id)
  2471. __docker_complete_networks --cur "${cur##*=}" --id
  2472. return
  2473. ;;
  2474. name)
  2475. __docker_complete_networks --cur "${cur##*=}" --name
  2476. return
  2477. ;;
  2478. type)
  2479. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  2480. return
  2481. ;;
  2482. esac
  2483. case "$prev" in
  2484. --filter|-f)
  2485. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  2486. __docker_nospace
  2487. return
  2488. ;;
  2489. --format)
  2490. return
  2491. ;;
  2492. esac
  2493. case "$cur" in
  2494. -*)
  2495. COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  2496. ;;
  2497. esac
  2498. }
  2499. _docker_network_prune() {
  2500. case "$prev" in
  2501. --filter)
  2502. COMPREPLY=( $( compgen -W "until" -S = -- "$cur" ) )
  2503. __docker_nospace
  2504. return
  2505. ;;
  2506. esac
  2507. case "$cur" in
  2508. -*)
  2509. COMPREPLY=( $( compgen -W "--force -f --filter --help" -- "$cur" ) )
  2510. ;;
  2511. esac
  2512. }
  2513. _docker_network_rm() {
  2514. case "$cur" in
  2515. -*)
  2516. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2517. ;;
  2518. *)
  2519. __docker_complete_networks --filter type=custom
  2520. esac
  2521. }
  2522. _docker_network() {
  2523. local subcommands="
  2524. connect
  2525. create
  2526. disconnect
  2527. inspect
  2528. ls
  2529. prune
  2530. rm
  2531. "
  2532. local aliases="
  2533. list
  2534. remove
  2535. "
  2536. __docker_subcommands "$subcommands $aliases" && return
  2537. case "$cur" in
  2538. -*)
  2539. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2540. ;;
  2541. *)
  2542. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2543. ;;
  2544. esac
  2545. }
  2546. _docker_service() {
  2547. local subcommands="
  2548. create
  2549. inspect
  2550. ls
  2551. rm
  2552. scale
  2553. ps
  2554. update
  2555. "
  2556. __docker_daemon_is_experimental && subcommands+="logs"
  2557. local aliases="
  2558. list
  2559. remove
  2560. "
  2561. __docker_subcommands "$subcommands $aliases" && return
  2562. case "$cur" in
  2563. -*)
  2564. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2565. ;;
  2566. *)
  2567. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2568. ;;
  2569. esac
  2570. }
  2571. _docker_service_create() {
  2572. _docker_service_update_and_create
  2573. }
  2574. _docker_service_inspect() {
  2575. case "$prev" in
  2576. --format|-f)
  2577. return
  2578. ;;
  2579. esac
  2580. case "$cur" in
  2581. -*)
  2582. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  2583. ;;
  2584. *)
  2585. __docker_complete_services
  2586. esac
  2587. }
  2588. _docker_service_logs() {
  2589. case "$prev" in
  2590. --since|--tail)
  2591. return
  2592. ;;
  2593. esac
  2594. case "$cur" in
  2595. -*)
  2596. COMPREPLY=( $( compgen -W "--details --follow -f --help --no-resolve --since --tail --timestamps -t" -- "$cur" ) )
  2597. ;;
  2598. *)
  2599. local counter=$(__docker_pos_first_nonflag '--since|--tail')
  2600. if [ $cword -eq $counter ]; then
  2601. __docker_complete_services
  2602. fi
  2603. ;;
  2604. esac
  2605. }
  2606. _docker_service_list() {
  2607. _docker_service_ls
  2608. }
  2609. _docker_service_ls() {
  2610. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2611. case "$key" in
  2612. id)
  2613. __docker_complete_services --cur "${cur##*=}" --id
  2614. return
  2615. ;;
  2616. name)
  2617. __docker_complete_services --cur "${cur##*=}" --name
  2618. return
  2619. ;;
  2620. esac
  2621. case "$prev" in
  2622. --filter|-f)
  2623. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  2624. __docker_nospace
  2625. return
  2626. ;;
  2627. --format)
  2628. return
  2629. ;;
  2630. esac
  2631. case "$cur" in
  2632. -*)
  2633. COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
  2634. ;;
  2635. esac
  2636. }
  2637. _docker_service_remove() {
  2638. _docker_service_rm
  2639. }
  2640. _docker_service_rm() {
  2641. case "$cur" in
  2642. -*)
  2643. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2644. ;;
  2645. *)
  2646. __docker_complete_services
  2647. esac
  2648. }
  2649. _docker_service_scale() {
  2650. case "$cur" in
  2651. -*)
  2652. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2653. ;;
  2654. *)
  2655. __docker_complete_services
  2656. __docker_append_to_completions "="
  2657. __docker_nospace
  2658. ;;
  2659. esac
  2660. }
  2661. _docker_service_ps() {
  2662. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2663. case "$key" in
  2664. desired-state)
  2665. COMPREPLY=( $( compgen -W "accepted running shutdown" -- "${cur##*=}" ) )
  2666. return
  2667. ;;
  2668. name)
  2669. __docker_complete_services --cur "${cur##*=}" --name
  2670. return
  2671. ;;
  2672. node)
  2673. __docker_complete_nodes --cur "${cur##*=}" --add self
  2674. return
  2675. ;;
  2676. esac
  2677. case "$prev" in
  2678. --filter|-f)
  2679. COMPREPLY=( $( compgen -W "desired-state id name node" -S = -- "$cur" ) )
  2680. __docker_nospace
  2681. return
  2682. ;;
  2683. esac
  2684. case "$cur" in
  2685. -*)
  2686. COMPREPLY=( $( compgen -W "--filter -f --help --no-resolve --no-trunc --quiet -q" -- "$cur" ) )
  2687. ;;
  2688. *)
  2689. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  2690. if [ $cword -eq $counter ]; then
  2691. __docker_complete_services
  2692. fi
  2693. ;;
  2694. esac
  2695. }
  2696. _docker_service_update() {
  2697. _docker_service_update_and_create
  2698. }
  2699. # _docker_service_update_and_create is the combined completion for `docker service create`
  2700. # and `docker service update`
  2701. _docker_service_update_and_create() {
  2702. local $subcommand="${words[$subcommand_pos]}"
  2703. local options_with_args="
  2704. --constraint
  2705. --endpoint-mode
  2706. --env -e
  2707. --force
  2708. --health-cmd
  2709. --health-interval
  2710. --health-retries
  2711. --health-timeout
  2712. --hostname
  2713. --label -l
  2714. --limit-cpu
  2715. --limit-memory
  2716. --log-driver
  2717. --log-opt
  2718. --mount
  2719. --network
  2720. --no-healthcheck
  2721. --replicas
  2722. --reserve-cpu
  2723. --reserve-memory
  2724. --restart-condition
  2725. --restart-delay
  2726. --restart-max-attempts
  2727. --restart-window
  2728. --rollback-delay
  2729. --rollback-failure-action
  2730. --rollback-max-failure-ratio
  2731. --rollback-monitor
  2732. --rollback-parallelism
  2733. --stop-grace-period
  2734. --update-delay
  2735. --update-failure-action
  2736. --update-max-failure-ratio
  2737. --update-monitor
  2738. --update-parallelism
  2739. --user -u
  2740. --workdir -w
  2741. "
  2742. local boolean_options="
  2743. --help
  2744. --read-only
  2745. --tty -t
  2746. --with-registry-auth
  2747. "
  2748. __docker_complete_log_driver_options && return
  2749. if [ "$subcommand" = "create" ] ; then
  2750. options_with_args="$options_with_args
  2751. --container-label
  2752. --dns
  2753. --dns-option
  2754. --dns-search
  2755. --env-file
  2756. --group
  2757. --host
  2758. --mode
  2759. --name
  2760. --publish -p
  2761. --secret
  2762. "
  2763. case "$prev" in
  2764. --env-file)
  2765. _filedir
  2766. return
  2767. ;;
  2768. --group)
  2769. COMPREPLY=( $(compgen -g -- "$cur") )
  2770. return
  2771. ;;
  2772. --host)
  2773. case "$cur" in
  2774. *:)
  2775. __docker_complete_resolved_hostname
  2776. return
  2777. ;;
  2778. esac
  2779. ;;
  2780. --mode)
  2781. COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) )
  2782. return
  2783. ;;
  2784. --secret)
  2785. __docker_complete_secrets
  2786. return
  2787. ;;
  2788. esac
  2789. fi
  2790. if [ "$subcommand" = "update" ] ; then
  2791. options_with_args="$options_with_args
  2792. --arg
  2793. --container-label-add
  2794. --container-label-rm
  2795. --dns-add
  2796. --dns-option-add
  2797. --dns-option-rm
  2798. --dns-rm
  2799. --dns-search-add
  2800. --dns-search-rm
  2801. --group-add
  2802. --group-rm
  2803. --host-add
  2804. --host-rm
  2805. --image
  2806. --publish-add
  2807. --publish-rm
  2808. --rollback
  2809. --secret-add
  2810. --secret-rm
  2811. "
  2812. case "$prev" in
  2813. --group-add|--group-rm)
  2814. COMPREPLY=( $(compgen -g -- "$cur") )
  2815. return
  2816. ;;
  2817. --host-add|--host-rm)
  2818. case "$cur" in
  2819. *:)
  2820. __docker_complete_resolved_hostname
  2821. return
  2822. ;;
  2823. esac
  2824. ;;
  2825. --image)
  2826. __docker_complete_image_repos_and_tags
  2827. return
  2828. ;;
  2829. --secret-add|--secret-rm)
  2830. __docker_complete_secrets
  2831. return
  2832. ;;
  2833. esac
  2834. fi
  2835. case "$prev" in
  2836. --endpoint-mode)
  2837. COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) )
  2838. return
  2839. ;;
  2840. --env|-e)
  2841. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  2842. COMPREPLY=( $( compgen -e -- "$cur" ) )
  2843. __docker_nospace
  2844. return
  2845. ;;
  2846. --log-driver)
  2847. __docker_complete_log_drivers
  2848. return
  2849. ;;
  2850. --log-opt)
  2851. __docker_complete_log_options
  2852. return
  2853. ;;
  2854. --network)
  2855. __docker_complete_networks
  2856. return
  2857. ;;
  2858. --restart-condition)
  2859. COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) )
  2860. return
  2861. ;;
  2862. --rollback-failure-action)
  2863. COMPREPLY=( $( compgen -W "continue pause" -- "$cur" ) )
  2864. return
  2865. ;;
  2866. --update-failure-action)
  2867. COMPREPLY=( $( compgen -W "continue pause rollback" -- "$cur" ) )
  2868. return
  2869. ;;
  2870. --user|-u)
  2871. __docker_complete_user_group
  2872. return
  2873. ;;
  2874. $(__docker_to_extglob "$options_with_args") )
  2875. return
  2876. ;;
  2877. esac
  2878. case "$cur" in
  2879. -*)
  2880. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  2881. ;;
  2882. *)
  2883. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2884. if [ "$subcommand" = "update" ] ; then
  2885. if [ $cword -eq $counter ]; then
  2886. __docker_complete_services
  2887. fi
  2888. else
  2889. if [ $cword -eq $counter ]; then
  2890. __docker_complete_images
  2891. fi
  2892. fi
  2893. ;;
  2894. esac
  2895. }
  2896. _docker_swarm() {
  2897. local subcommands="
  2898. init
  2899. join
  2900. join-token
  2901. leave
  2902. unlock
  2903. unlock-key
  2904. update
  2905. "
  2906. __docker_subcommands "$subcommands" && return
  2907. case "$cur" in
  2908. -*)
  2909. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2910. ;;
  2911. *)
  2912. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2913. ;;
  2914. esac
  2915. }
  2916. _docker_swarm_init() {
  2917. case "$prev" in
  2918. --advertise-addr)
  2919. if [[ $cur == *: ]] ; then
  2920. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2921. else
  2922. __docker_complete_local_interfaces
  2923. __docker_nospace
  2924. fi
  2925. return
  2926. ;;
  2927. --availability)
  2928. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  2929. return
  2930. ;;
  2931. --cert-expiry|--dispatcher-heartbeat|--external-ca|--max-snapshots|--snapshot-interval|--task-history-limit)
  2932. return
  2933. ;;
  2934. --listen-addr)
  2935. if [[ $cur == *: ]] ; then
  2936. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2937. else
  2938. __docker_complete_local_interfaces --add 0.0.0.0
  2939. __docker_nospace
  2940. fi
  2941. return
  2942. ;;
  2943. esac
  2944. case "$cur" in
  2945. -*)
  2946. COMPREPLY=( $( compgen -W "--advertise-addr --autolock --availability --cert-expiry --dispatcher-heartbeat --external-ca --force-new-cluster --help --listen-addr --max-snapshots --snapshot-interval --task-history-limit" -- "$cur" ) )
  2947. ;;
  2948. esac
  2949. }
  2950. _docker_swarm_join() {
  2951. case "$prev" in
  2952. --advertise-addr)
  2953. if [[ $cur == *: ]] ; then
  2954. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2955. else
  2956. __docker_complete_local_interfaces
  2957. __docker_nospace
  2958. fi
  2959. return
  2960. ;;
  2961. --listen-addr)
  2962. if [[ $cur == *: ]] ; then
  2963. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2964. else
  2965. __docker_complete_local_interfaces --add 0.0.0.0
  2966. __docker_nospace
  2967. fi
  2968. return
  2969. ;;
  2970. --availability)
  2971. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  2972. return
  2973. ;;
  2974. --token)
  2975. return
  2976. ;;
  2977. esac
  2978. case "$cur" in
  2979. -*)
  2980. COMPREPLY=( $( compgen -W "--advertise-addr --availability --help --listen-addr --token" -- "$cur" ) )
  2981. ;;
  2982. *:)
  2983. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2984. ;;
  2985. esac
  2986. }
  2987. _docker_swarm_join_token() {
  2988. case "$cur" in
  2989. -*)
  2990. COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) )
  2991. ;;
  2992. *)
  2993. local counter=$( __docker_pos_first_nonflag )
  2994. if [ $cword -eq $counter ]; then
  2995. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  2996. fi
  2997. ;;
  2998. esac
  2999. }
  3000. _docker_swarm_leave() {
  3001. case "$cur" in
  3002. -*)
  3003. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3004. ;;
  3005. esac
  3006. }
  3007. _docker_swarm_unlock() {
  3008. case "$cur" in
  3009. -*)
  3010. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3011. ;;
  3012. esac
  3013. }
  3014. _docker_swarm_unlock_key() {
  3015. case "$cur" in
  3016. -*)
  3017. COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) )
  3018. ;;
  3019. esac
  3020. }
  3021. _docker_swarm_update() {
  3022. case "$prev" in
  3023. --cert-expiry|--dispatcher-heartbeat|--external-ca|--max-snapshots|--snapshot-interval|--task-history-limit)
  3024. return
  3025. ;;
  3026. esac
  3027. case "$cur" in
  3028. -*)
  3029. COMPREPLY=( $( compgen -W "--autolock --cert-expiry --dispatcher-heartbeat --external-ca --help --max-snapshots --snapshot-interval --task-history-limit" -- "$cur" ) )
  3030. ;;
  3031. esac
  3032. }
  3033. _docker_node() {
  3034. local subcommands="
  3035. demote
  3036. inspect
  3037. ls
  3038. promote
  3039. rm
  3040. ps
  3041. update
  3042. "
  3043. local aliases="
  3044. list
  3045. remove
  3046. "
  3047. __docker_subcommands "$subcommands $aliases" && return
  3048. case "$cur" in
  3049. -*)
  3050. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3051. ;;
  3052. *)
  3053. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3054. ;;
  3055. esac
  3056. }
  3057. _docker_node_demote() {
  3058. case "$cur" in
  3059. -*)
  3060. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3061. ;;
  3062. *)
  3063. __docker_complete_nodes --filter role=manager
  3064. esac
  3065. }
  3066. _docker_node_inspect() {
  3067. case "$prev" in
  3068. --format|-f)
  3069. return
  3070. ;;
  3071. esac
  3072. case "$cur" in
  3073. -*)
  3074. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  3075. ;;
  3076. *)
  3077. __docker_complete_nodes --add self
  3078. esac
  3079. }
  3080. _docker_node_list() {
  3081. _docker_node_ls
  3082. }
  3083. _docker_node_ls() {
  3084. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3085. case "$key" in
  3086. id)
  3087. __docker_complete_nodes --cur "${cur##*=}" --id
  3088. return
  3089. ;;
  3090. membership)
  3091. COMPREPLY=( $( compgen -W "accepted pending" -- "${cur##*=}" ) )
  3092. return
  3093. ;;
  3094. name)
  3095. __docker_complete_nodes --cur "${cur##*=}" --name
  3096. return
  3097. ;;
  3098. role)
  3099. COMPREPLY=( $( compgen -W "manager worker" -- "${cur##*=}" ) )
  3100. return
  3101. ;;
  3102. esac
  3103. case "$prev" in
  3104. --filter|-f)
  3105. COMPREPLY=( $( compgen -W "id label membership name role" -S = -- "$cur" ) )
  3106. __docker_nospace
  3107. return
  3108. ;;
  3109. esac
  3110. case "$cur" in
  3111. -*)
  3112. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  3113. ;;
  3114. esac
  3115. }
  3116. _docker_node_promote() {
  3117. case "$cur" in
  3118. -*)
  3119. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3120. ;;
  3121. *)
  3122. __docker_complete_nodes --filter role=worker
  3123. esac
  3124. }
  3125. _docker_node_remove() {
  3126. _docker_node_rm
  3127. }
  3128. _docker_node_rm() {
  3129. case "$cur" in
  3130. -*)
  3131. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3132. ;;
  3133. *)
  3134. __docker_complete_nodes
  3135. esac
  3136. }
  3137. _docker_node_ps() {
  3138. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3139. case "$key" in
  3140. desired-state)
  3141. COMPREPLY=( $( compgen -W "accepted running shutdown" -- "${cur##*=}" ) )
  3142. return
  3143. ;;
  3144. name)
  3145. __docker_complete_services --cur "${cur##*=}" --name
  3146. return
  3147. ;;
  3148. esac
  3149. case "$prev" in
  3150. --filter|-f)
  3151. COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) )
  3152. __docker_nospace
  3153. return
  3154. ;;
  3155. esac
  3156. case "$cur" in
  3157. -*)
  3158. COMPREPLY=( $( compgen -W "--filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  3159. ;;
  3160. *)
  3161. __docker_complete_nodes --add self
  3162. ;;
  3163. esac
  3164. }
  3165. _docker_node_update() {
  3166. case "$prev" in
  3167. --availability)
  3168. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  3169. return
  3170. ;;
  3171. --role)
  3172. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  3173. return
  3174. ;;
  3175. --label-add|--label-rm)
  3176. return
  3177. ;;
  3178. esac
  3179. case "$cur" in
  3180. -*)
  3181. COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) )
  3182. ;;
  3183. *)
  3184. __docker_complete_nodes
  3185. esac
  3186. }
  3187. _docker_pause() {
  3188. _docker_container_pause
  3189. }
  3190. _docker_plugin() {
  3191. local subcommands="
  3192. create
  3193. disable
  3194. enable
  3195. inspect
  3196. install
  3197. ls
  3198. push
  3199. rm
  3200. set
  3201. upgrade
  3202. "
  3203. local aliases="
  3204. list
  3205. remove
  3206. "
  3207. __docker_subcommands "$subcommands $aliases" && return
  3208. case "$cur" in
  3209. -*)
  3210. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3211. ;;
  3212. *)
  3213. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3214. ;;
  3215. esac
  3216. }
  3217. _docker_plugin_create() {
  3218. case "$cur" in
  3219. -*)
  3220. COMPREPLY=( $( compgen -W "--compress --help" -- "$cur" ) )
  3221. ;;
  3222. *)
  3223. local counter=$(__docker_pos_first_nonflag)
  3224. if [ $cword -eq $counter ]; then
  3225. # reponame
  3226. return
  3227. elif [ $cword -eq $((counter + 1)) ]; then
  3228. _filedir -d
  3229. fi
  3230. ;;
  3231. esac
  3232. }
  3233. _docker_plugin_disable() {
  3234. case "$cur" in
  3235. -*)
  3236. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3237. ;;
  3238. *)
  3239. local counter=$(__docker_pos_first_nonflag)
  3240. if [ $cword -eq $counter ]; then
  3241. __docker_complete_plugins_installed --filter enabled=true
  3242. fi
  3243. ;;
  3244. esac
  3245. }
  3246. _docker_plugin_enable() {
  3247. case "$prev" in
  3248. --timeout)
  3249. return
  3250. ;;
  3251. esac
  3252. case "$cur" in
  3253. -*)
  3254. COMPREPLY=( $( compgen -W "--help --timeout" -- "$cur" ) )
  3255. ;;
  3256. *)
  3257. local counter=$(__docker_pos_first_nonflag '--timeout')
  3258. if [ $cword -eq $counter ]; then
  3259. __docker_complete_plugins_installed --filter enabled=false
  3260. fi
  3261. ;;
  3262. esac
  3263. }
  3264. _docker_plugin_inspect() {
  3265. case "$prev" in
  3266. --format|f)
  3267. return
  3268. ;;
  3269. esac
  3270. case "$cur" in
  3271. -*)
  3272. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3273. ;;
  3274. *)
  3275. __docker_complete_plugins_installed
  3276. ;;
  3277. esac
  3278. }
  3279. _docker_plugin_install() {
  3280. case "$prev" in
  3281. --alias)
  3282. return
  3283. ;;
  3284. esac
  3285. case "$cur" in
  3286. -*)
  3287. COMPREPLY=( $( compgen -W "--alias --disable --disable-content-trust=false --grant-all-permissions --help" -- "$cur" ) )
  3288. ;;
  3289. esac
  3290. }
  3291. _docker_plugin_list() {
  3292. _docker_plugin_ls
  3293. }
  3294. _docker_plugin_ls() {
  3295. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3296. case "$key" in
  3297. capability)
  3298. COMPREPLY=( $( compgen -W "authz ipamdriver networkdriver volumedriver" -- "${cur##*=}" ) )
  3299. return
  3300. ;;
  3301. enabled)
  3302. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  3303. return
  3304. ;;
  3305. esac
  3306. case "$prev" in
  3307. --filter|-f)
  3308. COMPREPLY=( $( compgen -S = -W "capability enabled" -- "$cur" ) )
  3309. __docker_nospace
  3310. return
  3311. ;;
  3312. --format)
  3313. return
  3314. ;;
  3315. esac
  3316. case "$cur" in
  3317. -*)
  3318. COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  3319. ;;
  3320. esac
  3321. }
  3322. _docker_plugin_push() {
  3323. case "$cur" in
  3324. -*)
  3325. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3326. ;;
  3327. *)
  3328. local counter=$(__docker_pos_first_nonflag)
  3329. if [ $cword -eq $counter ]; then
  3330. __docker_complete_plugins_installed
  3331. fi
  3332. ;;
  3333. esac
  3334. }
  3335. _docker_plugin_remove() {
  3336. _docker_plugin_rm
  3337. }
  3338. _docker_plugin_rm() {
  3339. case "$cur" in
  3340. -*)
  3341. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3342. ;;
  3343. *)
  3344. __docker_complete_plugins_installed
  3345. ;;
  3346. esac
  3347. }
  3348. _docker_plugin_set() {
  3349. case "$cur" in
  3350. -*)
  3351. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3352. ;;
  3353. *)
  3354. local counter=$(__docker_pos_first_nonflag)
  3355. if [ $cword -eq $counter ]; then
  3356. __docker_complete_plugins_installed
  3357. fi
  3358. ;;
  3359. esac
  3360. }
  3361. _docker_plugin_upgrade() {
  3362. case "$cur" in
  3363. -*)
  3364. COMPREPLY=( $( compgen -W "--disable-content-trust --grant-all-permissions --help --skip-remote-check" -- "$cur" ) )
  3365. ;;
  3366. *)
  3367. local counter=$(__docker_pos_first_nonflag)
  3368. if [ $cword -eq $counter ]; then
  3369. __docker_complete_plugins_installed
  3370. __ltrim_colon_completions "$cur"
  3371. elif [ $cword -eq $((counter + 1)) ]; then
  3372. local plugin_images="$(__docker_plugins_installed)"
  3373. COMPREPLY=( $(compgen -S : -W "${plugin_images%:*}" -- "$cur") )
  3374. __docker_nospace
  3375. fi
  3376. ;;
  3377. esac
  3378. }
  3379. _docker_port() {
  3380. _docker_container_port
  3381. }
  3382. _docker_ps() {
  3383. _docker_container_ls
  3384. }
  3385. _docker_pull() {
  3386. _docker_image_pull
  3387. }
  3388. _docker_push() {
  3389. _docker_image_push
  3390. }
  3391. _docker_rename() {
  3392. _docker_container_rename
  3393. }
  3394. _docker_restart() {
  3395. _docker_container_restart
  3396. }
  3397. _docker_rm() {
  3398. _docker_container_rm
  3399. }
  3400. _docker_rmi() {
  3401. _docker_image_rm
  3402. }
  3403. _docker_run() {
  3404. _docker_container_run
  3405. }
  3406. _docker_save() {
  3407. _docker_image_save
  3408. }
  3409. _docker_secret() {
  3410. local subcommands="
  3411. create
  3412. inspect
  3413. ls
  3414. rm
  3415. "
  3416. local aliases="
  3417. list
  3418. remove
  3419. "
  3420. __docker_subcommands "$subcommands $aliases" && return
  3421. case "$cur" in
  3422. -*)
  3423. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3424. ;;
  3425. *)
  3426. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3427. ;;
  3428. esac
  3429. }
  3430. _docker_secret_create() {
  3431. case "$prev" in
  3432. --label|-l)
  3433. return
  3434. ;;
  3435. esac
  3436. case "$cur" in
  3437. -*)
  3438. COMPREPLY=( $( compgen -W "--help --label -l" -- "$cur" ) )
  3439. ;;
  3440. esac
  3441. }
  3442. _docker_secret_inspect() {
  3443. case "$prev" in
  3444. --format|-f)
  3445. return
  3446. ;;
  3447. esac
  3448. case "$cur" in
  3449. -*)
  3450. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3451. ;;
  3452. *)
  3453. __docker_complete_secrets
  3454. ;;
  3455. esac
  3456. }
  3457. _docker_secret_list() {
  3458. _docker_secret_ls
  3459. }
  3460. _docker_secret_ls() {
  3461. case "$cur" in
  3462. -*)
  3463. COMPREPLY=( $( compgen -W "--help --quiet -q" -- "$cur" ) )
  3464. ;;
  3465. esac
  3466. }
  3467. _docker_secret_remove() {
  3468. case "$cur" in
  3469. -*)
  3470. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3471. ;;
  3472. *)
  3473. __docker_complete_secrets
  3474. ;;
  3475. esac
  3476. }
  3477. _docker_secret_rm() {
  3478. _docker_secret_remove
  3479. }
  3480. _docker_search() {
  3481. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3482. case "$key" in
  3483. is-automated)
  3484. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  3485. return
  3486. ;;
  3487. is-official)
  3488. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  3489. return
  3490. ;;
  3491. esac
  3492. case "$prev" in
  3493. --filter|-f)
  3494. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  3495. __docker_nospace
  3496. return
  3497. ;;
  3498. --limit)
  3499. return
  3500. ;;
  3501. esac
  3502. case "$cur" in
  3503. -*)
  3504. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  3505. ;;
  3506. esac
  3507. }
  3508. _docker_stack() {
  3509. local subcommands="
  3510. deploy
  3511. ls
  3512. ps
  3513. rm
  3514. services
  3515. "
  3516. local aliases="
  3517. down
  3518. list
  3519. remove
  3520. up
  3521. "
  3522. __docker_subcommands "$subcommands $aliases" && return
  3523. case "$cur" in
  3524. -*)
  3525. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3526. ;;
  3527. *)
  3528. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3529. ;;
  3530. esac
  3531. }
  3532. _docker_stack_deploy() {
  3533. case "$prev" in
  3534. --bundle-file)
  3535. if __docker_daemon_is_experimental ; then
  3536. _filedir dab
  3537. return
  3538. fi
  3539. ;;
  3540. --compose-file|-c)
  3541. _filedir yml
  3542. return
  3543. ;;
  3544. esac
  3545. case "$cur" in
  3546. -*)
  3547. local options="--compose-file -c --help --with-registry-auth"
  3548. __docker_daemon_is_experimental && options+=" --bundle-file"
  3549. COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
  3550. ;;
  3551. esac
  3552. }
  3553. _docker_stack_down() {
  3554. _docker_stack_rm
  3555. }
  3556. _docker_stack_list() {
  3557. _docker_stack_ls
  3558. }
  3559. _docker_stack_ls() {
  3560. case "$cur" in
  3561. -*)
  3562. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3563. ;;
  3564. esac
  3565. }
  3566. _docker_stack_ps() {
  3567. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3568. case "$key" in
  3569. desired-state)
  3570. COMPREPLY=( $( compgen -W "accepted running shutdown" -- "${cur##*=}" ) )
  3571. return
  3572. ;;
  3573. id)
  3574. __docker_complete_stacks --cur "${cur##*=}" --id
  3575. return
  3576. ;;
  3577. name)
  3578. __docker_complete_stacks --cur "${cur##*=}" --name
  3579. return
  3580. ;;
  3581. esac
  3582. case "$prev" in
  3583. --filter|-f)
  3584. COMPREPLY=( $( compgen -S = -W "id name desired-state" -- "$cur" ) )
  3585. __docker_nospace
  3586. return
  3587. ;;
  3588. esac
  3589. case "$cur" in
  3590. -*)
  3591. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  3592. ;;
  3593. *)
  3594. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  3595. if [ $cword -eq $counter ]; then
  3596. __docker_complete_stacks
  3597. fi
  3598. ;;
  3599. esac
  3600. }
  3601. _docker_stack_remove() {
  3602. _docker_stack_rm
  3603. }
  3604. _docker_stack_rm() {
  3605. case "$cur" in
  3606. -*)
  3607. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3608. ;;
  3609. *)
  3610. local counter=$(__docker_pos_first_nonflag)
  3611. if [ $cword -eq $counter ]; then
  3612. __docker_complete_stacks
  3613. fi
  3614. ;;
  3615. esac
  3616. }
  3617. _docker_stack_services() {
  3618. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3619. case "$key" in
  3620. id)
  3621. __docker_complete_services --cur "${cur##*=}" --id
  3622. return
  3623. ;;
  3624. label)
  3625. return
  3626. ;;
  3627. name)
  3628. __docker_complete_services --cur "${cur##*=}" --name
  3629. return
  3630. ;;
  3631. esac
  3632. case "$prev" in
  3633. --filter|-f)
  3634. COMPREPLY=( $( compgen -S = -W "id label name" -- "$cur" ) )
  3635. __docker_nospace
  3636. return
  3637. ;;
  3638. --format)
  3639. return
  3640. ;;
  3641. esac
  3642. case "$cur" in
  3643. -*)
  3644. COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
  3645. ;;
  3646. *)
  3647. local counter=$(__docker_pos_first_nonflag '--filter|-f|--format')
  3648. if [ $cword -eq $counter ]; then
  3649. __docker_complete_stacks
  3650. fi
  3651. ;;
  3652. esac
  3653. }
  3654. _docker_stack_up() {
  3655. _docker_stack_deploy
  3656. }
  3657. _docker_start() {
  3658. _docker_container_start
  3659. }
  3660. _docker_stats() {
  3661. _docker_container_stats
  3662. }
  3663. _docker_stop() {
  3664. _docker_container_stop
  3665. }
  3666. _docker_system() {
  3667. local subcommands="
  3668. df
  3669. events
  3670. info
  3671. prune
  3672. "
  3673. __docker_subcommands "$subcommands $aliases" && return
  3674. case "$cur" in
  3675. -*)
  3676. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3677. ;;
  3678. *)
  3679. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3680. ;;
  3681. esac
  3682. }
  3683. _docker_system_df() {
  3684. case "$cur" in
  3685. -*)
  3686. COMPREPLY=( $( compgen -W "--help --verbose -v" -- "$cur" ) )
  3687. ;;
  3688. esac
  3689. }
  3690. _docker_system_events() {
  3691. local key=$(__docker_map_key_of_current_option '-f|--filter')
  3692. case "$key" in
  3693. container)
  3694. __docker_complete_containers_all --cur "${cur##*=}"
  3695. return
  3696. ;;
  3697. daemon)
  3698. local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
  3699. COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
  3700. return
  3701. ;;
  3702. event)
  3703. COMPREPLY=( $( compgen -W "
  3704. attach
  3705. commit
  3706. connect
  3707. copy
  3708. create
  3709. delete
  3710. destroy
  3711. detach
  3712. die
  3713. disconnect
  3714. exec_create
  3715. exec_detach
  3716. exec_start
  3717. export
  3718. health_status
  3719. import
  3720. kill
  3721. load
  3722. mount
  3723. oom
  3724. pause
  3725. pull
  3726. push
  3727. reload
  3728. rename
  3729. resize
  3730. restart
  3731. save
  3732. start
  3733. stop
  3734. tag
  3735. top
  3736. unmount
  3737. unpause
  3738. untag
  3739. update
  3740. " -- "${cur##*=}" ) )
  3741. return
  3742. ;;
  3743. image)
  3744. cur="${cur##*=}"
  3745. __docker_complete_images
  3746. return
  3747. ;;
  3748. network)
  3749. __docker_complete_networks --cur "${cur##*=}"
  3750. return
  3751. ;;
  3752. type)
  3753. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  3754. return
  3755. ;;
  3756. volume)
  3757. __docker_complete_volumes --cur "${cur##*=}"
  3758. return
  3759. ;;
  3760. esac
  3761. case "$prev" in
  3762. --filter|-f)
  3763. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  3764. __docker_nospace
  3765. return
  3766. ;;
  3767. --since|--until)
  3768. return
  3769. ;;
  3770. esac
  3771. case "$cur" in
  3772. -*)
  3773. COMPREPLY=( $( compgen -W "--filter -f --help --since --until --format" -- "$cur" ) )
  3774. ;;
  3775. esac
  3776. }
  3777. _docker_system_info() {
  3778. case "$prev" in
  3779. --format|-f)
  3780. return
  3781. ;;
  3782. esac
  3783. case "$cur" in
  3784. -*)
  3785. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3786. ;;
  3787. esac
  3788. }
  3789. _docker_system_prune() {
  3790. case "$prev" in
  3791. --filter)
  3792. COMPREPLY=( $( compgen -W "until" -S = -- "$cur" ) )
  3793. __docker_nospace
  3794. return
  3795. ;;
  3796. esac
  3797. case "$cur" in
  3798. -*)
  3799. COMPREPLY=( $( compgen -W "--all -a --force -f --filter --help" -- "$cur" ) )
  3800. ;;
  3801. esac
  3802. }
  3803. _docker_tag() {
  3804. _docker_image_tag
  3805. }
  3806. _docker_unpause() {
  3807. _docker_container_unpause
  3808. }
  3809. _docker_update() {
  3810. _docker_container_update
  3811. }
  3812. _docker_top() {
  3813. _docker_container_top
  3814. }
  3815. _docker_version() {
  3816. case "$prev" in
  3817. --format|-f)
  3818. return
  3819. ;;
  3820. esac
  3821. case "$cur" in
  3822. -*)
  3823. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3824. ;;
  3825. esac
  3826. }
  3827. _docker_volume_create() {
  3828. case "$prev" in
  3829. --driver|-d)
  3830. __docker_complete_plugins_bundled --type Volume
  3831. return
  3832. ;;
  3833. --label|--opt|-o)
  3834. return
  3835. ;;
  3836. esac
  3837. case "$cur" in
  3838. -*)
  3839. COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) )
  3840. ;;
  3841. esac
  3842. }
  3843. _docker_volume_inspect() {
  3844. case "$prev" in
  3845. --format|-f)
  3846. return
  3847. ;;
  3848. esac
  3849. case "$cur" in
  3850. -*)
  3851. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3852. ;;
  3853. *)
  3854. __docker_complete_volumes
  3855. ;;
  3856. esac
  3857. }
  3858. _docker_volume_list() {
  3859. _docker_volume_ls
  3860. }
  3861. _docker_volume_ls() {
  3862. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3863. case "$key" in
  3864. dangling)
  3865. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  3866. return
  3867. ;;
  3868. driver)
  3869. __docker_complete_plugins_bundled --cur "${cur##*=}" --type Volume
  3870. return
  3871. ;;
  3872. name)
  3873. __docker_complete_volumes --cur "${cur##*=}"
  3874. return
  3875. ;;
  3876. esac
  3877. case "$prev" in
  3878. --filter|-f)
  3879. COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) )
  3880. __docker_nospace
  3881. return
  3882. ;;
  3883. --format)
  3884. return
  3885. ;;
  3886. esac
  3887. case "$cur" in
  3888. -*)
  3889. COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
  3890. ;;
  3891. esac
  3892. }
  3893. _docker_volume_prune() {
  3894. case "$cur" in
  3895. -*)
  3896. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3897. ;;
  3898. esac
  3899. }
  3900. _docker_volume_remove() {
  3901. _docker_volume_rm
  3902. }
  3903. _docker_volume_rm() {
  3904. case "$cur" in
  3905. -*)
  3906. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3907. ;;
  3908. *)
  3909. __docker_complete_volumes
  3910. ;;
  3911. esac
  3912. }
  3913. _docker_volume() {
  3914. local subcommands="
  3915. create
  3916. inspect
  3917. ls
  3918. prune
  3919. rm
  3920. "
  3921. local aliases="
  3922. list
  3923. remove
  3924. "
  3925. __docker_subcommands "$subcommands $aliases" && return
  3926. case "$cur" in
  3927. -*)
  3928. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3929. ;;
  3930. *)
  3931. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3932. ;;
  3933. esac
  3934. }
  3935. _docker_wait() {
  3936. _docker_container_wait
  3937. }
  3938. _docker() {
  3939. local previous_extglob_setting=$(shopt -p extglob)
  3940. shopt -s extglob
  3941. local management_commands=(
  3942. container
  3943. image
  3944. network
  3945. node
  3946. plugin
  3947. secret
  3948. service
  3949. stack
  3950. system
  3951. volume
  3952. )
  3953. local top_level_commands=(
  3954. build
  3955. login
  3956. logout
  3957. run
  3958. search
  3959. version
  3960. )
  3961. local legacy_commands=(
  3962. commit
  3963. cp
  3964. create
  3965. diff
  3966. events
  3967. exec
  3968. export
  3969. history
  3970. images
  3971. import
  3972. info
  3973. inspect
  3974. kill
  3975. load
  3976. logs
  3977. pause
  3978. port
  3979. ps
  3980. pull
  3981. push
  3982. rename
  3983. restart
  3984. rm
  3985. rmi
  3986. save
  3987. start
  3988. stats
  3989. stop
  3990. swarm
  3991. tag
  3992. top
  3993. unpause
  3994. update
  3995. wait
  3996. )
  3997. local experimental_commands=(
  3998. checkpoint
  3999. deploy
  4000. )
  4001. local commands=(${management_commands[*]} ${top_level_commands[*]})
  4002. [ -z "$DOCKER_HIDE_LEGACY_COMMANDS" ] && commands+=(${legacy_commands[*]})
  4003. # These options are valid as global options for all client commands
  4004. # and valid as command options for `docker daemon`
  4005. local global_boolean_options="
  4006. --debug -D
  4007. --tls
  4008. --tlsverify
  4009. "
  4010. local global_options_with_args="
  4011. --config
  4012. --host -H
  4013. --log-level -l
  4014. --tlscacert
  4015. --tlscert
  4016. --tlskey
  4017. "
  4018. local host config daemon_os
  4019. COMPREPLY=()
  4020. local cur prev words cword
  4021. _get_comp_words_by_ref -n : cur prev words cword
  4022. local command='docker' command_pos=0 subcommand_pos
  4023. local counter=1
  4024. while [ $counter -lt $cword ]; do
  4025. case "${words[$counter]}" in
  4026. # save host so that completion can use custom daemon
  4027. --host|-H)
  4028. (( counter++ ))
  4029. host="${words[$counter]}"
  4030. ;;
  4031. # save config so that completion can use custom configuration directories
  4032. --config)
  4033. (( counter++ ))
  4034. config="${words[$counter]}"
  4035. ;;
  4036. $(__docker_to_extglob "$global_options_with_args") )
  4037. (( counter++ ))
  4038. ;;
  4039. -*)
  4040. ;;
  4041. =)
  4042. (( counter++ ))
  4043. ;;
  4044. *)
  4045. command="${words[$counter]}"
  4046. command_pos=$counter
  4047. break
  4048. ;;
  4049. esac
  4050. (( counter++ ))
  4051. done
  4052. local binary="${words[0]}"
  4053. if [[ $binary == ?(*/)dockerd ]] ; then
  4054. # for the dockerd binary, we reuse completion of `docker daemon`.
  4055. # dockerd does not have subcommands and global options.
  4056. command=daemon
  4057. command_pos=0
  4058. fi
  4059. local completions_func=_docker_${command//-/_}
  4060. declare -F $completions_func >/dev/null && $completions_func
  4061. eval "$previous_extglob_setting"
  4062. return 0
  4063. }
  4064. eval "$__docker_previous_extglob_setting"
  4065. unset __docker_previous_extglob_setting
  4066. complete -F _docker docker docker.exe dockerd dockerd.exe