docker 58 KB

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