docker 53 KB

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