docker 41 KB

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