docker 86 KB

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