docker 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339
  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. # Finds the position of the first word that is neither option nor an option's argument.
  166. # If there are options that require arguments, you should pass a glob describing those
  167. # options, e.g. "--option1|-o|--option2"
  168. # Use this function to restrict completions to exact positions after the argument list.
  169. __docker_pos_first_nonflag() {
  170. local argument_flags=$1
  171. local counter=$((${subcommand_pos:-${command_pos}} + 1))
  172. while [ $counter -le $cword ]; do
  173. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  174. (( counter++ ))
  175. # eat "=" in case of --option=arg syntax
  176. [ "${words[$counter]}" = "=" ] && (( counter++ ))
  177. else
  178. case "${words[$counter]}" in
  179. -*)
  180. ;;
  181. *)
  182. break
  183. ;;
  184. esac
  185. fi
  186. # Bash splits words at "=", retaining "=" as a word, examples:
  187. # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
  188. while [ "${words[$counter + 1]}" = "=" ] ; do
  189. counter=$(( counter + 2))
  190. done
  191. (( counter++ ))
  192. done
  193. echo $counter
  194. }
  195. # If we are currently completing the value of a map option (key=value)
  196. # which matches the extglob given as an argument, returns key.
  197. # This function is needed for key-specific completions.
  198. __docker_map_key_of_current_option() {
  199. local glob="$1"
  200. local key glob_pos
  201. if [ "$cur" = "=" ] ; then # key= case
  202. key="$prev"
  203. glob_pos=$((cword - 2))
  204. elif [[ $cur == *=* ]] ; then # key=value case (OSX)
  205. key=${cur%=*}
  206. glob_pos=$((cword - 1))
  207. elif [ "$prev" = "=" ] ; then
  208. key=${words[$cword - 2]} # key=value case
  209. glob_pos=$((cword - 3))
  210. else
  211. return
  212. fi
  213. [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax
  214. [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key"
  215. }
  216. # Returns the value of the first option matching option_glob.
  217. # Valid values for option_glob are option names like '--log-level' and
  218. # globs like '--log-level|-l'
  219. # Only positions between the command and the current word are considered.
  220. __docker_value_of_option() {
  221. local option_extglob=$(__docker_to_extglob "$1")
  222. local counter=$((command_pos + 1))
  223. while [ $counter -lt $cword ]; do
  224. case ${words[$counter]} in
  225. $option_extglob )
  226. echo ${words[$counter + 1]}
  227. break
  228. ;;
  229. esac
  230. (( counter++ ))
  231. done
  232. }
  233. # Transforms a multiline list of strings into a single line string
  234. # with the words separated by "|".
  235. # This is used to prepare arguments to __docker_pos_first_nonflag().
  236. __docker_to_alternatives() {
  237. local parts=( $1 )
  238. local IFS='|'
  239. echo "${parts[*]}"
  240. }
  241. # Transforms a multiline list of options into an extglob pattern
  242. # suitable for use in case statements.
  243. __docker_to_extglob() {
  244. local extglob=$( __docker_to_alternatives "$1" )
  245. echo "@($extglob)"
  246. }
  247. # Subcommand processing.
  248. # Locates the first occurrence of any of the subcommands contained in the
  249. # first argument. In case of a match, calls the corresponding completion
  250. # function and returns 0.
  251. # If no match is found, 1 is returned. The calling function can then
  252. # continue processing its completion.
  253. #
  254. # TODO if the preceding command has options that accept arguments and an
  255. # argument is equal ot one of the subcommands, this is falsely detected as
  256. # a match.
  257. __docker_subcommands() {
  258. local subcommands="$1"
  259. local counter=$(($command_pos + 1))
  260. while [ $counter -lt $cword ]; do
  261. case "${words[$counter]}" in
  262. $(__docker_to_extglob "$subcommands") )
  263. subcommand_pos=$counter
  264. local subcommand=${words[$counter]}
  265. local completions_func=_docker_${command}_${subcommand}
  266. declare -F $completions_func >/dev/null && $completions_func
  267. return 0
  268. ;;
  269. esac
  270. (( counter++ ))
  271. done
  272. return 1
  273. }
  274. # suppress trailing whitespace
  275. __docker_nospace() {
  276. # compopt is not available in ancient bash versions
  277. type compopt &>/dev/null && compopt -o nospace
  278. }
  279. __docker_complete_resolved_hostname() {
  280. command -v host >/dev/null 2>&1 || return
  281. COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
  282. }
  283. __docker_complete_capabilities() {
  284. # The list of capabilities is defined in types.go, ALL was added manually.
  285. COMPREPLY=( $( compgen -W "
  286. ALL
  287. AUDIT_CONTROL
  288. AUDIT_WRITE
  289. AUDIT_READ
  290. BLOCK_SUSPEND
  291. CHOWN
  292. DAC_OVERRIDE
  293. DAC_READ_SEARCH
  294. FOWNER
  295. FSETID
  296. IPC_LOCK
  297. IPC_OWNER
  298. KILL
  299. LEASE
  300. LINUX_IMMUTABLE
  301. MAC_ADMIN
  302. MAC_OVERRIDE
  303. MKNOD
  304. NET_ADMIN
  305. NET_BIND_SERVICE
  306. NET_BROADCAST
  307. NET_RAW
  308. SETFCAP
  309. SETGID
  310. SETPCAP
  311. SETUID
  312. SYS_ADMIN
  313. SYS_BOOT
  314. SYS_CHROOT
  315. SYSLOG
  316. SYS_MODULE
  317. SYS_NICE
  318. SYS_PACCT
  319. SYS_PTRACE
  320. SYS_RAWIO
  321. SYS_RESOURCE
  322. SYS_TIME
  323. SYS_TTY_CONFIG
  324. WAKE_ALARM
  325. " -- "$cur" ) )
  326. }
  327. __docker_complete_detach-keys() {
  328. case "$prev" in
  329. --detach-keys)
  330. case "$cur" in
  331. *,)
  332. COMPREPLY=( $( compgen -W "${cur}ctrl-" -- "$cur" ) )
  333. ;;
  334. *)
  335. COMPREPLY=( $( compgen -W "ctrl-" -- "$cur" ) )
  336. ;;
  337. esac
  338. __docker_nospace
  339. return
  340. ;;
  341. esac
  342. return 1
  343. }
  344. __docker_complete_isolation() {
  345. COMPREPLY=( $( compgen -W "default hyperv process" -- "$cur" ) )
  346. }
  347. __docker_complete_log_drivers() {
  348. COMPREPLY=( $( compgen -W "
  349. awslogs
  350. etwlogs
  351. fluentd
  352. gcplogs
  353. gelf
  354. journald
  355. json-file
  356. none
  357. splunk
  358. syslog
  359. " -- "$cur" ) )
  360. }
  361. __docker_complete_log_options() {
  362. # see docs/reference/logging/index.md
  363. local awslogs_options="awslogs-region awslogs-group awslogs-stream"
  364. local fluentd_options="env fluentd-address fluentd-async-connect fluentd-buffer-limit fluentd-retry-wait fluentd-max-retries labels tag"
  365. local gcplogs_options="env gcp-log-cmd gcp-project labels"
  366. local gelf_options="env gelf-address gelf-compression-level gelf-compression-type labels tag"
  367. local journald_options="env labels tag"
  368. local json_file_options="env labels max-file max-size"
  369. local syslog_options="syslog-address syslog-format syslog-tls-ca-cert syslog-tls-cert syslog-tls-key syslog-tls-skip-verify syslog-facility tag"
  370. local splunk_options="env labels splunk-caname splunk-capath splunk-index splunk-insecureskipverify splunk-source splunk-sourcetype splunk-token splunk-url tag"
  371. local all_options="$fluentd_options $gcplogs_options $gelf_options $journald_options $json_file_options $syslog_options $splunk_options"
  372. case $(__docker_value_of_option --log-driver) in
  373. '')
  374. COMPREPLY=( $( compgen -W "$all_options" -S = -- "$cur" ) )
  375. ;;
  376. awslogs)
  377. COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) )
  378. ;;
  379. fluentd)
  380. COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) )
  381. ;;
  382. gcplogs)
  383. COMPREPLY=( $( compgen -W "$gcplogs_options" -S = -- "$cur" ) )
  384. ;;
  385. gelf)
  386. COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) )
  387. ;;
  388. journald)
  389. COMPREPLY=( $( compgen -W "$journald_options" -S = -- "$cur" ) )
  390. ;;
  391. json-file)
  392. COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) )
  393. ;;
  394. syslog)
  395. COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) )
  396. ;;
  397. splunk)
  398. COMPREPLY=( $( compgen -W "$splunk_options" -S = -- "$cur" ) )
  399. ;;
  400. *)
  401. return
  402. ;;
  403. esac
  404. __docker_nospace
  405. }
  406. __docker_complete_log_driver_options() {
  407. local key=$(__docker_map_key_of_current_option '--log-opt')
  408. case "$key" in
  409. fluentd-async-connect)
  410. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  411. return
  412. ;;
  413. gelf-address)
  414. COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur##*=}" ) )
  415. __docker_nospace
  416. return
  417. ;;
  418. gelf-compression-level)
  419. COMPREPLY=( $( compgen -W "1 2 3 4 5 6 7 8 9" -- "${cur##*=}" ) )
  420. return
  421. ;;
  422. gelf-compression-type)
  423. COMPREPLY=( $( compgen -W "gzip none zlib" -- "${cur##*=}" ) )
  424. return
  425. ;;
  426. syslog-address)
  427. COMPREPLY=( $( compgen -W "tcp:// tcp+tls:// udp:// unix://" -- "${cur##*=}" ) )
  428. __docker_nospace
  429. __ltrim_colon_completions "${cur}"
  430. return
  431. ;;
  432. syslog-facility)
  433. COMPREPLY=( $( compgen -W "
  434. auth
  435. authpriv
  436. cron
  437. daemon
  438. ftp
  439. kern
  440. local0
  441. local1
  442. local2
  443. local3
  444. local4
  445. local5
  446. local6
  447. local7
  448. lpr
  449. mail
  450. news
  451. syslog
  452. user
  453. uucp
  454. " -- "${cur##*=}" ) )
  455. return
  456. ;;
  457. syslog-format)
  458. COMPREPLY=( $( compgen -W "rfc3164 rfc5424 rfc5424micro" -- "${cur##*=}" ) )
  459. return
  460. ;;
  461. syslog-tls-@(ca-cert|cert|key))
  462. _filedir
  463. return
  464. ;;
  465. syslog-tls-skip-verify)
  466. COMPREPLY=( $( compgen -W "true" -- "${cur##*=}" ) )
  467. return
  468. ;;
  469. splunk-url)
  470. COMPREPLY=( $( compgen -W "http:// https://" -- "${cur##*=}" ) )
  471. __docker_nospace
  472. __ltrim_colon_completions "${cur}"
  473. return
  474. ;;
  475. splunk-insecureskipverify)
  476. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  477. return
  478. ;;
  479. esac
  480. return 1
  481. }
  482. __docker_complete_log_levels() {
  483. COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) )
  484. }
  485. __docker_complete_restart() {
  486. case "$prev" in
  487. --restart)
  488. case "$cur" in
  489. on-failure:*)
  490. ;;
  491. *)
  492. COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") )
  493. ;;
  494. esac
  495. return
  496. ;;
  497. esac
  498. return 1
  499. }
  500. # a selection of the available signals that is most likely of interest in the
  501. # context of docker containers.
  502. __docker_complete_signals() {
  503. local signals=(
  504. SIGCONT
  505. SIGHUP
  506. SIGINT
  507. SIGKILL
  508. SIGQUIT
  509. SIGSTOP
  510. SIGTERM
  511. SIGUSR1
  512. SIGUSR2
  513. )
  514. COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) )
  515. }
  516. __docker_complete_user_group() {
  517. if [[ $cur == *:* ]] ; then
  518. COMPREPLY=( $(compgen -g -- "${cur#*:}") )
  519. else
  520. COMPREPLY=( $(compgen -u -S : -- "$cur") )
  521. __docker_nospace
  522. fi
  523. }
  524. # global options that may appear after the docker command
  525. _docker_docker() {
  526. local boolean_options="
  527. $global_boolean_options
  528. --help
  529. --version -v
  530. "
  531. case "$prev" in
  532. --config)
  533. _filedir -d
  534. return
  535. ;;
  536. --log-level|-l)
  537. __docker_complete_log_levels
  538. return
  539. ;;
  540. $(__docker_to_extglob "$global_options_with_args") )
  541. return
  542. ;;
  543. esac
  544. case "$cur" in
  545. -*)
  546. COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) )
  547. ;;
  548. *)
  549. local counter=$( __docker_pos_first_nonflag "$(__docker_to_extglob "$global_options_with_args")" )
  550. if [ $cword -eq $counter ]; then
  551. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  552. fi
  553. ;;
  554. esac
  555. }
  556. _docker_attach() {
  557. __docker_complete_detach-keys && return
  558. case "$cur" in
  559. -*)
  560. COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) )
  561. ;;
  562. *)
  563. local counter=$(__docker_pos_first_nonflag '--detach-keys')
  564. if [ $cword -eq $counter ]; then
  565. __docker_complete_containers_running
  566. fi
  567. ;;
  568. esac
  569. }
  570. _docker_build() {
  571. local options_with_args="
  572. --build-arg
  573. --cgroup-parent
  574. --cpuset-cpus
  575. --cpuset-mems
  576. --cpu-shares
  577. --cpu-period
  578. --cpu-quota
  579. --file -f
  580. --isolation
  581. --label
  582. --memory -m
  583. --memory-swap
  584. --shm-size
  585. --tag -t
  586. --ulimit
  587. "
  588. local boolean_options="
  589. --disable-content-trust=false
  590. --force-rm
  591. --help
  592. --no-cache
  593. --pull
  594. --quiet -q
  595. --rm
  596. "
  597. local all_options="$options_with_args $boolean_options"
  598. case "$prev" in
  599. --build-arg)
  600. COMPREPLY=( $( compgen -e -- "$cur" ) )
  601. __docker_nospace
  602. return
  603. ;;
  604. --file|-f)
  605. _filedir
  606. return
  607. ;;
  608. --isolation)
  609. __docker_complete_isolation
  610. return
  611. ;;
  612. --tag|-t)
  613. __docker_complete_image_repos_and_tags
  614. return
  615. ;;
  616. $(__docker_to_extglob "$options_with_args") )
  617. return
  618. ;;
  619. esac
  620. case "$cur" in
  621. -*)
  622. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  623. ;;
  624. *)
  625. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  626. if [ $cword -eq $counter ]; then
  627. _filedir -d
  628. fi
  629. ;;
  630. esac
  631. }
  632. _docker_commit() {
  633. case "$prev" in
  634. --author|-a|--change|-c|--message|-m)
  635. return
  636. ;;
  637. esac
  638. case "$cur" in
  639. -*)
  640. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) )
  641. ;;
  642. *)
  643. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  644. if [ $cword -eq $counter ]; then
  645. __docker_complete_containers_all
  646. return
  647. fi
  648. (( counter++ ))
  649. if [ $cword -eq $counter ]; then
  650. __docker_complete_image_repos_and_tags
  651. return
  652. fi
  653. ;;
  654. esac
  655. }
  656. _docker_cp() {
  657. case "$cur" in
  658. -*)
  659. COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) )
  660. ;;
  661. *)
  662. local counter=$(__docker_pos_first_nonflag)
  663. if [ $cword -eq $counter ]; then
  664. case "$cur" in
  665. *:)
  666. return
  667. ;;
  668. *)
  669. # combined container and filename completion
  670. _filedir
  671. local files=( ${COMPREPLY[@]} )
  672. __docker_complete_containers_all
  673. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  674. local containers=( ${COMPREPLY[@]} )
  675. COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) )
  676. if [[ "$COMPREPLY" == *: ]]; then
  677. __docker_nospace
  678. fi
  679. return
  680. ;;
  681. esac
  682. fi
  683. (( counter++ ))
  684. if [ $cword -eq $counter ]; then
  685. if [ -e "$prev" ]; then
  686. __docker_complete_containers_all
  687. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  688. __docker_nospace
  689. else
  690. _filedir
  691. fi
  692. return
  693. fi
  694. ;;
  695. esac
  696. }
  697. _docker_create() {
  698. _docker_run
  699. }
  700. _docker_daemon() {
  701. local boolean_options="
  702. $global_boolean_options
  703. --disable-legacy-registry
  704. --help
  705. --icc=false
  706. --ip-forward=false
  707. --ip-masq=false
  708. --iptables=false
  709. --ipv6
  710. --raw-logs
  711. --selinux-enabled
  712. --userland-proxy=false
  713. "
  714. local options_with_args="
  715. $global_options_with_args
  716. --api-cors-header
  717. --authorization-plugin
  718. --bip
  719. --bridge -b
  720. --cgroup-parent
  721. --cluster-advertise
  722. --cluster-store
  723. --cluster-store-opt
  724. --containerd
  725. --default-gateway
  726. --default-gateway-v6
  727. --default-ulimit
  728. --dns
  729. --dns-search
  730. --dns-opt
  731. --exec-opt
  732. --exec-root
  733. --fixed-cidr
  734. --fixed-cidr-v6
  735. --graph -g
  736. --group -G
  737. --insecure-registry
  738. --ip
  739. --label
  740. --log-driver
  741. --log-opt
  742. --max-concurrent-downloads
  743. --max-concurrent-uploads
  744. --mtu
  745. --pidfile -p
  746. --registry-mirror
  747. --storage-driver -s
  748. --storage-opt
  749. --userns-remap
  750. "
  751. __docker_complete_log_driver_options && return
  752. key=$(__docker_map_key_of_current_option '--cluster-store-opt')
  753. case "$key" in
  754. kv.*file)
  755. cur=${cur##*=}
  756. _filedir
  757. return
  758. ;;
  759. esac
  760. local key=$(__docker_map_key_of_current_option '--storage-opt')
  761. case "$key" in
  762. dm.@(blkdiscard|override_udev_sync_check|use_deferred_@(removal|deletion)))
  763. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  764. return
  765. ;;
  766. dm.fs)
  767. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) )
  768. return
  769. ;;
  770. dm.thinpooldev)
  771. cur=${cur##*=}
  772. _filedir
  773. return
  774. ;;
  775. esac
  776. case "$prev" in
  777. --authorization-plugin)
  778. __docker_complete_plugins Authorization
  779. return
  780. ;;
  781. --cluster-store)
  782. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  783. __docker_nospace
  784. return
  785. ;;
  786. --cluster-store-opt)
  787. COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) )
  788. __docker_nospace
  789. return
  790. ;;
  791. --exec-root|--graph|-g)
  792. _filedir -d
  793. return
  794. ;;
  795. --log-driver)
  796. __docker_complete_log_drivers
  797. return
  798. ;;
  799. --containerd|--pidfile|-p|--tlscacert|--tlscert|--tlskey)
  800. _filedir
  801. return
  802. ;;
  803. --storage-driver|-s)
  804. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  805. return
  806. ;;
  807. --storage-opt)
  808. local devicemapper_options="
  809. dm.basesize
  810. dm.blkdiscard
  811. dm.blocksize
  812. dm.fs
  813. dm.loopdatasize
  814. dm.loopmetadatasize
  815. dm.min_free_space
  816. dm.mkfsarg
  817. dm.mountopt
  818. dm.override_udev_sync_check
  819. dm.thinpooldev
  820. dm.use_deferred_deletion
  821. dm.use_deferred_removal
  822. "
  823. local zfs_options="zfs.fsname"
  824. case $(__docker_value_of_option '--storage-driver|-s') in
  825. '')
  826. COMPREPLY=( $( compgen -W "$devicemapper_options $zfs_options" -S = -- "$cur" ) )
  827. ;;
  828. devicemapper)
  829. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  830. ;;
  831. zfs)
  832. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  833. ;;
  834. *)
  835. return
  836. ;;
  837. esac
  838. __docker_nospace
  839. return
  840. ;;
  841. --log-level|-l)
  842. __docker_complete_log_levels
  843. return
  844. ;;
  845. --log-opt)
  846. __docker_complete_log_options
  847. return
  848. ;;
  849. --userns-remap)
  850. __docker_complete_user_group
  851. return
  852. ;;
  853. $(__docker_to_extglob "$options_with_args") )
  854. return
  855. ;;
  856. esac
  857. case "$cur" in
  858. -*)
  859. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  860. ;;
  861. esac
  862. }
  863. _docker_diff() {
  864. case "$cur" in
  865. -*)
  866. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  867. ;;
  868. *)
  869. local counter=$(__docker_pos_first_nonflag)
  870. if [ $cword -eq $counter ]; then
  871. __docker_complete_containers_all
  872. fi
  873. ;;
  874. esac
  875. }
  876. _docker_events() {
  877. local key=$(__docker_map_key_of_current_option '-f|--filter')
  878. case "$key" in
  879. container)
  880. cur="${cur##*=}"
  881. __docker_complete_containers_all
  882. return
  883. ;;
  884. daemon)
  885. local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
  886. COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
  887. return
  888. ;;
  889. event)
  890. COMPREPLY=( $( compgen -W "
  891. attach
  892. commit
  893. connect
  894. copy
  895. create
  896. delete
  897. destroy
  898. detach
  899. die
  900. disconnect
  901. exec_create
  902. exec_detach
  903. exec_start
  904. export
  905. import
  906. kill
  907. mount
  908. oom
  909. pause
  910. pull
  911. push
  912. reload
  913. rename
  914. resize
  915. restart
  916. start
  917. stop
  918. tag
  919. top
  920. unmount
  921. unpause
  922. untag
  923. update
  924. " -- "${cur##*=}" ) )
  925. return
  926. ;;
  927. image)
  928. cur="${cur##*=}"
  929. __docker_complete_images
  930. return
  931. ;;
  932. network)
  933. cur="${cur##*=}"
  934. __docker_complete_networks
  935. return
  936. ;;
  937. type)
  938. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  939. return
  940. ;;
  941. volume)
  942. cur="${cur##*=}"
  943. __docker_complete_volumes
  944. return
  945. ;;
  946. esac
  947. case "$prev" in
  948. --filter|-f)
  949. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  950. __docker_nospace
  951. return
  952. ;;
  953. --since|--until)
  954. return
  955. ;;
  956. esac
  957. case "$cur" in
  958. -*)
  959. COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) )
  960. ;;
  961. esac
  962. }
  963. _docker_exec() {
  964. __docker_complete_detach-keys && return
  965. case "$prev" in
  966. --user|-u)
  967. __docker_complete_user_group
  968. return
  969. ;;
  970. esac
  971. case "$cur" in
  972. -*)
  973. COMPREPLY=( $( compgen -W "--detach -d --detach-keys --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  974. ;;
  975. *)
  976. __docker_complete_containers_running
  977. ;;
  978. esac
  979. }
  980. _docker_export() {
  981. case "$cur" in
  982. -*)
  983. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  984. ;;
  985. *)
  986. local counter=$(__docker_pos_first_nonflag)
  987. if [ $cword -eq $counter ]; then
  988. __docker_complete_containers_all
  989. fi
  990. ;;
  991. esac
  992. }
  993. _docker_help() {
  994. local counter=$(__docker_pos_first_nonflag)
  995. if [ $cword -eq $counter ]; then
  996. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  997. fi
  998. }
  999. _docker_history() {
  1000. case "$cur" in
  1001. -*)
  1002. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  1003. ;;
  1004. *)
  1005. local counter=$(__docker_pos_first_nonflag)
  1006. if [ $cword -eq $counter ]; then
  1007. __docker_complete_images
  1008. fi
  1009. ;;
  1010. esac
  1011. }
  1012. _docker_images() {
  1013. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1014. case "$key" in
  1015. before)
  1016. cur="${cur##*=}"
  1017. __docker_complete_images
  1018. return
  1019. ;;
  1020. dangling)
  1021. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1022. return
  1023. ;;
  1024. label)
  1025. return
  1026. ;;
  1027. since)
  1028. cur="${cur##*=}"
  1029. __docker_complete_images
  1030. return
  1031. ;;
  1032. esac
  1033. case "$prev" in
  1034. --filter|-f)
  1035. COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) )
  1036. __docker_nospace
  1037. return
  1038. ;;
  1039. --format)
  1040. return
  1041. ;;
  1042. esac
  1043. case "$cur" in
  1044. -*)
  1045. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1046. ;;
  1047. =)
  1048. return
  1049. ;;
  1050. *)
  1051. __docker_complete_image_repos
  1052. ;;
  1053. esac
  1054. }
  1055. _docker_import() {
  1056. case "$prev" in
  1057. --change|-c|--message|-m)
  1058. return
  1059. ;;
  1060. esac
  1061. case "$cur" in
  1062. -*)
  1063. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1064. ;;
  1065. *)
  1066. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1067. if [ $cword -eq $counter ]; then
  1068. return
  1069. fi
  1070. (( counter++ ))
  1071. if [ $cword -eq $counter ]; then
  1072. __docker_complete_image_repos_and_tags
  1073. return
  1074. fi
  1075. ;;
  1076. esac
  1077. }
  1078. _docker_info() {
  1079. case "$cur" in
  1080. -*)
  1081. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1082. ;;
  1083. esac
  1084. }
  1085. _docker_inspect() {
  1086. case "$prev" in
  1087. --format|-f)
  1088. return
  1089. ;;
  1090. --type)
  1091. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  1092. return
  1093. ;;
  1094. esac
  1095. case "$cur" in
  1096. -*)
  1097. COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) )
  1098. ;;
  1099. *)
  1100. case $(__docker_value_of_option --type) in
  1101. '')
  1102. __docker_complete_containers_and_images
  1103. ;;
  1104. container)
  1105. __docker_complete_containers_all
  1106. ;;
  1107. image)
  1108. __docker_complete_images
  1109. ;;
  1110. esac
  1111. esac
  1112. }
  1113. _docker_kill() {
  1114. case "$prev" in
  1115. --signal|-s)
  1116. __docker_complete_signals
  1117. return
  1118. ;;
  1119. esac
  1120. case "$cur" in
  1121. -*)
  1122. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  1123. ;;
  1124. *)
  1125. __docker_complete_containers_running
  1126. ;;
  1127. esac
  1128. }
  1129. _docker_load() {
  1130. case "$prev" in
  1131. --input|-i)
  1132. _filedir
  1133. return
  1134. ;;
  1135. esac
  1136. case "$cur" in
  1137. -*)
  1138. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1139. ;;
  1140. esac
  1141. }
  1142. _docker_login() {
  1143. case "$prev" in
  1144. --password|-p|--username|-u)
  1145. return
  1146. ;;
  1147. esac
  1148. case "$cur" in
  1149. -*)
  1150. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  1151. ;;
  1152. esac
  1153. }
  1154. _docker_logout() {
  1155. case "$cur" in
  1156. -*)
  1157. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1158. ;;
  1159. esac
  1160. }
  1161. _docker_logs() {
  1162. case "$prev" in
  1163. --since|--tail)
  1164. return
  1165. ;;
  1166. esac
  1167. case "$cur" in
  1168. -*)
  1169. COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  1170. ;;
  1171. *)
  1172. local counter=$(__docker_pos_first_nonflag '--tail')
  1173. if [ $cword -eq $counter ]; then
  1174. __docker_complete_containers_all
  1175. fi
  1176. ;;
  1177. esac
  1178. }
  1179. _docker_network_connect() {
  1180. local options_with_args="
  1181. --alias
  1182. --ip
  1183. --ip6
  1184. --link
  1185. "
  1186. local boolean_options="
  1187. --help
  1188. "
  1189. case "$prev" in
  1190. --link)
  1191. case "$cur" in
  1192. *:*)
  1193. ;;
  1194. *)
  1195. __docker_complete_containers_running
  1196. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1197. __docker_nospace
  1198. ;;
  1199. esac
  1200. return
  1201. ;;
  1202. $(__docker_to_extglob "$options_with_args") )
  1203. return
  1204. ;;
  1205. esac
  1206. case "$cur" in
  1207. -*)
  1208. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1209. ;;
  1210. *)
  1211. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1212. if [ $cword -eq $counter ]; then
  1213. __docker_complete_networks
  1214. elif [ $cword -eq $(($counter + 1)) ]; then
  1215. __docker_complete_containers_all
  1216. fi
  1217. ;;
  1218. esac
  1219. }
  1220. _docker_network_create() {
  1221. case "$prev" in
  1222. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  1223. return
  1224. ;;
  1225. --ipam-driver)
  1226. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  1227. return
  1228. ;;
  1229. --driver|-d)
  1230. local plugins=" $(__docker_plugins Network) "
  1231. # remove drivers that allow one instance only
  1232. plugins=${plugins/ host / }
  1233. plugins=${plugins/ null / }
  1234. COMPREPLY=( $(compgen -W "$plugins" -- "$cur") )
  1235. return
  1236. ;;
  1237. --label)
  1238. return
  1239. ;;
  1240. esac
  1241. case "$cur" in
  1242. -*)
  1243. COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  1244. ;;
  1245. esac
  1246. }
  1247. _docker_network_disconnect() {
  1248. case "$cur" in
  1249. -*)
  1250. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1251. ;;
  1252. *)
  1253. local counter=$(__docker_pos_first_nonflag)
  1254. if [ $cword -eq $counter ]; then
  1255. __docker_complete_networks
  1256. elif [ $cword -eq $(($counter + 1)) ]; then
  1257. __docker_complete_containers_in_network "$prev"
  1258. fi
  1259. ;;
  1260. esac
  1261. }
  1262. _docker_network_inspect() {
  1263. case "$prev" in
  1264. --format|-f)
  1265. return
  1266. ;;
  1267. esac
  1268. case "$cur" in
  1269. -*)
  1270. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1271. ;;
  1272. *)
  1273. __docker_complete_networks
  1274. esac
  1275. }
  1276. _docker_network_ls() {
  1277. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1278. case "$key" in
  1279. driver)
  1280. local plugins=" $(__docker_plugins Network) "
  1281. COMPREPLY=( $(compgen -W "$plugins" -- "${cur##*=}") )
  1282. return
  1283. ;;
  1284. id)
  1285. cur="${cur##*=}"
  1286. __docker_complete_network_ids
  1287. return
  1288. ;;
  1289. name)
  1290. cur="${cur##*=}"
  1291. __docker_complete_network_names
  1292. return
  1293. ;;
  1294. type)
  1295. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  1296. return
  1297. ;;
  1298. esac
  1299. case "$prev" in
  1300. --filter|-f)
  1301. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  1302. __docker_nospace
  1303. return
  1304. ;;
  1305. esac
  1306. case "$cur" in
  1307. -*)
  1308. COMPREPLY=( $( compgen -W "--filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
  1309. ;;
  1310. esac
  1311. }
  1312. _docker_network_rm() {
  1313. case "$cur" in
  1314. -*)
  1315. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1316. ;;
  1317. *)
  1318. __docker_complete_networks type=custom
  1319. esac
  1320. }
  1321. _docker_network() {
  1322. local subcommands="
  1323. connect
  1324. create
  1325. disconnect
  1326. inspect
  1327. ls
  1328. rm
  1329. "
  1330. __docker_subcommands "$subcommands" && return
  1331. case "$cur" in
  1332. -*)
  1333. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1334. ;;
  1335. *)
  1336. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1337. ;;
  1338. esac
  1339. }
  1340. _docker_pause() {
  1341. case "$cur" in
  1342. -*)
  1343. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1344. ;;
  1345. *)
  1346. local counter=$(__docker_pos_first_nonflag)
  1347. if [ $cword -eq $counter ]; then
  1348. __docker_complete_containers_pauseable
  1349. fi
  1350. ;;
  1351. esac
  1352. }
  1353. _docker_port() {
  1354. case "$cur" in
  1355. -*)
  1356. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1357. ;;
  1358. *)
  1359. local counter=$(__docker_pos_first_nonflag)
  1360. if [ $cword -eq $counter ]; then
  1361. __docker_complete_containers_all
  1362. fi
  1363. ;;
  1364. esac
  1365. }
  1366. _docker_ps() {
  1367. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1368. case "$key" in
  1369. ancestor)
  1370. cur="${cur##*=}"
  1371. __docker_complete_images
  1372. return
  1373. ;;
  1374. before)
  1375. cur="${cur##*=}"
  1376. __docker_complete_containers_all
  1377. return
  1378. ;;
  1379. id)
  1380. cur="${cur##*=}"
  1381. __docker_complete_container_ids
  1382. return
  1383. ;;
  1384. name)
  1385. cur="${cur##*=}"
  1386. __docker_complete_container_names
  1387. return
  1388. ;;
  1389. since)
  1390. cur="${cur##*=}"
  1391. __docker_complete_containers_all
  1392. return
  1393. ;;
  1394. status)
  1395. COMPREPLY=( $( compgen -W "created dead exited paused restarting running" -- "${cur##*=}" ) )
  1396. return
  1397. ;;
  1398. volume)
  1399. cur="${cur##*=}"
  1400. __docker_complete_volumes
  1401. return
  1402. ;;
  1403. esac
  1404. case "$prev" in
  1405. --filter|-f)
  1406. COMPREPLY=( $( compgen -S = -W "ancestor before exited id label name since status volume" -- "$cur" ) )
  1407. __docker_nospace
  1408. return
  1409. ;;
  1410. --format|-n)
  1411. return
  1412. ;;
  1413. esac
  1414. case "$cur" in
  1415. -*)
  1416. COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --latest -l -n --no-trunc --quiet -q --size -s" -- "$cur" ) )
  1417. ;;
  1418. esac
  1419. }
  1420. _docker_pull() {
  1421. case "$cur" in
  1422. -*)
  1423. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  1424. ;;
  1425. *)
  1426. local counter=$(__docker_pos_first_nonflag)
  1427. if [ $cword -eq $counter ]; then
  1428. for arg in "${COMP_WORDS[@]}"; do
  1429. case "$arg" in
  1430. --all-tags|-a)
  1431. __docker_complete_image_repos
  1432. return
  1433. ;;
  1434. esac
  1435. done
  1436. __docker_complete_image_repos_and_tags
  1437. fi
  1438. ;;
  1439. esac
  1440. }
  1441. _docker_push() {
  1442. case "$cur" in
  1443. -*)
  1444. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  1445. ;;
  1446. *)
  1447. local counter=$(__docker_pos_first_nonflag)
  1448. if [ $cword -eq $counter ]; then
  1449. __docker_complete_image_repos_and_tags
  1450. fi
  1451. ;;
  1452. esac
  1453. }
  1454. _docker_rename() {
  1455. case "$cur" in
  1456. -*)
  1457. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1458. ;;
  1459. *)
  1460. local counter=$(__docker_pos_first_nonflag)
  1461. if [ $cword -eq $counter ]; then
  1462. __docker_complete_containers_all
  1463. fi
  1464. ;;
  1465. esac
  1466. }
  1467. _docker_restart() {
  1468. case "$prev" in
  1469. --time|-t)
  1470. return
  1471. ;;
  1472. esac
  1473. case "$cur" in
  1474. -*)
  1475. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1476. ;;
  1477. *)
  1478. __docker_complete_containers_all
  1479. ;;
  1480. esac
  1481. }
  1482. _docker_rm() {
  1483. case "$cur" in
  1484. -*)
  1485. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  1486. ;;
  1487. *)
  1488. for arg in "${COMP_WORDS[@]}"; do
  1489. case "$arg" in
  1490. --force|-f)
  1491. __docker_complete_containers_all
  1492. return
  1493. ;;
  1494. esac
  1495. done
  1496. __docker_complete_containers_stopped
  1497. ;;
  1498. esac
  1499. }
  1500. _docker_rmi() {
  1501. case "$cur" in
  1502. -*)
  1503. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  1504. ;;
  1505. *)
  1506. __docker_complete_images
  1507. ;;
  1508. esac
  1509. }
  1510. _docker_run() {
  1511. local options_with_args="
  1512. --add-host
  1513. --attach -a
  1514. --blkio-weight
  1515. --blkio-weight-device
  1516. --cap-add
  1517. --cap-drop
  1518. --cgroup-parent
  1519. --cidfile
  1520. --cpu-period
  1521. --cpu-quota
  1522. --cpuset-cpus
  1523. --cpuset-mems
  1524. --cpu-shares
  1525. --device
  1526. --device-read-bps
  1527. --device-read-iops
  1528. --device-write-bps
  1529. --device-write-iops
  1530. --dns
  1531. --dns-opt
  1532. --dns-search
  1533. --entrypoint
  1534. --env -e
  1535. --env-file
  1536. --expose
  1537. --group-add
  1538. --hostname -h
  1539. --ip
  1540. --ip6
  1541. --ipc
  1542. --isolation
  1543. --kernel-memory
  1544. --label-file
  1545. --label -l
  1546. --link
  1547. --log-driver
  1548. --log-opt
  1549. --mac-address
  1550. --memory -m
  1551. --memory-swap
  1552. --memory-swappiness
  1553. --memory-reservation
  1554. --name
  1555. --net
  1556. --net-alias
  1557. --oom-score-adj
  1558. --pid
  1559. --pids-limit
  1560. --publish -p
  1561. --restart
  1562. --security-opt
  1563. --shm-size
  1564. --stop-signal
  1565. --tmpfs
  1566. --sysctl
  1567. --ulimit
  1568. --user -u
  1569. --userns
  1570. --uts
  1571. --volume-driver
  1572. --volumes-from
  1573. --volume -v
  1574. --workdir -w
  1575. "
  1576. local boolean_options="
  1577. --disable-content-trust=false
  1578. --help
  1579. --interactive -i
  1580. --oom-kill-disable
  1581. --privileged
  1582. --publish-all -P
  1583. --read-only
  1584. --tty -t
  1585. "
  1586. if [ "$command" = "run" ] ; then
  1587. options_with_args="$options_with_args
  1588. --detach-keys
  1589. --health-cmd
  1590. --health-interval
  1591. --health-retries
  1592. --health-timeout
  1593. "
  1594. boolean_options="$boolean_options
  1595. --detach -d
  1596. --no-healthcheck
  1597. --rm
  1598. --sig-proxy=false
  1599. "
  1600. __docker_complete_detach-keys && return
  1601. fi
  1602. local all_options="$options_with_args $boolean_options"
  1603. __docker_complete_log_driver_options && return
  1604. __docker_complete_restart && return
  1605. local key=$(__docker_map_key_of_current_option '--security-opt')
  1606. case "$key" in
  1607. label)
  1608. [[ $cur == *: ]] && return
  1609. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  1610. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  1611. __docker_nospace
  1612. fi
  1613. return
  1614. ;;
  1615. seccomp)
  1616. local cur=${cur##*=}
  1617. _filedir
  1618. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  1619. return
  1620. ;;
  1621. esac
  1622. case "$prev" in
  1623. --add-host)
  1624. case "$cur" in
  1625. *:)
  1626. __docker_complete_resolved_hostname
  1627. return
  1628. ;;
  1629. esac
  1630. ;;
  1631. --attach|-a)
  1632. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  1633. return
  1634. ;;
  1635. --cap-add|--cap-drop)
  1636. __docker_complete_capabilities
  1637. return
  1638. ;;
  1639. --cidfile|--env-file|--label-file)
  1640. _filedir
  1641. return
  1642. ;;
  1643. --device|--tmpfs|--volume|-v)
  1644. case "$cur" in
  1645. *:*)
  1646. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  1647. ;;
  1648. '')
  1649. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  1650. __docker_nospace
  1651. ;;
  1652. /*)
  1653. _filedir
  1654. __docker_nospace
  1655. ;;
  1656. esac
  1657. return
  1658. ;;
  1659. --env|-e)
  1660. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1661. __docker_nospace
  1662. return
  1663. ;;
  1664. --ipc)
  1665. case "$cur" in
  1666. *:*)
  1667. cur="${cur#*:}"
  1668. __docker_complete_containers_running
  1669. ;;
  1670. *)
  1671. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1672. if [ "$COMPREPLY" = "container:" ]; then
  1673. __docker_nospace
  1674. fi
  1675. ;;
  1676. esac
  1677. return
  1678. ;;
  1679. --isolation)
  1680. __docker_complete_isolation
  1681. return
  1682. ;;
  1683. --link)
  1684. case "$cur" in
  1685. *:*)
  1686. ;;
  1687. *)
  1688. __docker_complete_containers_running
  1689. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1690. __docker_nospace
  1691. ;;
  1692. esac
  1693. return
  1694. ;;
  1695. --log-driver)
  1696. __docker_complete_log_drivers
  1697. return
  1698. ;;
  1699. --log-opt)
  1700. __docker_complete_log_options
  1701. return
  1702. ;;
  1703. --net)
  1704. case "$cur" in
  1705. container:*)
  1706. local cur=${cur#*:}
  1707. __docker_complete_containers_all
  1708. ;;
  1709. *)
  1710. COMPREPLY=( $( compgen -W "$(__docker_plugins Network) $(__docker_networks) container:" -- "$cur") )
  1711. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1712. __docker_nospace
  1713. fi
  1714. ;;
  1715. esac
  1716. return
  1717. ;;
  1718. --pid)
  1719. case "$cur" in
  1720. *:*)
  1721. cur="${cur#*:}"
  1722. __docker_complete_containers_running
  1723. ;;
  1724. *)
  1725. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1726. if [ "$COMPREPLY" = "container:" ]; then
  1727. __docker_nospace
  1728. fi
  1729. ;;
  1730. esac
  1731. return
  1732. ;;
  1733. --security-opt)
  1734. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  1735. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  1736. __docker_nospace
  1737. fi
  1738. return
  1739. ;;
  1740. --user|-u)
  1741. __docker_complete_user_group
  1742. return
  1743. ;;
  1744. --userns)
  1745. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  1746. return
  1747. ;;
  1748. --volume-driver)
  1749. __docker_complete_plugins Volume
  1750. return
  1751. ;;
  1752. --volumes-from)
  1753. __docker_complete_containers_all
  1754. return
  1755. ;;
  1756. $(__docker_to_extglob "$options_with_args") )
  1757. return
  1758. ;;
  1759. esac
  1760. case "$cur" in
  1761. -*)
  1762. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1763. ;;
  1764. *)
  1765. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1766. if [ $cword -eq $counter ]; then
  1767. __docker_complete_images
  1768. fi
  1769. ;;
  1770. esac
  1771. }
  1772. _docker_save() {
  1773. case "$prev" in
  1774. --output|-o)
  1775. _filedir
  1776. return
  1777. ;;
  1778. esac
  1779. case "$cur" in
  1780. -*)
  1781. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  1782. ;;
  1783. *)
  1784. __docker_complete_images
  1785. ;;
  1786. esac
  1787. }
  1788. _docker_search() {
  1789. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1790. case "$key" in
  1791. is-automated)
  1792. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1793. return
  1794. ;;
  1795. is-official)
  1796. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1797. return
  1798. ;;
  1799. esac
  1800. case "$prev" in
  1801. --filter|-f)
  1802. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  1803. __docker_nospace
  1804. return
  1805. ;;
  1806. --limit)
  1807. return
  1808. ;;
  1809. esac
  1810. case "$cur" in
  1811. -*)
  1812. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  1813. ;;
  1814. esac
  1815. }
  1816. _docker_start() {
  1817. __docker_complete_detach-keys && return
  1818. case "$cur" in
  1819. -*)
  1820. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  1821. ;;
  1822. *)
  1823. __docker_complete_containers_stopped
  1824. ;;
  1825. esac
  1826. }
  1827. _docker_stats() {
  1828. case "$cur" in
  1829. -*)
  1830. COMPREPLY=( $( compgen -W "--all -a --help --no-stream" -- "$cur" ) )
  1831. ;;
  1832. *)
  1833. __docker_complete_containers_running
  1834. ;;
  1835. esac
  1836. }
  1837. _docker_stop() {
  1838. case "$prev" in
  1839. --time|-t)
  1840. return
  1841. ;;
  1842. esac
  1843. case "$cur" in
  1844. -*)
  1845. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1846. ;;
  1847. *)
  1848. __docker_complete_containers_running
  1849. ;;
  1850. esac
  1851. }
  1852. _docker_tag() {
  1853. case "$cur" in
  1854. -*)
  1855. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1856. ;;
  1857. *)
  1858. local counter=$(__docker_pos_first_nonflag)
  1859. if [ $cword -eq $counter ]; then
  1860. __docker_complete_image_repos_and_tags
  1861. return
  1862. fi
  1863. (( counter++ ))
  1864. if [ $cword -eq $counter ]; then
  1865. __docker_complete_image_repos_and_tags
  1866. return
  1867. fi
  1868. ;;
  1869. esac
  1870. }
  1871. _docker_unpause() {
  1872. case "$cur" in
  1873. -*)
  1874. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1875. ;;
  1876. *)
  1877. local counter=$(__docker_pos_first_nonflag)
  1878. if [ $cword -eq $counter ]; then
  1879. __docker_complete_containers_unpauseable
  1880. fi
  1881. ;;
  1882. esac
  1883. }
  1884. _docker_update() {
  1885. local options_with_args="
  1886. --blkio-weight
  1887. --cpu-period
  1888. --cpu-quota
  1889. --cpuset-cpus
  1890. --cpuset-mems
  1891. --cpu-shares
  1892. --kernel-memory
  1893. --memory -m
  1894. --memory-reservation
  1895. --memory-swap
  1896. --restart
  1897. "
  1898. local boolean_options="
  1899. --help
  1900. "
  1901. local all_options="$options_with_args $boolean_options"
  1902. __docker_complete_restart && return
  1903. case "$prev" in
  1904. $(__docker_to_extglob "$options_with_args") )
  1905. return
  1906. ;;
  1907. esac
  1908. case "$cur" in
  1909. -*)
  1910. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1911. ;;
  1912. *)
  1913. __docker_complete_containers_all
  1914. ;;
  1915. esac
  1916. }
  1917. _docker_top() {
  1918. case "$cur" in
  1919. -*)
  1920. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1921. ;;
  1922. *)
  1923. local counter=$(__docker_pos_first_nonflag)
  1924. if [ $cword -eq $counter ]; then
  1925. __docker_complete_containers_running
  1926. fi
  1927. ;;
  1928. esac
  1929. }
  1930. _docker_version() {
  1931. case "$cur" in
  1932. -*)
  1933. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1934. ;;
  1935. esac
  1936. }
  1937. _docker_volume_create() {
  1938. case "$prev" in
  1939. --driver|-d)
  1940. __docker_complete_plugins Volume
  1941. return
  1942. ;;
  1943. --label|--name|--opt|-o)
  1944. return
  1945. ;;
  1946. esac
  1947. case "$cur" in
  1948. -*)
  1949. COMPREPLY=( $( compgen -W "--driver -d --help --label --name --opt -o" -- "$cur" ) )
  1950. ;;
  1951. esac
  1952. }
  1953. _docker_volume_inspect() {
  1954. case "$prev" in
  1955. --format|-f)
  1956. return
  1957. ;;
  1958. esac
  1959. case "$cur" in
  1960. -*)
  1961. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1962. ;;
  1963. *)
  1964. __docker_complete_volumes
  1965. ;;
  1966. esac
  1967. }
  1968. _docker_volume_ls() {
  1969. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1970. case "$key" in
  1971. dangling)
  1972. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  1973. return
  1974. ;;
  1975. driver)
  1976. cur=${cur##*=}
  1977. __docker_complete_plugins Volume
  1978. return
  1979. ;;
  1980. name)
  1981. cur=${cur##*=}
  1982. __docker_complete_volumes
  1983. return
  1984. ;;
  1985. esac
  1986. case "$prev" in
  1987. --filter|-f)
  1988. COMPREPLY=( $( compgen -S = -W "dangling driver name" -- "$cur" ) )
  1989. __docker_nospace
  1990. return
  1991. ;;
  1992. esac
  1993. case "$cur" in
  1994. -*)
  1995. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1996. ;;
  1997. esac
  1998. }
  1999. _docker_volume_rm() {
  2000. case "$cur" in
  2001. -*)
  2002. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2003. ;;
  2004. *)
  2005. __docker_complete_volumes
  2006. ;;
  2007. esac
  2008. }
  2009. _docker_volume() {
  2010. local subcommands="
  2011. create
  2012. inspect
  2013. ls
  2014. rm
  2015. "
  2016. __docker_subcommands "$subcommands" && return
  2017. case "$cur" in
  2018. -*)
  2019. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2020. ;;
  2021. *)
  2022. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2023. ;;
  2024. esac
  2025. }
  2026. _docker_wait() {
  2027. case "$cur" in
  2028. -*)
  2029. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2030. ;;
  2031. *)
  2032. __docker_complete_containers_all
  2033. ;;
  2034. esac
  2035. }
  2036. _docker() {
  2037. local previous_extglob_setting=$(shopt -p extglob)
  2038. shopt -s extglob
  2039. local commands=(
  2040. attach
  2041. build
  2042. commit
  2043. cp
  2044. create
  2045. daemon
  2046. diff
  2047. events
  2048. exec
  2049. export
  2050. history
  2051. images
  2052. import
  2053. info
  2054. inspect
  2055. kill
  2056. load
  2057. login
  2058. logout
  2059. logs
  2060. network
  2061. pause
  2062. port
  2063. ps
  2064. pull
  2065. push
  2066. rename
  2067. restart
  2068. rm
  2069. rmi
  2070. run
  2071. save
  2072. search
  2073. start
  2074. stats
  2075. stop
  2076. tag
  2077. top
  2078. unpause
  2079. update
  2080. version
  2081. volume
  2082. wait
  2083. )
  2084. # These options are valid as global options for all client commands
  2085. # and valid as command options for `docker daemon`
  2086. local global_boolean_options="
  2087. --debug -D
  2088. --tls
  2089. --tlsverify
  2090. "
  2091. local global_options_with_args="
  2092. --config
  2093. --host -H
  2094. --log-level -l
  2095. --tlscacert
  2096. --tlscert
  2097. --tlskey
  2098. "
  2099. local host config
  2100. COMPREPLY=()
  2101. local cur prev words cword
  2102. _get_comp_words_by_ref -n : cur prev words cword
  2103. local command='docker' command_pos=0 subcommand_pos
  2104. local counter=1
  2105. while [ $counter -lt $cword ]; do
  2106. case "${words[$counter]}" in
  2107. # save host so that completion can use custom daemon
  2108. --host|-H)
  2109. (( counter++ ))
  2110. host="${words[$counter]}"
  2111. ;;
  2112. # save config so that completion can use custom configuration directories
  2113. --config)
  2114. (( counter++ ))
  2115. config="${words[$counter]}"
  2116. ;;
  2117. $(__docker_to_extglob "$global_options_with_args") )
  2118. (( counter++ ))
  2119. ;;
  2120. -*)
  2121. ;;
  2122. =)
  2123. (( counter++ ))
  2124. ;;
  2125. *)
  2126. command="${words[$counter]}"
  2127. command_pos=$counter
  2128. break
  2129. ;;
  2130. esac
  2131. (( counter++ ))
  2132. done
  2133. local binary="${words[0]}"
  2134. if [[ $binary == dockerd ]] ; then
  2135. # for the dockerd binary, we reuse completion of `docker daemon`.
  2136. # dockerd does not have subcommands and global options.
  2137. command=daemon
  2138. command_pos=0
  2139. fi
  2140. local completions_func=_docker_${command}
  2141. declare -F $completions_func >/dev/null && $completions_func
  2142. eval "$previous_extglob_setting"
  2143. return 0
  2144. }
  2145. eval "$__docker_previous_extglob_setting"
  2146. unset __docker_previous_extglob_setting
  2147. complete -F _docker docker dockerd