docker 46 KB

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