docker 86 KB

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