docker 67 KB

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