docker 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073
  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 | sed -n "/^Plugins/,/^[^ ]/s/ $type: //p"))
  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 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_services)
  2117. $(__docker_volumes)
  2118. " -- "$cur" ) )
  2119. ;;
  2120. container)
  2121. __docker_complete_containers_all
  2122. ;;
  2123. image)
  2124. __docker_complete_images
  2125. ;;
  2126. network)
  2127. __docker_complete_networks
  2128. ;;
  2129. node)
  2130. __docker_complete_nodes
  2131. ;;
  2132. service)
  2133. __docker_complete_services
  2134. ;;
  2135. volume)
  2136. __docker_complete_volumes
  2137. ;;
  2138. esac
  2139. esac
  2140. }
  2141. _docker_kill() {
  2142. _docker_container_kill
  2143. }
  2144. _docker_load() {
  2145. _docker_image_load
  2146. }
  2147. _docker_login() {
  2148. case "$prev" in
  2149. --password|-p|--username|-u)
  2150. return
  2151. ;;
  2152. esac
  2153. case "$cur" in
  2154. -*)
  2155. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  2156. ;;
  2157. esac
  2158. }
  2159. _docker_logout() {
  2160. case "$cur" in
  2161. -*)
  2162. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2163. ;;
  2164. esac
  2165. }
  2166. _docker_logs() {
  2167. _docker_container_logs
  2168. }
  2169. _docker_network_connect() {
  2170. local options_with_args="
  2171. --alias
  2172. --ip
  2173. --ip6
  2174. --link
  2175. --link-local-ip
  2176. "
  2177. local boolean_options="
  2178. --help
  2179. "
  2180. case "$prev" in
  2181. --link)
  2182. case "$cur" in
  2183. *:*)
  2184. ;;
  2185. *)
  2186. __docker_complete_containers_running
  2187. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  2188. __docker_nospace
  2189. ;;
  2190. esac
  2191. return
  2192. ;;
  2193. $(__docker_to_extglob "$options_with_args") )
  2194. return
  2195. ;;
  2196. esac
  2197. case "$cur" in
  2198. -*)
  2199. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  2200. ;;
  2201. *)
  2202. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2203. if [ $cword -eq $counter ]; then
  2204. __docker_complete_networks
  2205. elif [ $cword -eq $(($counter + 1)) ]; then
  2206. __docker_complete_containers_all
  2207. fi
  2208. ;;
  2209. esac
  2210. }
  2211. _docker_network_create() {
  2212. case "$prev" in
  2213. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  2214. return
  2215. ;;
  2216. --ipam-driver)
  2217. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  2218. return
  2219. ;;
  2220. --driver|-d)
  2221. # remove drivers that allow one instance only, add drivers missing in `docker info`
  2222. __docker_complete_plugins_bundled --type Network --remove host --remove null --add macvlan
  2223. return
  2224. ;;
  2225. --label)
  2226. return
  2227. ;;
  2228. esac
  2229. case "$cur" in
  2230. -*)
  2231. COMPREPLY=( $( compgen -W "--attachable --aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  2232. ;;
  2233. esac
  2234. }
  2235. _docker_network_disconnect() {
  2236. case "$cur" in
  2237. -*)
  2238. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2239. ;;
  2240. *)
  2241. local counter=$(__docker_pos_first_nonflag)
  2242. if [ $cword -eq $counter ]; then
  2243. __docker_complete_networks
  2244. elif [ $cword -eq $(($counter + 1)) ]; then
  2245. __docker_complete_containers_in_network "$prev"
  2246. fi
  2247. ;;
  2248. esac
  2249. }
  2250. _docker_network_inspect() {
  2251. case "$prev" in
  2252. --format|-f)
  2253. return
  2254. ;;
  2255. esac
  2256. case "$cur" in
  2257. -*)
  2258. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2259. ;;
  2260. *)
  2261. __docker_complete_networks
  2262. esac
  2263. }
  2264. _docker_network_ls() {
  2265. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2266. case "$key" in
  2267. driver)
  2268. __docker_complete_plugins_bundled --cur "${cur##*=}" --type Network --add macvlan
  2269. return
  2270. ;;
  2271. id)
  2272. __docker_complete_networks --cur "${cur##*=}" --id
  2273. return
  2274. ;;
  2275. name)
  2276. __docker_complete_networks --cur "${cur##*=}" --name
  2277. return
  2278. ;;
  2279. type)
  2280. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  2281. return
  2282. ;;
  2283. esac
  2284. case "$prev" in
  2285. --filter|-f)
  2286. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  2287. __docker_nospace
  2288. return
  2289. ;;
  2290. --format)
  2291. return
  2292. ;;
  2293. esac
  2294. case "$cur" in
  2295. -*)
  2296. COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  2297. ;;
  2298. esac
  2299. }
  2300. _docker_network_prune() {
  2301. case "$cur" in
  2302. -*)
  2303. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2304. ;;
  2305. esac
  2306. }
  2307. _docker_network_rm() {
  2308. case "$cur" in
  2309. -*)
  2310. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2311. ;;
  2312. *)
  2313. __docker_complete_networks --filter type=custom
  2314. esac
  2315. }
  2316. _docker_network() {
  2317. local subcommands="
  2318. connect
  2319. create
  2320. disconnect
  2321. inspect
  2322. ls
  2323. prune
  2324. rm
  2325. "
  2326. __docker_subcommands "$subcommands" && return
  2327. case "$cur" in
  2328. -*)
  2329. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2330. ;;
  2331. *)
  2332. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2333. ;;
  2334. esac
  2335. }
  2336. _docker_service() {
  2337. local subcommands="
  2338. create
  2339. inspect
  2340. ls list
  2341. rm remove
  2342. scale
  2343. ps
  2344. update
  2345. "
  2346. __docker_subcommands "$subcommands" && return
  2347. case "$cur" in
  2348. -*)
  2349. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2350. ;;
  2351. *)
  2352. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2353. ;;
  2354. esac
  2355. }
  2356. _docker_service_create() {
  2357. _docker_service_update
  2358. }
  2359. _docker_service_inspect() {
  2360. case "$prev" in
  2361. --format|-f)
  2362. return
  2363. ;;
  2364. esac
  2365. case "$cur" in
  2366. -*)
  2367. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  2368. ;;
  2369. *)
  2370. __docker_complete_services
  2371. esac
  2372. }
  2373. _docker_service_list() {
  2374. _docker_service_ls
  2375. }
  2376. _docker_service_ls() {
  2377. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2378. case "$key" in
  2379. id)
  2380. __docker_complete_services --cur "${cur##*=}" --id
  2381. return
  2382. ;;
  2383. name)
  2384. __docker_complete_services --cur "${cur##*=}" --name
  2385. return
  2386. ;;
  2387. esac
  2388. case "$prev" in
  2389. --filter|-f)
  2390. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  2391. __docker_nospace
  2392. return
  2393. ;;
  2394. esac
  2395. case "$cur" in
  2396. -*)
  2397. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  2398. ;;
  2399. esac
  2400. }
  2401. _docker_service_remove() {
  2402. _docker_service_rm
  2403. }
  2404. _docker_service_rm() {
  2405. case "$cur" in
  2406. -*)
  2407. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2408. ;;
  2409. *)
  2410. __docker_complete_services
  2411. esac
  2412. }
  2413. _docker_service_scale() {
  2414. case "$cur" in
  2415. -*)
  2416. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2417. ;;
  2418. *)
  2419. __docker_complete_services
  2420. __docker_append_to_completions "="
  2421. __docker_nospace
  2422. ;;
  2423. esac
  2424. }
  2425. _docker_service_ps() {
  2426. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2427. case "$key" in
  2428. desired-state)
  2429. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  2430. return
  2431. ;;
  2432. name)
  2433. __docker_complete_services --cur "${cur##*=}" --name
  2434. return
  2435. ;;
  2436. esac
  2437. case "$prev" in
  2438. --filter|-f)
  2439. COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) )
  2440. __docker_nospace
  2441. return
  2442. ;;
  2443. esac
  2444. case "$cur" in
  2445. -*)
  2446. COMPREPLY=( $( compgen -W "--filter -f --help --no-resolve --no-trunc --quiet -q" -- "$cur" ) )
  2447. ;;
  2448. *)
  2449. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  2450. if [ $cword -eq $counter ]; then
  2451. __docker_complete_services
  2452. fi
  2453. ;;
  2454. esac
  2455. }
  2456. _docker_service_update() {
  2457. local $subcommand="${words[$subcommand_pos]}"
  2458. local options_with_args="
  2459. --constraint
  2460. --endpoint-mode
  2461. --env -e
  2462. --force
  2463. --health-cmd
  2464. --health-interval
  2465. --health-retries
  2466. --health-timeout
  2467. --hostname
  2468. --label -l
  2469. --limit-cpu
  2470. --limit-memory
  2471. --log-driver
  2472. --log-opt
  2473. --mount
  2474. --network
  2475. --no-healthcheck
  2476. --publish -p
  2477. --replicas
  2478. --reserve-cpu
  2479. --reserve-memory
  2480. --restart-condition
  2481. --restart-delay
  2482. --restart-max-attempts
  2483. --restart-window
  2484. --rollback
  2485. --stop-grace-period
  2486. --update-delay
  2487. --update-failure-action
  2488. --update-max-failure-ratio
  2489. --update-monitor
  2490. --update-parallelism
  2491. --user -u
  2492. --workdir -w
  2493. "
  2494. local boolean_options="
  2495. --help
  2496. --tty -t
  2497. --with-registry-auth
  2498. "
  2499. __docker_complete_log_driver_options && return
  2500. if [ "$subcommand" = "create" ] ; then
  2501. options_with_args="$options_with_args
  2502. --container-label
  2503. --dns
  2504. --dns-option
  2505. --dns-search
  2506. --env-file
  2507. --group
  2508. --host
  2509. --mode
  2510. --name
  2511. --port
  2512. --secret
  2513. "
  2514. case "$prev" in
  2515. --env-file)
  2516. _filedir
  2517. return
  2518. ;;
  2519. --host)
  2520. case "$cur" in
  2521. *:)
  2522. __docker_complete_resolved_hostname
  2523. return
  2524. ;;
  2525. esac
  2526. ;;
  2527. --mode)
  2528. COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) )
  2529. return
  2530. ;;
  2531. --secret)
  2532. __docker_complete_secrets
  2533. return
  2534. ;;
  2535. --group)
  2536. COMPREPLY=( $(compgen -g -- "$cur") )
  2537. return
  2538. ;;
  2539. esac
  2540. fi
  2541. if [ "$subcommand" = "update" ] ; then
  2542. options_with_args="$options_with_args
  2543. --arg
  2544. --container-label-add
  2545. --container-label-rm
  2546. --dns-add
  2547. --dns-option-add
  2548. --dns-option-rm
  2549. --dns-rm
  2550. --dns-search-add
  2551. --dns-search-rm
  2552. --group-add
  2553. --group-rm
  2554. --host-add
  2555. --host-rm
  2556. --image
  2557. --port-add
  2558. --port-rm
  2559. --secret-add
  2560. --secret-rm
  2561. "
  2562. case "$prev" in
  2563. --group-add)
  2564. COMPREPLY=( $(compgen -g -- "$cur") )
  2565. return
  2566. ;;
  2567. --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 "--all -a --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 "$cur" in
  2981. -*)
  2982. COMPREPLY=( $( compgen -W "--disable --grant-all-permissions--help" -- "$cur" ) )
  2983. ;;
  2984. esac
  2985. }
  2986. _docker_plugin_list() {
  2987. _docker_plugin_ls
  2988. }
  2989. _docker_plugin_ls() {
  2990. case "$cur" in
  2991. -*)
  2992. COMPREPLY=( $( compgen -W "--help --no-trunc" -- "$cur" ) )
  2993. ;;
  2994. esac
  2995. }
  2996. _docker_plugin_push() {
  2997. case "$cur" in
  2998. -*)
  2999. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3000. ;;
  3001. *)
  3002. local counter=$(__docker_pos_first_nonflag)
  3003. if [ $cword -eq $counter ]; then
  3004. __docker_complete_plugins_installed
  3005. fi
  3006. ;;
  3007. esac
  3008. }
  3009. _docker_plugin_remove() {
  3010. _docker_plugin_rm
  3011. }
  3012. _docker_plugin_rm() {
  3013. case "$cur" in
  3014. -*)
  3015. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3016. ;;
  3017. *)
  3018. __docker_complete_plugins_installed
  3019. ;;
  3020. esac
  3021. }
  3022. _docker_plugin_set() {
  3023. case "$cur" in
  3024. -*)
  3025. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3026. ;;
  3027. *)
  3028. local counter=$(__docker_pos_first_nonflag)
  3029. if [ $cword -eq $counter ]; then
  3030. __docker_complete_plugins_installed
  3031. fi
  3032. ;;
  3033. esac
  3034. }
  3035. _docker_port() {
  3036. _docker_container_port
  3037. }
  3038. _docker_ps() {
  3039. _docker_container_ls
  3040. }
  3041. _docker_pull() {
  3042. _docker_image_pull
  3043. }
  3044. _docker_push() {
  3045. _docker_image_push
  3046. }
  3047. _docker_rename() {
  3048. _docker_container_rename
  3049. }
  3050. _docker_restart() {
  3051. _docker_container_restart
  3052. }
  3053. _docker_rm() {
  3054. _docker_container_rm
  3055. }
  3056. _docker_rmi() {
  3057. _docker_image_rm
  3058. }
  3059. _docker_run() {
  3060. _docker_container_run
  3061. }
  3062. _docker_save() {
  3063. _docker_image_save
  3064. }
  3065. _docker_secret() {
  3066. local subcommands="
  3067. create
  3068. inspect
  3069. ls
  3070. rm
  3071. "
  3072. local aliases="
  3073. list
  3074. remove
  3075. "
  3076. __docker_subcommands "$subcommands $aliases" && return
  3077. case "$cur" in
  3078. -*)
  3079. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3080. ;;
  3081. *)
  3082. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3083. ;;
  3084. esac
  3085. }
  3086. _docker_secret_create() {
  3087. case "$prev" in
  3088. --label|-l)
  3089. return
  3090. ;;
  3091. esac
  3092. case "$cur" in
  3093. -*)
  3094. COMPREPLY=( $( compgen -W "--help --label -l" -- "$cur" ) )
  3095. ;;
  3096. esac
  3097. }
  3098. _docker_secret_inspect() {
  3099. case "$prev" in
  3100. --format|-f)
  3101. return
  3102. ;;
  3103. esac
  3104. case "$cur" in
  3105. -*)
  3106. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3107. ;;
  3108. *)
  3109. __docker_complete_secrets
  3110. ;;
  3111. esac
  3112. }
  3113. _docker_secret_list() {
  3114. _docker_secret_ls
  3115. }
  3116. _docker_secret_ls() {
  3117. case "$cur" in
  3118. -*)
  3119. COMPREPLY=( $( compgen -W "--help --quiet -q" -- "$cur" ) )
  3120. ;;
  3121. esac
  3122. }
  3123. _docker_secret_remove() {
  3124. case "$cur" in
  3125. -*)
  3126. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3127. ;;
  3128. *)
  3129. __docker_complete_secrets
  3130. ;;
  3131. esac
  3132. }
  3133. _docker_secret_rm() {
  3134. _docker_secret_remove
  3135. }
  3136. _docker_search() {
  3137. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3138. case "$key" in
  3139. is-automated)
  3140. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  3141. return
  3142. ;;
  3143. is-official)
  3144. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  3145. return
  3146. ;;
  3147. esac
  3148. case "$prev" in
  3149. --filter|-f)
  3150. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  3151. __docker_nospace
  3152. return
  3153. ;;
  3154. --limit)
  3155. return
  3156. ;;
  3157. esac
  3158. case "$cur" in
  3159. -*)
  3160. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  3161. ;;
  3162. esac
  3163. }
  3164. _docker_stack() {
  3165. local subcommands="
  3166. deploy
  3167. ls
  3168. ps
  3169. rm
  3170. services
  3171. "
  3172. local aliases="
  3173. down
  3174. list
  3175. remove
  3176. up
  3177. "
  3178. __docker_subcommands "$subcommands $aliases" && return
  3179. case "$cur" in
  3180. -*)
  3181. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3182. ;;
  3183. *)
  3184. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3185. ;;
  3186. esac
  3187. }
  3188. _docker_stack_deploy() {
  3189. case "$prev" in
  3190. --bundle-file)
  3191. _filedir dab
  3192. return
  3193. ;;
  3194. --compose-file|-c)
  3195. _filedir yml
  3196. return
  3197. ;;
  3198. esac
  3199. case "$cur" in
  3200. -*)
  3201. COMPREPLY=( $( compgen -W "--bundle-file --compose-file -c --help --with-registry-auth" -- "$cur" ) )
  3202. ;;
  3203. esac
  3204. }
  3205. _docker_stack_down() {
  3206. _docker_stack_rm
  3207. }
  3208. _docker_stack_list() {
  3209. _docker_stack_ls
  3210. }
  3211. _docker_stack_ls() {
  3212. case "$cur" in
  3213. -*)
  3214. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3215. ;;
  3216. esac
  3217. }
  3218. _docker_stack_ps() {
  3219. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3220. case "$key" in
  3221. desired-state)
  3222. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  3223. return
  3224. ;;
  3225. id)
  3226. __docker_complete_stacks --cur "${cur##*=}" --id
  3227. return
  3228. ;;
  3229. name)
  3230. __docker_complete_stacks --cur "${cur##*=}" --name
  3231. return
  3232. ;;
  3233. esac
  3234. case "$prev" in
  3235. --filter|-f)
  3236. COMPREPLY=( $( compgen -S = -W "id name desired-state" -- "$cur" ) )
  3237. __docker_nospace
  3238. return
  3239. ;;
  3240. esac
  3241. case "$cur" in
  3242. -*)
  3243. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  3244. ;;
  3245. *)
  3246. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  3247. if [ $cword -eq $counter ]; then
  3248. __docker_complete_stacks
  3249. fi
  3250. ;;
  3251. esac
  3252. }
  3253. _docker_stack_remove() {
  3254. _docker_stack_rm
  3255. }
  3256. _docker_stack_rm() {
  3257. case "$cur" in
  3258. -*)
  3259. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3260. ;;
  3261. *)
  3262. local counter=$(__docker_pos_first_nonflag)
  3263. if [ $cword -eq $counter ]; then
  3264. __docker_complete_stacks
  3265. fi
  3266. ;;
  3267. esac
  3268. }
  3269. _docker_stack_services() {
  3270. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3271. case "$key" in
  3272. id)
  3273. __docker_complete_services --cur "${cur##*=}" --id
  3274. return
  3275. ;;
  3276. label)
  3277. return
  3278. ;;
  3279. name)
  3280. __docker_complete_services --cur "${cur##*=}" --name
  3281. return
  3282. ;;
  3283. esac
  3284. case "$prev" in
  3285. --filter|-f)
  3286. COMPREPLY=( $( compgen -S = -W "id label name" -- "$cur" ) )
  3287. __docker_nospace
  3288. return
  3289. ;;
  3290. esac
  3291. case "$cur" in
  3292. -*)
  3293. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  3294. ;;
  3295. *)
  3296. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  3297. if [ $cword -eq $counter ]; then
  3298. __docker_complete_stacks
  3299. fi
  3300. ;;
  3301. esac
  3302. }
  3303. _docker_stack_up() {
  3304. _docker_stack_deploy
  3305. }
  3306. _docker_start() {
  3307. _docker_container_start
  3308. }
  3309. _docker_stats() {
  3310. _docker_container_stats
  3311. }
  3312. _docker_stop() {
  3313. _docker_container_stop
  3314. }
  3315. _docker_system() {
  3316. local subcommands="
  3317. df
  3318. events
  3319. info
  3320. prune
  3321. "
  3322. __docker_subcommands "$subcommands $aliases" && return
  3323. case "$cur" in
  3324. -*)
  3325. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3326. ;;
  3327. *)
  3328. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3329. ;;
  3330. esac
  3331. }
  3332. _docker_system_df() {
  3333. case "$cur" in
  3334. -*)
  3335. COMPREPLY=( $( compgen -W "--help --verbose -v" -- "$cur" ) )
  3336. ;;
  3337. esac
  3338. }
  3339. _docker_system_events() {
  3340. local key=$(__docker_map_key_of_current_option '-f|--filter')
  3341. case "$key" in
  3342. container)
  3343. __docker_complete_containers_all --cur "${cur##*=}"
  3344. return
  3345. ;;
  3346. daemon)
  3347. local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
  3348. COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
  3349. return
  3350. ;;
  3351. event)
  3352. COMPREPLY=( $( compgen -W "
  3353. attach
  3354. commit
  3355. connect
  3356. copy
  3357. create
  3358. delete
  3359. destroy
  3360. detach
  3361. die
  3362. disconnect
  3363. exec_create
  3364. exec_detach
  3365. exec_start
  3366. export
  3367. health_status
  3368. import
  3369. kill
  3370. load
  3371. mount
  3372. oom
  3373. pause
  3374. pull
  3375. push
  3376. reload
  3377. rename
  3378. resize
  3379. restart
  3380. save
  3381. start
  3382. stop
  3383. tag
  3384. top
  3385. unmount
  3386. unpause
  3387. untag
  3388. update
  3389. " -- "${cur##*=}" ) )
  3390. return
  3391. ;;
  3392. image)
  3393. cur="${cur##*=}"
  3394. __docker_complete_images
  3395. return
  3396. ;;
  3397. network)
  3398. __docker_complete_networks --cur "${cur##*=}"
  3399. return
  3400. ;;
  3401. type)
  3402. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  3403. return
  3404. ;;
  3405. volume)
  3406. __docker_complete_volumes --cur "${cur##*=}"
  3407. return
  3408. ;;
  3409. esac
  3410. case "$prev" in
  3411. --filter|-f)
  3412. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  3413. __docker_nospace
  3414. return
  3415. ;;
  3416. --since|--until)
  3417. return
  3418. ;;
  3419. esac
  3420. case "$cur" in
  3421. -*)
  3422. COMPREPLY=( $( compgen -W "--filter -f --help --since --until --format" -- "$cur" ) )
  3423. ;;
  3424. esac
  3425. }
  3426. _docker_system_info() {
  3427. case "$prev" in
  3428. --format|-f)
  3429. return
  3430. ;;
  3431. esac
  3432. case "$cur" in
  3433. -*)
  3434. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3435. ;;
  3436. esac
  3437. }
  3438. _docker_system_prune() {
  3439. case "$cur" in
  3440. -*)
  3441. COMPREPLY=( $( compgen -W "--all -a --force -f --help" -- "$cur" ) )
  3442. ;;
  3443. esac
  3444. }
  3445. _docker_tag() {
  3446. _docker_image_tag
  3447. }
  3448. _docker_unpause() {
  3449. _docker_container_unpause
  3450. }
  3451. _docker_update() {
  3452. _docker_container_update
  3453. }
  3454. _docker_top() {
  3455. _docker_container_top
  3456. }
  3457. _docker_version() {
  3458. case "$prev" in
  3459. --format|-f)
  3460. return
  3461. ;;
  3462. esac
  3463. case "$cur" in
  3464. -*)
  3465. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3466. ;;
  3467. esac
  3468. }
  3469. _docker_volume_create() {
  3470. case "$prev" in
  3471. --driver|-d)
  3472. __docker_complete_plugins_bundled --type Volume
  3473. return
  3474. ;;
  3475. --label|--opt|-o)
  3476. return
  3477. ;;
  3478. esac
  3479. case "$cur" in
  3480. -*)
  3481. COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) )
  3482. ;;
  3483. esac
  3484. }
  3485. _docker_volume_inspect() {
  3486. case "$prev" in
  3487. --format|-f)
  3488. return
  3489. ;;
  3490. esac
  3491. case "$cur" in
  3492. -*)
  3493. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3494. ;;
  3495. *)
  3496. __docker_complete_volumes
  3497. ;;
  3498. esac
  3499. }
  3500. _docker_volume_ls() {
  3501. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3502. case "$key" in
  3503. dangling)
  3504. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  3505. return
  3506. ;;
  3507. driver)
  3508. __docker_complete_plugins_bundled --cur "${cur##*=}" --type Volume
  3509. return
  3510. ;;
  3511. name)
  3512. __docker_complete_volumes --cur "${cur##*=}"
  3513. return
  3514. ;;
  3515. esac
  3516. case "$prev" in
  3517. --filter|-f)
  3518. COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) )
  3519. __docker_nospace
  3520. return
  3521. ;;
  3522. --format)
  3523. return
  3524. ;;
  3525. esac
  3526. case "$cur" in
  3527. -*)
  3528. COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
  3529. ;;
  3530. esac
  3531. }
  3532. _docker_volume_prune() {
  3533. case "$cur" in
  3534. -*)
  3535. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3536. ;;
  3537. esac
  3538. }
  3539. _docker_volume_rm() {
  3540. case "$cur" in
  3541. -*)
  3542. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3543. ;;
  3544. *)
  3545. __docker_complete_volumes
  3546. ;;
  3547. esac
  3548. }
  3549. _docker_volume() {
  3550. local subcommands="
  3551. create
  3552. inspect
  3553. ls
  3554. prune
  3555. rm
  3556. "
  3557. __docker_subcommands "$subcommands" && return
  3558. case "$cur" in
  3559. -*)
  3560. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3561. ;;
  3562. *)
  3563. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3564. ;;
  3565. esac
  3566. }
  3567. _docker_wait() {
  3568. _docker_container_wait
  3569. }
  3570. _docker() {
  3571. local previous_extglob_setting=$(shopt -p extglob)
  3572. shopt -s extglob
  3573. local commands=(
  3574. attach
  3575. build
  3576. commit
  3577. container
  3578. cp
  3579. create
  3580. daemon
  3581. diff
  3582. events
  3583. exec
  3584. export
  3585. history
  3586. image
  3587. images
  3588. import
  3589. info
  3590. inspect
  3591. kill
  3592. load
  3593. login
  3594. logout
  3595. logs
  3596. network
  3597. node
  3598. pause
  3599. plugin
  3600. port
  3601. ps
  3602. pull
  3603. push
  3604. rename
  3605. restart
  3606. rm
  3607. rmi
  3608. run
  3609. save
  3610. search
  3611. secret
  3612. service
  3613. stack
  3614. start
  3615. stats
  3616. stop
  3617. swarm
  3618. system
  3619. tag
  3620. top
  3621. unpause
  3622. update
  3623. version
  3624. volume
  3625. wait
  3626. )
  3627. local experimental_commands=(
  3628. deploy
  3629. )
  3630. # These options are valid as global options for all client commands
  3631. # and valid as command options for `docker daemon`
  3632. local global_boolean_options="
  3633. --debug -D
  3634. --tls
  3635. --tlsverify
  3636. "
  3637. local global_options_with_args="
  3638. --config
  3639. --host -H
  3640. --log-level -l
  3641. --tlscacert
  3642. --tlscert
  3643. --tlskey
  3644. "
  3645. local host config
  3646. COMPREPLY=()
  3647. local cur prev words cword
  3648. _get_comp_words_by_ref -n : cur prev words cword
  3649. local command='docker' command_pos=0 subcommand_pos
  3650. local counter=1
  3651. while [ $counter -lt $cword ]; do
  3652. case "${words[$counter]}" in
  3653. # save host so that completion can use custom daemon
  3654. --host|-H)
  3655. (( counter++ ))
  3656. host="${words[$counter]}"
  3657. ;;
  3658. # save config so that completion can use custom configuration directories
  3659. --config)
  3660. (( counter++ ))
  3661. config="${words[$counter]}"
  3662. ;;
  3663. $(__docker_to_extglob "$global_options_with_args") )
  3664. (( counter++ ))
  3665. ;;
  3666. -*)
  3667. ;;
  3668. =)
  3669. (( counter++ ))
  3670. ;;
  3671. *)
  3672. command="${words[$counter]}"
  3673. command_pos=$counter
  3674. break
  3675. ;;
  3676. esac
  3677. (( counter++ ))
  3678. done
  3679. local binary="${words[0]}"
  3680. if [[ $binary == ?(*/)dockerd ]] ; then
  3681. # for the dockerd binary, we reuse completion of `docker daemon`.
  3682. # dockerd does not have subcommands and global options.
  3683. command=daemon
  3684. command_pos=0
  3685. fi
  3686. local completions_func=_docker_${command}
  3687. declare -F $completions_func >/dev/null && $completions_func
  3688. eval "$previous_extglob_setting"
  3689. return 0
  3690. }
  3691. eval "$__docker_previous_extglob_setting"
  3692. unset __docker_previous_extglob_setting
  3693. complete -F _docker docker dockerd