docker 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125
  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_complete_detach-keys && return
  750. case "$cur" in
  751. -*)
  752. COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) )
  753. ;;
  754. *)
  755. local counter=$(__docker_pos_first_nonflag '--detach-keys')
  756. if [ $cword -eq $counter ]; then
  757. __docker_complete_containers_running
  758. fi
  759. ;;
  760. esac
  761. }
  762. _docker_build() {
  763. local options_with_args="
  764. --build-arg
  765. --cgroup-parent
  766. --cpuset-cpus
  767. --cpuset-mems
  768. --cpu-shares -c
  769. --cpu-period
  770. --cpu-quota
  771. --file -f
  772. --isolation
  773. --label
  774. --memory -m
  775. --memory-swap
  776. --shm-size
  777. --tag -t
  778. --ulimit
  779. "
  780. local boolean_options="
  781. --compress
  782. --disable-content-trust=false
  783. --force-rm
  784. --help
  785. --no-cache
  786. --pull
  787. --quiet -q
  788. --rm
  789. "
  790. local all_options="$options_with_args $boolean_options"
  791. case "$prev" in
  792. --build-arg)
  793. COMPREPLY=( $( compgen -e -- "$cur" ) )
  794. __docker_nospace
  795. return
  796. ;;
  797. --file|-f)
  798. _filedir
  799. return
  800. ;;
  801. --isolation)
  802. __docker_complete_isolation
  803. return
  804. ;;
  805. --tag|-t)
  806. __docker_complete_image_repos_and_tags
  807. return
  808. ;;
  809. $(__docker_to_extglob "$options_with_args") )
  810. return
  811. ;;
  812. esac
  813. case "$cur" in
  814. -*)
  815. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  816. ;;
  817. *)
  818. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  819. if [ $cword -eq $counter ]; then
  820. _filedir -d
  821. fi
  822. ;;
  823. esac
  824. }
  825. _docker_commit() {
  826. case "$prev" in
  827. --author|-a|--change|-c|--message|-m)
  828. return
  829. ;;
  830. esac
  831. case "$cur" in
  832. -*)
  833. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) )
  834. ;;
  835. *)
  836. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  837. if [ $cword -eq $counter ]; then
  838. __docker_complete_containers_all
  839. return
  840. fi
  841. (( counter++ ))
  842. if [ $cword -eq $counter ]; then
  843. __docker_complete_image_repos_and_tags
  844. return
  845. fi
  846. ;;
  847. esac
  848. }
  849. _docker_cp() {
  850. case "$cur" in
  851. -*)
  852. COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) )
  853. ;;
  854. *)
  855. local counter=$(__docker_pos_first_nonflag)
  856. if [ $cword -eq $counter ]; then
  857. case "$cur" in
  858. *:)
  859. return
  860. ;;
  861. *)
  862. # combined container and filename completion
  863. _filedir
  864. local files=( ${COMPREPLY[@]} )
  865. __docker_complete_containers_all
  866. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  867. local containers=( ${COMPREPLY[@]} )
  868. COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) )
  869. if [[ "$COMPREPLY" == *: ]]; then
  870. __docker_nospace
  871. fi
  872. return
  873. ;;
  874. esac
  875. fi
  876. (( counter++ ))
  877. if [ $cword -eq $counter ]; then
  878. if [ -e "$prev" ]; then
  879. __docker_complete_containers_all
  880. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  881. __docker_nospace
  882. else
  883. _filedir
  884. fi
  885. return
  886. fi
  887. ;;
  888. esac
  889. }
  890. _docker_create() {
  891. _docker_run
  892. }
  893. _docker_daemon() {
  894. local boolean_options="
  895. $global_boolean_options
  896. --disable-legacy-registry
  897. --help
  898. --icc=false
  899. --ip-forward=false
  900. --ip-masq=false
  901. --iptables=false
  902. --ipv6
  903. --live-restore
  904. --raw-logs
  905. --selinux-enabled
  906. --userland-proxy=false
  907. "
  908. local options_with_args="
  909. $global_options_with_args
  910. --add-runtime
  911. --api-cors-header
  912. --authorization-plugin
  913. --bip
  914. --bridge -b
  915. --cgroup-parent
  916. --cluster-advertise
  917. --cluster-store
  918. --cluster-store-opt
  919. --config-file
  920. --containerd
  921. --default-gateway
  922. --default-gateway-v6
  923. --default-ulimit
  924. --dns
  925. --dns-search
  926. --dns-opt
  927. --exec-opt
  928. --exec-root
  929. --fixed-cidr
  930. --fixed-cidr-v6
  931. --graph -g
  932. --group -G
  933. --init-path
  934. --insecure-registry
  935. --ip
  936. --label
  937. --log-driver
  938. --log-opt
  939. --max-concurrent-downloads
  940. --max-concurrent-uploads
  941. --mtu
  942. --oom-score-adjust
  943. --pidfile -p
  944. --registry-mirror
  945. --storage-driver -s
  946. --storage-opt
  947. --userns-remap
  948. "
  949. __docker_complete_log_driver_options && return
  950. key=$(__docker_map_key_of_current_option '--cluster-store-opt')
  951. case "$key" in
  952. kv.*file)
  953. cur=${cur##*=}
  954. _filedir
  955. return
  956. ;;
  957. esac
  958. local key=$(__docker_map_key_of_current_option '--storage-opt')
  959. case "$key" in
  960. dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion)
  961. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  962. return
  963. ;;
  964. dm.fs)
  965. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) )
  966. return
  967. ;;
  968. dm.thinpooldev)
  969. cur=${cur##*=}
  970. _filedir
  971. return
  972. ;;
  973. esac
  974. case "$prev" in
  975. --authorization-plugin)
  976. __docker_complete_plugins --type Authorization
  977. return
  978. ;;
  979. --cluster-store)
  980. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  981. __docker_nospace
  982. return
  983. ;;
  984. --cluster-store-opt)
  985. COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) )
  986. __docker_nospace
  987. return
  988. ;;
  989. --config-file|--containerd|--init-path|--pidfile|-p|--tlscacert|--tlscert|--tlskey)
  990. _filedir
  991. return
  992. ;;
  993. --exec-root|--graph|-g)
  994. _filedir -d
  995. return
  996. ;;
  997. --log-driver)
  998. __docker_complete_log_drivers
  999. return
  1000. ;;
  1001. --storage-driver|-s)
  1002. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  1003. return
  1004. ;;
  1005. --storage-opt)
  1006. local btrfs_options="btrfs.min_space"
  1007. local devicemapper_options="
  1008. dm.basesize
  1009. dm.blkdiscard
  1010. dm.blocksize
  1011. dm.fs
  1012. dm.loopdatasize
  1013. dm.loopmetadatasize
  1014. dm.min_free_space
  1015. dm.mkfsarg
  1016. dm.mountopt
  1017. dm.override_udev_sync_check
  1018. dm.thinpooldev
  1019. dm.use_deferred_deletion
  1020. dm.use_deferred_removal
  1021. "
  1022. local zfs_options="zfs.fsname"
  1023. case $(__docker_value_of_option '--storage-driver|-s') in
  1024. '')
  1025. COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) )
  1026. ;;
  1027. btrfs)
  1028. COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) )
  1029. ;;
  1030. devicemapper)
  1031. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  1032. ;;
  1033. zfs)
  1034. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  1035. ;;
  1036. *)
  1037. return
  1038. ;;
  1039. esac
  1040. __docker_nospace
  1041. return
  1042. ;;
  1043. --log-level|-l)
  1044. __docker_complete_log_levels
  1045. return
  1046. ;;
  1047. --log-opt)
  1048. __docker_complete_log_options
  1049. return
  1050. ;;
  1051. --userns-remap)
  1052. __docker_complete_user_group
  1053. return
  1054. ;;
  1055. $(__docker_to_extglob "$options_with_args") )
  1056. return
  1057. ;;
  1058. esac
  1059. case "$cur" in
  1060. -*)
  1061. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1062. ;;
  1063. esac
  1064. }
  1065. _docker_diff() {
  1066. case "$cur" in
  1067. -*)
  1068. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1069. ;;
  1070. *)
  1071. local counter=$(__docker_pos_first_nonflag)
  1072. if [ $cword -eq $counter ]; then
  1073. __docker_complete_containers_all
  1074. fi
  1075. ;;
  1076. esac
  1077. }
  1078. _docker_events() {
  1079. local key=$(__docker_map_key_of_current_option '-f|--filter')
  1080. case "$key" in
  1081. container)
  1082. __docker_complete_containers_all --cur "${cur##*=}"
  1083. return
  1084. ;;
  1085. daemon)
  1086. local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
  1087. COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
  1088. return
  1089. ;;
  1090. event)
  1091. COMPREPLY=( $( compgen -W "
  1092. attach
  1093. commit
  1094. connect
  1095. copy
  1096. create
  1097. delete
  1098. destroy
  1099. detach
  1100. die
  1101. disconnect
  1102. exec_create
  1103. exec_detach
  1104. exec_start
  1105. export
  1106. health_status
  1107. import
  1108. kill
  1109. load
  1110. mount
  1111. oom
  1112. pause
  1113. pull
  1114. push
  1115. reload
  1116. rename
  1117. resize
  1118. restart
  1119. save
  1120. start
  1121. stop
  1122. tag
  1123. top
  1124. unmount
  1125. unpause
  1126. untag
  1127. update
  1128. " -- "${cur##*=}" ) )
  1129. return
  1130. ;;
  1131. image)
  1132. cur="${cur##*=}"
  1133. __docker_complete_images
  1134. return
  1135. ;;
  1136. network)
  1137. __docker_complete_networks --cur "${cur##*=}"
  1138. return
  1139. ;;
  1140. type)
  1141. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  1142. return
  1143. ;;
  1144. volume)
  1145. __docker_complete_volumes --cur "${cur##*=}"
  1146. return
  1147. ;;
  1148. esac
  1149. case "$prev" in
  1150. --filter|-f)
  1151. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  1152. __docker_nospace
  1153. return
  1154. ;;
  1155. --since|--until)
  1156. return
  1157. ;;
  1158. esac
  1159. case "$cur" in
  1160. -*)
  1161. COMPREPLY=( $( compgen -W "--filter -f --help --since --until --format" -- "$cur" ) )
  1162. ;;
  1163. esac
  1164. }
  1165. _docker_exec() {
  1166. __docker_complete_detach-keys && return
  1167. case "$prev" in
  1168. --user|-u)
  1169. __docker_complete_user_group
  1170. return
  1171. ;;
  1172. esac
  1173. case "$cur" in
  1174. -*)
  1175. COMPREPLY=( $( compgen -W "--detach -d --detach-keys --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  1176. ;;
  1177. *)
  1178. __docker_complete_containers_running
  1179. ;;
  1180. esac
  1181. }
  1182. _docker_export() {
  1183. case "$cur" in
  1184. -*)
  1185. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1186. ;;
  1187. *)
  1188. local counter=$(__docker_pos_first_nonflag)
  1189. if [ $cword -eq $counter ]; then
  1190. __docker_complete_containers_all
  1191. fi
  1192. ;;
  1193. esac
  1194. }
  1195. _docker_help() {
  1196. local counter=$(__docker_pos_first_nonflag)
  1197. if [ $cword -eq $counter ]; then
  1198. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  1199. fi
  1200. }
  1201. _docker_history() {
  1202. case "$cur" in
  1203. -*)
  1204. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  1205. ;;
  1206. *)
  1207. local counter=$(__docker_pos_first_nonflag)
  1208. if [ $cword -eq $counter ]; then
  1209. __docker_complete_images
  1210. fi
  1211. ;;
  1212. esac
  1213. }
  1214. _docker_images() {
  1215. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1216. case "$key" in
  1217. before)
  1218. cur="${cur##*=}"
  1219. __docker_complete_images
  1220. return
  1221. ;;
  1222. dangling)
  1223. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1224. return
  1225. ;;
  1226. label)
  1227. return
  1228. ;;
  1229. since)
  1230. cur="${cur##*=}"
  1231. __docker_complete_images
  1232. return
  1233. ;;
  1234. esac
  1235. case "$prev" in
  1236. --filter|-f)
  1237. COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) )
  1238. __docker_nospace
  1239. return
  1240. ;;
  1241. --format)
  1242. return
  1243. ;;
  1244. esac
  1245. case "$cur" in
  1246. -*)
  1247. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1248. ;;
  1249. =)
  1250. return
  1251. ;;
  1252. *)
  1253. __docker_complete_image_repos
  1254. ;;
  1255. esac
  1256. }
  1257. _docker_import() {
  1258. case "$prev" in
  1259. --change|-c|--message|-m)
  1260. return
  1261. ;;
  1262. esac
  1263. case "$cur" in
  1264. -*)
  1265. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1266. ;;
  1267. *)
  1268. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1269. if [ $cword -eq $counter ]; then
  1270. return
  1271. fi
  1272. (( counter++ ))
  1273. if [ $cword -eq $counter ]; then
  1274. __docker_complete_image_repos_and_tags
  1275. return
  1276. fi
  1277. ;;
  1278. esac
  1279. }
  1280. _docker_info() {
  1281. case "$prev" in
  1282. --format|-f)
  1283. return
  1284. ;;
  1285. esac
  1286. case "$cur" in
  1287. -*)
  1288. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1289. ;;
  1290. esac
  1291. }
  1292. _docker_inspect() {
  1293. case "$prev" in
  1294. --format|-f)
  1295. return
  1296. ;;
  1297. --type)
  1298. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  1299. return
  1300. ;;
  1301. esac
  1302. case "$cur" in
  1303. -*)
  1304. COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) )
  1305. ;;
  1306. *)
  1307. case $(__docker_value_of_option --type) in
  1308. '')
  1309. __docker_complete_containers_and_images
  1310. ;;
  1311. container)
  1312. __docker_complete_containers_all
  1313. ;;
  1314. image)
  1315. __docker_complete_images
  1316. ;;
  1317. esac
  1318. esac
  1319. }
  1320. _docker_kill() {
  1321. case "$prev" in
  1322. --signal|-s)
  1323. __docker_complete_signals
  1324. return
  1325. ;;
  1326. esac
  1327. case "$cur" in
  1328. -*)
  1329. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  1330. ;;
  1331. *)
  1332. __docker_complete_containers_running
  1333. ;;
  1334. esac
  1335. }
  1336. _docker_load() {
  1337. case "$prev" in
  1338. --input|-i)
  1339. _filedir
  1340. return
  1341. ;;
  1342. esac
  1343. case "$cur" in
  1344. -*)
  1345. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1346. ;;
  1347. esac
  1348. }
  1349. _docker_login() {
  1350. case "$prev" in
  1351. --password|-p|--username|-u)
  1352. return
  1353. ;;
  1354. esac
  1355. case "$cur" in
  1356. -*)
  1357. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  1358. ;;
  1359. esac
  1360. }
  1361. _docker_logout() {
  1362. case "$cur" in
  1363. -*)
  1364. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1365. ;;
  1366. esac
  1367. }
  1368. _docker_logs() {
  1369. case "$prev" in
  1370. --since|--tail)
  1371. return
  1372. ;;
  1373. esac
  1374. case "$cur" in
  1375. -*)
  1376. COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  1377. ;;
  1378. *)
  1379. local counter=$(__docker_pos_first_nonflag '--since|--tail')
  1380. if [ $cword -eq $counter ]; then
  1381. __docker_complete_containers_all
  1382. fi
  1383. ;;
  1384. esac
  1385. }
  1386. _docker_network_connect() {
  1387. local options_with_args="
  1388. --alias
  1389. --ip
  1390. --ip6
  1391. --link
  1392. --link-local-ip
  1393. "
  1394. local boolean_options="
  1395. --help
  1396. "
  1397. case "$prev" in
  1398. --link)
  1399. case "$cur" in
  1400. *:*)
  1401. ;;
  1402. *)
  1403. __docker_complete_containers_running
  1404. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1405. __docker_nospace
  1406. ;;
  1407. esac
  1408. return
  1409. ;;
  1410. $(__docker_to_extglob "$options_with_args") )
  1411. return
  1412. ;;
  1413. esac
  1414. case "$cur" in
  1415. -*)
  1416. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1417. ;;
  1418. *)
  1419. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1420. if [ $cword -eq $counter ]; then
  1421. __docker_complete_networks
  1422. elif [ $cword -eq $(($counter + 1)) ]; then
  1423. __docker_complete_containers_all
  1424. fi
  1425. ;;
  1426. esac
  1427. }
  1428. _docker_network_create() {
  1429. case "$prev" in
  1430. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  1431. return
  1432. ;;
  1433. --ipam-driver)
  1434. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  1435. return
  1436. ;;
  1437. --driver|-d)
  1438. # remove drivers that allow one instance only, add drivers missing in `docker info`
  1439. __docker_complete_plugins --type Network --remove host --remove null --add macvlan
  1440. return
  1441. ;;
  1442. --label)
  1443. return
  1444. ;;
  1445. esac
  1446. case "$cur" in
  1447. -*)
  1448. COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  1449. ;;
  1450. esac
  1451. }
  1452. _docker_network_disconnect() {
  1453. case "$cur" in
  1454. -*)
  1455. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1456. ;;
  1457. *)
  1458. local counter=$(__docker_pos_first_nonflag)
  1459. if [ $cword -eq $counter ]; then
  1460. __docker_complete_networks
  1461. elif [ $cword -eq $(($counter + 1)) ]; then
  1462. __docker_complete_containers_in_network "$prev"
  1463. fi
  1464. ;;
  1465. esac
  1466. }
  1467. _docker_network_inspect() {
  1468. case "$prev" in
  1469. --format|-f)
  1470. return
  1471. ;;
  1472. esac
  1473. case "$cur" in
  1474. -*)
  1475. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1476. ;;
  1477. *)
  1478. __docker_complete_networks
  1479. esac
  1480. }
  1481. _docker_network_ls() {
  1482. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1483. case "$key" in
  1484. driver)
  1485. __docker_complete_plugins --cur "${cur##*=}" --type Network --add macvlan
  1486. return
  1487. ;;
  1488. id)
  1489. __docker_complete_networks --cur "${cur##*=}" --id
  1490. return
  1491. ;;
  1492. name)
  1493. __docker_complete_networks --cur "${cur##*=}" --name
  1494. return
  1495. ;;
  1496. type)
  1497. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  1498. return
  1499. ;;
  1500. esac
  1501. case "$prev" in
  1502. --filter|-f)
  1503. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  1504. __docker_nospace
  1505. return
  1506. ;;
  1507. --format)
  1508. return
  1509. ;;
  1510. esac
  1511. case "$cur" in
  1512. -*)
  1513. COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1514. ;;
  1515. esac
  1516. }
  1517. _docker_network_rm() {
  1518. case "$cur" in
  1519. -*)
  1520. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1521. ;;
  1522. *)
  1523. __docker_complete_networks --filter type=custom
  1524. esac
  1525. }
  1526. _docker_network() {
  1527. local subcommands="
  1528. connect
  1529. create
  1530. disconnect
  1531. inspect
  1532. ls
  1533. rm
  1534. "
  1535. __docker_subcommands "$subcommands" && return
  1536. case "$cur" in
  1537. -*)
  1538. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1539. ;;
  1540. *)
  1541. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1542. ;;
  1543. esac
  1544. }
  1545. _docker_service() {
  1546. local subcommands="
  1547. create
  1548. inspect
  1549. ls list
  1550. rm remove
  1551. scale
  1552. ps
  1553. update
  1554. "
  1555. __docker_subcommands "$subcommands" && return
  1556. case "$cur" in
  1557. -*)
  1558. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1559. ;;
  1560. *)
  1561. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1562. ;;
  1563. esac
  1564. }
  1565. _docker_service_create() {
  1566. _docker_service_update
  1567. }
  1568. _docker_service_inspect() {
  1569. case "$prev" in
  1570. --format|-f)
  1571. return
  1572. ;;
  1573. esac
  1574. case "$cur" in
  1575. -*)
  1576. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  1577. ;;
  1578. *)
  1579. __docker_complete_services
  1580. esac
  1581. }
  1582. _docker_service_list() {
  1583. _docker_service_ls
  1584. }
  1585. _docker_service_ls() {
  1586. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1587. case "$key" in
  1588. id)
  1589. __docker_complete_services --cur "${cur##*=}" --id
  1590. return
  1591. ;;
  1592. name)
  1593. __docker_complete_services --cur "${cur##*=}" --name
  1594. return
  1595. ;;
  1596. esac
  1597. case "$prev" in
  1598. --filter|-f)
  1599. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  1600. __docker_nospace
  1601. return
  1602. ;;
  1603. esac
  1604. case "$cur" in
  1605. -*)
  1606. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1607. ;;
  1608. esac
  1609. }
  1610. _docker_service_remove() {
  1611. _docker_service_rm
  1612. }
  1613. _docker_service_rm() {
  1614. case "$cur" in
  1615. -*)
  1616. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1617. ;;
  1618. *)
  1619. __docker_complete_services
  1620. esac
  1621. }
  1622. _docker_service_scale() {
  1623. case "$cur" in
  1624. -*)
  1625. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1626. ;;
  1627. *)
  1628. __docker_complete_services
  1629. __docker_append_to_completions "="
  1630. __docker_nospace
  1631. ;;
  1632. esac
  1633. }
  1634. _docker_service_ps() {
  1635. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1636. case "$key" in
  1637. desired-state)
  1638. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  1639. return
  1640. ;;
  1641. name)
  1642. __docker_complete_services --cur "${cur##*=}" --name
  1643. return
  1644. ;;
  1645. esac
  1646. case "$prev" in
  1647. --filter|-f)
  1648. COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) )
  1649. __docker_nospace
  1650. return
  1651. ;;
  1652. esac
  1653. case "$cur" in
  1654. -*)
  1655. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  1656. ;;
  1657. *)
  1658. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  1659. if [ $cword -eq $counter ]; then
  1660. __docker_complete_services
  1661. fi
  1662. ;;
  1663. esac
  1664. }
  1665. _docker_service_update() {
  1666. local $subcommand="${words[$subcommand_pos]}"
  1667. local options_with_args="
  1668. --constraint
  1669. --endpoint-mode
  1670. --env -e
  1671. --group-add
  1672. --label -l
  1673. --limit-cpu
  1674. --limit-memory
  1675. --log-driver
  1676. --log-opt
  1677. --mount
  1678. --name
  1679. --network
  1680. --publish -p
  1681. --replicas
  1682. --reserve-cpu
  1683. --reserve-memory
  1684. --restart-condition
  1685. --restart-delay
  1686. --restart-max-attempts
  1687. --restart-window
  1688. --rollback
  1689. --stop-grace-period
  1690. --update-delay
  1691. --update-failure-action
  1692. --update-max-failure-ratio
  1693. --update-monitor
  1694. --update-parallelism
  1695. --user -u
  1696. --workdir -w
  1697. "
  1698. local boolean_options="
  1699. --help
  1700. --with-registry-auth
  1701. "
  1702. __docker_complete_log_driver_options && return
  1703. if [ "$subcommand" = "create" ] ; then
  1704. options_with_args="$options_with_args
  1705. --container-label
  1706. --mode
  1707. "
  1708. case "$prev" in
  1709. --mode)
  1710. COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) )
  1711. return
  1712. ;;
  1713. esac
  1714. fi
  1715. if [ "$subcommand" = "update" ] ; then
  1716. options_with_args="$options_with_args
  1717. --arg
  1718. --container-label-add
  1719. --container-label-rm
  1720. --group-rm
  1721. --image
  1722. "
  1723. case "$prev" in
  1724. --group-rm)
  1725. COMPREPLY=( $(compgen -g -- "$cur") )
  1726. return
  1727. ;;
  1728. --image)
  1729. __docker_complete_image_repos_and_tags
  1730. return
  1731. ;;
  1732. esac
  1733. fi
  1734. case "$prev" in
  1735. --endpoint-mode)
  1736. COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) )
  1737. return
  1738. ;;
  1739. --env|-e)
  1740. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  1741. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1742. __docker_nospace
  1743. return
  1744. ;;
  1745. --group-add)
  1746. COMPREPLY=( $(compgen -g -- "$cur") )
  1747. return
  1748. ;;
  1749. --log-driver)
  1750. __docker_complete_log_drivers
  1751. return
  1752. ;;
  1753. --log-opt)
  1754. __docker_complete_log_options
  1755. return
  1756. ;;
  1757. --network)
  1758. __docker_complete_networks
  1759. return
  1760. ;;
  1761. --restart-condition)
  1762. COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) )
  1763. return
  1764. ;;
  1765. --user|-u)
  1766. __docker_complete_user_group
  1767. return
  1768. ;;
  1769. $(__docker_to_extglob "$options_with_args") )
  1770. return
  1771. ;;
  1772. esac
  1773. case "$cur" in
  1774. -*)
  1775. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1776. ;;
  1777. *)
  1778. if [ "$subcommand" = "update" ] ; then
  1779. __docker_complete_services
  1780. fi
  1781. esac
  1782. }
  1783. _docker_swarm() {
  1784. local subcommands="
  1785. init
  1786. join
  1787. join-token
  1788. leave
  1789. update
  1790. "
  1791. __docker_subcommands "$subcommands" && return
  1792. case "$cur" in
  1793. -*)
  1794. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1795. ;;
  1796. *)
  1797. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1798. ;;
  1799. esac
  1800. }
  1801. _docker_swarm_init() {
  1802. case "$prev" in
  1803. --advertise-addr)
  1804. if [[ $cur == *: ]] ; then
  1805. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1806. else
  1807. __docker_complete_local_interfaces
  1808. __docker_nospace
  1809. fi
  1810. return
  1811. ;;
  1812. --listen-addr)
  1813. if [[ $cur == *: ]] ; then
  1814. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1815. else
  1816. __docker_complete_local_interfaces --add 0.0.0.0
  1817. __docker_nospace
  1818. fi
  1819. return
  1820. ;;
  1821. esac
  1822. case "$cur" in
  1823. -*)
  1824. COMPREPLY=( $( compgen -W "--advertise-addr --force-new-cluster --help --listen-addr" -- "$cur" ) )
  1825. ;;
  1826. esac
  1827. }
  1828. _docker_swarm_join() {
  1829. case "$prev" in
  1830. --advertise-addr)
  1831. if [[ $cur == *: ]] ; then
  1832. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1833. else
  1834. __docker_complete_local_interfaces
  1835. __docker_nospace
  1836. fi
  1837. return
  1838. ;;
  1839. --listen-addr)
  1840. if [[ $cur == *: ]] ; then
  1841. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1842. else
  1843. __docker_complete_local_interfaces --add 0.0.0.0
  1844. __docker_nospace
  1845. fi
  1846. return
  1847. ;;
  1848. --token)
  1849. return
  1850. ;;
  1851. esac
  1852. case "$cur" in
  1853. -*)
  1854. COMPREPLY=( $( compgen -W "--advertise-addr --help --listen-addr --token" -- "$cur" ) )
  1855. ;;
  1856. *:)
  1857. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1858. ;;
  1859. esac
  1860. }
  1861. _docker_swarm_join-token() {
  1862. case "$cur" in
  1863. -*)
  1864. COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) )
  1865. ;;
  1866. *)
  1867. local counter=$( __docker_pos_first_nonflag )
  1868. if [ $cword -eq $counter ]; then
  1869. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  1870. fi
  1871. ;;
  1872. esac
  1873. }
  1874. _docker_swarm_leave() {
  1875. case "$cur" in
  1876. -*)
  1877. COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) )
  1878. ;;
  1879. esac
  1880. }
  1881. _docker_swarm_update() {
  1882. case "$prev" in
  1883. --cert-expiry|--dispatcher-heartbeat|--task-history-limit)
  1884. return
  1885. ;;
  1886. esac
  1887. case "$cur" in
  1888. -*)
  1889. COMPREPLY=( $( compgen -W "--cert-expiry --dispatcher-heartbeat --help --task-history-limit" -- "$cur" ) )
  1890. ;;
  1891. esac
  1892. }
  1893. _docker_node() {
  1894. local subcommands="
  1895. demote
  1896. inspect
  1897. ls list
  1898. promote
  1899. rm remove
  1900. ps
  1901. update
  1902. "
  1903. __docker_subcommands "$subcommands" && return
  1904. case "$cur" in
  1905. -*)
  1906. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1907. ;;
  1908. *)
  1909. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1910. ;;
  1911. esac
  1912. }
  1913. _docker_node_demote() {
  1914. case "$cur" in
  1915. -*)
  1916. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1917. ;;
  1918. *)
  1919. __docker_complete_nodes --filter role=manager
  1920. esac
  1921. }
  1922. _docker_node_inspect() {
  1923. case "$prev" in
  1924. --format|-f)
  1925. return
  1926. ;;
  1927. esac
  1928. case "$cur" in
  1929. -*)
  1930. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  1931. ;;
  1932. *)
  1933. __docker_complete_nodes_plus_self
  1934. esac
  1935. }
  1936. _docker_node_list() {
  1937. _docker_node_ls
  1938. }
  1939. _docker_node_ls() {
  1940. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1941. case "$key" in
  1942. id)
  1943. __docker_complete_nodes --cur "${cur##*=}" --id
  1944. return
  1945. ;;
  1946. name)
  1947. __docker_complete_nodes --cur "${cur##*=}" --name
  1948. return
  1949. ;;
  1950. esac
  1951. case "$prev" in
  1952. --filter|-f)
  1953. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  1954. __docker_nospace
  1955. return
  1956. ;;
  1957. esac
  1958. case "$cur" in
  1959. -*)
  1960. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1961. ;;
  1962. esac
  1963. }
  1964. _docker_node_promote() {
  1965. case "$cur" in
  1966. -*)
  1967. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1968. ;;
  1969. *)
  1970. __docker_complete_nodes --filter role=worker
  1971. esac
  1972. }
  1973. _docker_node_remove() {
  1974. _docker_node_rm
  1975. }
  1976. _docker_node_rm() {
  1977. case "$cur" in
  1978. -*)
  1979. COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) )
  1980. ;;
  1981. *)
  1982. __docker_complete_nodes
  1983. esac
  1984. }
  1985. _docker_node_ps() {
  1986. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1987. case "$key" in
  1988. desired-state)
  1989. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  1990. return
  1991. ;;
  1992. name)
  1993. __docker_complete_services --cur "${cur##*=}" --name
  1994. return
  1995. ;;
  1996. esac
  1997. case "$prev" in
  1998. --filter|-f)
  1999. COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) )
  2000. __docker_nospace
  2001. return
  2002. ;;
  2003. esac
  2004. case "$cur" in
  2005. -*)
  2006. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  2007. ;;
  2008. *)
  2009. __docker_complete_nodes_plus_self
  2010. ;;
  2011. esac
  2012. }
  2013. _docker_node_update() {
  2014. case "$prev" in
  2015. --availability)
  2016. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  2017. return
  2018. ;;
  2019. --role)
  2020. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  2021. return
  2022. ;;
  2023. --label-add|--label-rm)
  2024. return
  2025. ;;
  2026. esac
  2027. case "$cur" in
  2028. -*)
  2029. COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) )
  2030. ;;
  2031. *)
  2032. __docker_complete_nodes
  2033. esac
  2034. }
  2035. _docker_pause() {
  2036. case "$cur" in
  2037. -*)
  2038. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2039. ;;
  2040. *)
  2041. local counter=$(__docker_pos_first_nonflag)
  2042. if [ $cword -eq $counter ]; then
  2043. __docker_complete_containers_running
  2044. fi
  2045. ;;
  2046. esac
  2047. }
  2048. _docker_port() {
  2049. case "$cur" in
  2050. -*)
  2051. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2052. ;;
  2053. *)
  2054. local counter=$(__docker_pos_first_nonflag)
  2055. if [ $cword -eq $counter ]; then
  2056. __docker_complete_containers_all
  2057. fi
  2058. ;;
  2059. esac
  2060. }
  2061. _docker_ps() {
  2062. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2063. case "$key" in
  2064. ancestor)
  2065. cur="${cur##*=}"
  2066. __docker_complete_images
  2067. return
  2068. ;;
  2069. before)
  2070. __docker_complete_containers_all --cur "${cur##*=}"
  2071. return
  2072. ;;
  2073. id)
  2074. __docker_complete_containers_all --cur "${cur##*=}" --id
  2075. return
  2076. ;;
  2077. is-task)
  2078. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  2079. return
  2080. ;;
  2081. name)
  2082. __docker_complete_containers_all --cur "${cur##*=}" --name
  2083. return
  2084. ;;
  2085. network)
  2086. __docker_complete_networks --cur "${cur##*=}"
  2087. return
  2088. ;;
  2089. since)
  2090. __docker_complete_containers_all --cur "${cur##*=}"
  2091. return
  2092. ;;
  2093. status)
  2094. COMPREPLY=( $( compgen -W "created dead exited paused restarting running removing" -- "${cur##*=}" ) )
  2095. return
  2096. ;;
  2097. volume)
  2098. __docker_complete_volumes --cur "${cur##*=}"
  2099. return
  2100. ;;
  2101. esac
  2102. case "$prev" in
  2103. --filter|-f)
  2104. COMPREPLY=( $( compgen -S = -W "ancestor before exited id label name network since status volume" -- "$cur" ) )
  2105. __docker_nospace
  2106. return
  2107. ;;
  2108. --format|--last|-n)
  2109. return
  2110. ;;
  2111. esac
  2112. case "$cur" in
  2113. -*)
  2114. COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) )
  2115. ;;
  2116. esac
  2117. }
  2118. _docker_pull() {
  2119. case "$cur" in
  2120. -*)
  2121. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  2122. ;;
  2123. *)
  2124. local counter=$(__docker_pos_first_nonflag)
  2125. if [ $cword -eq $counter ]; then
  2126. for arg in "${COMP_WORDS[@]}"; do
  2127. case "$arg" in
  2128. --all-tags|-a)
  2129. __docker_complete_image_repos
  2130. return
  2131. ;;
  2132. esac
  2133. done
  2134. __docker_complete_image_repos_and_tags
  2135. fi
  2136. ;;
  2137. esac
  2138. }
  2139. _docker_push() {
  2140. case "$cur" in
  2141. -*)
  2142. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  2143. ;;
  2144. *)
  2145. local counter=$(__docker_pos_first_nonflag)
  2146. if [ $cword -eq $counter ]; then
  2147. __docker_complete_image_repos_and_tags
  2148. fi
  2149. ;;
  2150. esac
  2151. }
  2152. _docker_rename() {
  2153. case "$cur" in
  2154. -*)
  2155. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2156. ;;
  2157. *)
  2158. local counter=$(__docker_pos_first_nonflag)
  2159. if [ $cword -eq $counter ]; then
  2160. __docker_complete_containers_all
  2161. fi
  2162. ;;
  2163. esac
  2164. }
  2165. _docker_restart() {
  2166. case "$prev" in
  2167. --time|-t)
  2168. return
  2169. ;;
  2170. esac
  2171. case "$cur" in
  2172. -*)
  2173. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2174. ;;
  2175. *)
  2176. __docker_complete_containers_all
  2177. ;;
  2178. esac
  2179. }
  2180. _docker_rm() {
  2181. case "$cur" in
  2182. -*)
  2183. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  2184. ;;
  2185. *)
  2186. for arg in "${COMP_WORDS[@]}"; do
  2187. case "$arg" in
  2188. --force|-f)
  2189. __docker_complete_containers_all
  2190. return
  2191. ;;
  2192. esac
  2193. done
  2194. __docker_complete_containers_stopped
  2195. ;;
  2196. esac
  2197. }
  2198. _docker_rmi() {
  2199. case "$cur" in
  2200. -*)
  2201. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  2202. ;;
  2203. *)
  2204. __docker_complete_images
  2205. ;;
  2206. esac
  2207. }
  2208. _docker_run() {
  2209. local options_with_args="
  2210. --add-host
  2211. --attach -a
  2212. --blkio-weight
  2213. --blkio-weight-device
  2214. --cap-add
  2215. --cap-drop
  2216. --cgroup-parent
  2217. --cidfile
  2218. --cpu-period
  2219. --cpu-quota
  2220. --cpuset-cpus
  2221. --cpuset-mems
  2222. --cpu-shares -c
  2223. --device
  2224. --device-read-bps
  2225. --device-read-iops
  2226. --device-write-bps
  2227. --device-write-iops
  2228. --dns
  2229. --dns-opt
  2230. --dns-search
  2231. --entrypoint
  2232. --env -e
  2233. --env-file
  2234. --expose
  2235. --group-add
  2236. --hostname -h
  2237. --ip
  2238. --ip6
  2239. --ipc
  2240. --isolation
  2241. --kernel-memory
  2242. --label-file
  2243. --label -l
  2244. --link
  2245. --link-local-ip
  2246. --log-driver
  2247. --log-opt
  2248. --mac-address
  2249. --memory -m
  2250. --memory-swap
  2251. --memory-swappiness
  2252. --memory-reservation
  2253. --name
  2254. --network
  2255. --network-alias
  2256. --oom-score-adj
  2257. --pid
  2258. --pids-limit
  2259. --publish -p
  2260. --restart
  2261. --runtime
  2262. --security-opt
  2263. --shm-size
  2264. --stop-signal
  2265. --stop-timeout
  2266. --storage-opt
  2267. --tmpfs
  2268. --sysctl
  2269. --ulimit
  2270. --user -u
  2271. --userns
  2272. --uts
  2273. --volume-driver
  2274. --volumes-from
  2275. --volume -v
  2276. --workdir -w
  2277. "
  2278. local boolean_options="
  2279. --disable-content-trust=false
  2280. --help
  2281. --interactive -i
  2282. --oom-kill-disable
  2283. --privileged
  2284. --publish-all -P
  2285. --read-only
  2286. --tty -t
  2287. "
  2288. if [ "$command" = "run" ] ; then
  2289. options_with_args="$options_with_args
  2290. --detach-keys
  2291. --health-cmd
  2292. --health-interval
  2293. --health-retries
  2294. --health-timeout
  2295. "
  2296. boolean_options="$boolean_options
  2297. --detach -d
  2298. --no-healthcheck
  2299. --rm
  2300. --sig-proxy=false
  2301. "
  2302. __docker_complete_detach-keys && return
  2303. fi
  2304. local all_options="$options_with_args $boolean_options"
  2305. __docker_complete_log_driver_options && return
  2306. __docker_complete_restart && return
  2307. local key=$(__docker_map_key_of_current_option '--security-opt')
  2308. case "$key" in
  2309. label)
  2310. [[ $cur == *: ]] && return
  2311. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  2312. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  2313. __docker_nospace
  2314. fi
  2315. return
  2316. ;;
  2317. seccomp)
  2318. local cur=${cur##*=}
  2319. _filedir
  2320. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  2321. return
  2322. ;;
  2323. esac
  2324. case "$prev" in
  2325. --add-host)
  2326. case "$cur" in
  2327. *:)
  2328. __docker_complete_resolved_hostname
  2329. return
  2330. ;;
  2331. esac
  2332. ;;
  2333. --attach|-a)
  2334. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  2335. return
  2336. ;;
  2337. --cap-add|--cap-drop)
  2338. __docker_complete_capabilities
  2339. return
  2340. ;;
  2341. --cidfile|--env-file|--label-file)
  2342. _filedir
  2343. return
  2344. ;;
  2345. --device|--tmpfs|--volume|-v)
  2346. case "$cur" in
  2347. *:*)
  2348. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  2349. ;;
  2350. '')
  2351. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  2352. __docker_nospace
  2353. ;;
  2354. /*)
  2355. _filedir
  2356. __docker_nospace
  2357. ;;
  2358. esac
  2359. return
  2360. ;;
  2361. --env|-e)
  2362. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  2363. COMPREPLY=( $( compgen -e -- "$cur" ) )
  2364. __docker_nospace
  2365. return
  2366. ;;
  2367. --ipc)
  2368. case "$cur" in
  2369. *:*)
  2370. cur="${cur#*:}"
  2371. __docker_complete_containers_running
  2372. ;;
  2373. *)
  2374. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  2375. if [ "$COMPREPLY" = "container:" ]; then
  2376. __docker_nospace
  2377. fi
  2378. ;;
  2379. esac
  2380. return
  2381. ;;
  2382. --isolation)
  2383. __docker_complete_isolation
  2384. return
  2385. ;;
  2386. --link)
  2387. case "$cur" in
  2388. *:*)
  2389. ;;
  2390. *)
  2391. __docker_complete_containers_running
  2392. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  2393. __docker_nospace
  2394. ;;
  2395. esac
  2396. return
  2397. ;;
  2398. --log-driver)
  2399. __docker_complete_log_drivers
  2400. return
  2401. ;;
  2402. --log-opt)
  2403. __docker_complete_log_options
  2404. return
  2405. ;;
  2406. --network)
  2407. case "$cur" in
  2408. container:*)
  2409. __docker_complete_containers_all --cur "${cur#*:}"
  2410. ;;
  2411. *)
  2412. COMPREPLY=( $( compgen -W "$(__docker_plugins --type Network) $(__docker_networks) container:" -- "$cur") )
  2413. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  2414. __docker_nospace
  2415. fi
  2416. ;;
  2417. esac
  2418. return
  2419. ;;
  2420. --pid)
  2421. case "$cur" in
  2422. *:*)
  2423. __docker_complete_containers_running --cur "${cur#*:}"
  2424. ;;
  2425. *)
  2426. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  2427. if [ "$COMPREPLY" = "container:" ]; then
  2428. __docker_nospace
  2429. fi
  2430. ;;
  2431. esac
  2432. return
  2433. ;;
  2434. --runtime)
  2435. __docker_complete_runtimes
  2436. return
  2437. ;;
  2438. --security-opt)
  2439. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  2440. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  2441. __docker_nospace
  2442. fi
  2443. return
  2444. ;;
  2445. --storage-opt)
  2446. COMPREPLY=( $( compgen -W "size" -S = -- "$cur") )
  2447. __docker_nospace
  2448. return
  2449. ;;
  2450. --user|-u)
  2451. __docker_complete_user_group
  2452. return
  2453. ;;
  2454. --userns)
  2455. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  2456. return
  2457. ;;
  2458. --volume-driver)
  2459. __docker_complete_plugins --type Volume
  2460. return
  2461. ;;
  2462. --volumes-from)
  2463. __docker_complete_containers_all
  2464. return
  2465. ;;
  2466. $(__docker_to_extglob "$options_with_args") )
  2467. return
  2468. ;;
  2469. esac
  2470. case "$cur" in
  2471. -*)
  2472. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2473. ;;
  2474. *)
  2475. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2476. if [ $cword -eq $counter ]; then
  2477. __docker_complete_images
  2478. fi
  2479. ;;
  2480. esac
  2481. }
  2482. _docker_save() {
  2483. case "$prev" in
  2484. --output|-o)
  2485. _filedir
  2486. return
  2487. ;;
  2488. esac
  2489. case "$cur" in
  2490. -*)
  2491. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  2492. ;;
  2493. *)
  2494. __docker_complete_images
  2495. ;;
  2496. esac
  2497. }
  2498. _docker_search() {
  2499. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2500. case "$key" in
  2501. is-automated)
  2502. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2503. return
  2504. ;;
  2505. is-official)
  2506. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2507. return
  2508. ;;
  2509. esac
  2510. case "$prev" in
  2511. --filter|-f)
  2512. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  2513. __docker_nospace
  2514. return
  2515. ;;
  2516. --limit)
  2517. return
  2518. ;;
  2519. esac
  2520. case "$cur" in
  2521. -*)
  2522. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  2523. ;;
  2524. esac
  2525. }
  2526. _docker_start() {
  2527. __docker_complete_detach-keys && return
  2528. case "$cur" in
  2529. -*)
  2530. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  2531. ;;
  2532. *)
  2533. __docker_complete_containers_stopped
  2534. ;;
  2535. esac
  2536. }
  2537. _docker_stats() {
  2538. case "$prev" in
  2539. --format)
  2540. return
  2541. ;;
  2542. esac
  2543. case "$cur" in
  2544. -*)
  2545. COMPREPLY=( $( compgen -W "--all -a --format --help --no-stream" -- "$cur" ) )
  2546. ;;
  2547. *)
  2548. __docker_complete_containers_running
  2549. ;;
  2550. esac
  2551. }
  2552. _docker_stop() {
  2553. case "$prev" in
  2554. --time|-t)
  2555. return
  2556. ;;
  2557. esac
  2558. case "$cur" in
  2559. -*)
  2560. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2561. ;;
  2562. *)
  2563. __docker_complete_containers_running
  2564. ;;
  2565. esac
  2566. }
  2567. _docker_tag() {
  2568. case "$cur" in
  2569. -*)
  2570. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2571. ;;
  2572. *)
  2573. local counter=$(__docker_pos_first_nonflag)
  2574. if [ $cword -eq $counter ]; then
  2575. __docker_complete_image_repos_and_tags
  2576. return
  2577. fi
  2578. (( counter++ ))
  2579. if [ $cword -eq $counter ]; then
  2580. __docker_complete_image_repos_and_tags
  2581. return
  2582. fi
  2583. ;;
  2584. esac
  2585. }
  2586. _docker_unpause() {
  2587. case "$cur" in
  2588. -*)
  2589. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2590. ;;
  2591. *)
  2592. local counter=$(__docker_pos_first_nonflag)
  2593. if [ $cword -eq $counter ]; then
  2594. __docker_complete_containers_unpauseable
  2595. fi
  2596. ;;
  2597. esac
  2598. }
  2599. _docker_update() {
  2600. local options_with_args="
  2601. --blkio-weight
  2602. --cpu-period
  2603. --cpu-quota
  2604. --cpuset-cpus
  2605. --cpuset-mems
  2606. --cpu-shares -c
  2607. --kernel-memory
  2608. --memory -m
  2609. --memory-reservation
  2610. --memory-swap
  2611. --restart
  2612. "
  2613. local boolean_options="
  2614. --help
  2615. "
  2616. local all_options="$options_with_args $boolean_options"
  2617. __docker_complete_restart && return
  2618. case "$prev" in
  2619. $(__docker_to_extglob "$options_with_args") )
  2620. return
  2621. ;;
  2622. esac
  2623. case "$cur" in
  2624. -*)
  2625. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2626. ;;
  2627. *)
  2628. __docker_complete_containers_all
  2629. ;;
  2630. esac
  2631. }
  2632. _docker_top() {
  2633. case "$cur" in
  2634. -*)
  2635. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2636. ;;
  2637. *)
  2638. local counter=$(__docker_pos_first_nonflag)
  2639. if [ $cword -eq $counter ]; then
  2640. __docker_complete_containers_running
  2641. fi
  2642. ;;
  2643. esac
  2644. }
  2645. _docker_version() {
  2646. case "$cur" in
  2647. -*)
  2648. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2649. ;;
  2650. esac
  2651. }
  2652. _docker_volume_create() {
  2653. case "$prev" in
  2654. --driver|-d)
  2655. __docker_complete_plugins --type Volume
  2656. return
  2657. ;;
  2658. --label|--opt|-o)
  2659. return
  2660. ;;
  2661. esac
  2662. case "$cur" in
  2663. -*)
  2664. COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) )
  2665. ;;
  2666. esac
  2667. }
  2668. _docker_volume_inspect() {
  2669. case "$prev" in
  2670. --format|-f)
  2671. return
  2672. ;;
  2673. esac
  2674. case "$cur" in
  2675. -*)
  2676. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2677. ;;
  2678. *)
  2679. __docker_complete_volumes
  2680. ;;
  2681. esac
  2682. }
  2683. _docker_volume_ls() {
  2684. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2685. case "$key" in
  2686. dangling)
  2687. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  2688. return
  2689. ;;
  2690. driver)
  2691. __docker_complete_plugins --cur "${cur##*=}" --type Volume
  2692. return
  2693. ;;
  2694. name)
  2695. __docker_complete_volumes --cur "${cur##*=}"
  2696. return
  2697. ;;
  2698. esac
  2699. case "$prev" in
  2700. --filter|-f)
  2701. COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) )
  2702. __docker_nospace
  2703. return
  2704. ;;
  2705. --format)
  2706. return
  2707. ;;
  2708. esac
  2709. case "$cur" in
  2710. -*)
  2711. COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
  2712. ;;
  2713. esac
  2714. }
  2715. _docker_volume_rm() {
  2716. case "$cur" in
  2717. -*)
  2718. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2719. ;;
  2720. *)
  2721. __docker_complete_volumes
  2722. ;;
  2723. esac
  2724. }
  2725. _docker_volume() {
  2726. local subcommands="
  2727. create
  2728. inspect
  2729. ls
  2730. rm
  2731. "
  2732. __docker_subcommands "$subcommands" && return
  2733. case "$cur" in
  2734. -*)
  2735. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2736. ;;
  2737. *)
  2738. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2739. ;;
  2740. esac
  2741. }
  2742. _docker_wait() {
  2743. case "$cur" in
  2744. -*)
  2745. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2746. ;;
  2747. *)
  2748. __docker_complete_containers_all
  2749. ;;
  2750. esac
  2751. }
  2752. _docker() {
  2753. local previous_extglob_setting=$(shopt -p extglob)
  2754. shopt -s extglob
  2755. local commands=(
  2756. attach
  2757. build
  2758. commit
  2759. cp
  2760. create
  2761. daemon
  2762. diff
  2763. events
  2764. exec
  2765. export
  2766. history
  2767. images
  2768. import
  2769. info
  2770. inspect
  2771. kill
  2772. load
  2773. login
  2774. logout
  2775. logs
  2776. network
  2777. node
  2778. pause
  2779. port
  2780. ps
  2781. pull
  2782. push
  2783. rename
  2784. restart
  2785. rm
  2786. rmi
  2787. run
  2788. save
  2789. search
  2790. service
  2791. start
  2792. stats
  2793. stop
  2794. swarm
  2795. tag
  2796. top
  2797. unpause
  2798. update
  2799. version
  2800. volume
  2801. wait
  2802. )
  2803. # These options are valid as global options for all client commands
  2804. # and valid as command options for `docker daemon`
  2805. local global_boolean_options="
  2806. --debug -D
  2807. --tls
  2808. --tlsverify
  2809. "
  2810. local global_options_with_args="
  2811. --config
  2812. --host -H
  2813. --log-level -l
  2814. --tlscacert
  2815. --tlscert
  2816. --tlskey
  2817. "
  2818. local host config
  2819. COMPREPLY=()
  2820. local cur prev words cword
  2821. _get_comp_words_by_ref -n : cur prev words cword
  2822. local command='docker' command_pos=0 subcommand_pos
  2823. local counter=1
  2824. while [ $counter -lt $cword ]; do
  2825. case "${words[$counter]}" in
  2826. # save host so that completion can use custom daemon
  2827. --host|-H)
  2828. (( counter++ ))
  2829. host="${words[$counter]}"
  2830. ;;
  2831. # save config so that completion can use custom configuration directories
  2832. --config)
  2833. (( counter++ ))
  2834. config="${words[$counter]}"
  2835. ;;
  2836. $(__docker_to_extglob "$global_options_with_args") )
  2837. (( counter++ ))
  2838. ;;
  2839. -*)
  2840. ;;
  2841. =)
  2842. (( counter++ ))
  2843. ;;
  2844. *)
  2845. command="${words[$counter]}"
  2846. command_pos=$counter
  2847. break
  2848. ;;
  2849. esac
  2850. (( counter++ ))
  2851. done
  2852. local binary="${words[0]}"
  2853. if [[ $binary == ?(*/)dockerd ]] ; then
  2854. # for the dockerd binary, we reuse completion of `docker daemon`.
  2855. # dockerd does not have subcommands and global options.
  2856. command=daemon
  2857. command_pos=0
  2858. fi
  2859. local completions_func=_docker_${command}
  2860. declare -F $completions_func >/dev/null && $completions_func
  2861. eval "$previous_extglob_setting"
  2862. return 0
  2863. }
  2864. eval "$__docker_previous_extglob_setting"
  2865. unset __docker_previous_extglob_setting
  2866. complete -F _docker docker dockerd