docker 78 KB

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