docker 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844
  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. # You can tailor completion for the "events", "history", "inspect", "run",
  21. # "rmi" and "save" commands by settings the following environment
  22. # variables:
  23. #
  24. # DOCKER_COMPLETION_SHOW_IMAGE_IDS
  25. # "none" - Show names only (default)
  26. # "non-intermediate" - Show names and ids, but omit intermediate image IDs
  27. # "all" - Show names and ids, including intermediate image IDs
  28. #
  29. # DOCKER_COMPLETION_SHOW_TAGS
  30. # "yes" - include tags in completion options (default)
  31. # "no" - don't include tags in completion options
  32. #
  33. # Note:
  34. # Currently, the completions will not work if the docker daemon is not
  35. # bound to the default communication port/socket
  36. # If the docker daemon is using a unix socket for communication your user
  37. # must have access to the socket for the completions to function correctly
  38. #
  39. # Note for developers:
  40. # Please arrange options sorted alphabetically by long name with the short
  41. # options immediately following their corresponding long form.
  42. # This order should be applied to lists, alternatives and code blocks.
  43. __docker_q() {
  44. docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@"
  45. }
  46. __docker_containers_all() {
  47. local IFS=$'\n'
  48. local containers=( $(__docker_q ps -aq --no-trunc) )
  49. if [ "$1" ]; then
  50. containers=( $(__docker_q inspect --format "{{if $1}}{{.Id}}{{end}}" "${containers[@]}") )
  51. fi
  52. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  53. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  54. unset IFS
  55. COMPREPLY=( $(compgen -W "${names[*]} ${containers[*]}" -- "$cur") )
  56. }
  57. __docker_containers_running() {
  58. __docker_containers_all '.State.Running'
  59. }
  60. __docker_containers_stopped() {
  61. __docker_containers_all 'not .State.Running'
  62. }
  63. __docker_containers_pauseable() {
  64. __docker_containers_all 'and .State.Running (not .State.Paused)'
  65. }
  66. __docker_containers_unpauseable() {
  67. __docker_containers_all '.State.Paused'
  68. }
  69. __docker_container_names() {
  70. local containers=( $(__docker_q ps -aq --no-trunc) )
  71. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  72. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  73. COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") )
  74. }
  75. __docker_container_ids() {
  76. local containers=( $(__docker_q ps -aq) )
  77. COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") )
  78. }
  79. __docker_images() {
  80. local images_args=""
  81. case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
  82. all)
  83. images_args="--no-trunc -a"
  84. ;;
  85. non-intermediate)
  86. images_args="--no-trunc"
  87. ;;
  88. esac
  89. local repo_print_command
  90. if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then
  91. repo_print_command='print $1; print $1":"$2'
  92. else
  93. repo_print_command='print $1'
  94. fi
  95. local awk_script
  96. case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
  97. all|non-intermediate)
  98. awk_script='NR>1 { print $3; if ($1 != "<none>") { '"$repo_print_command"' } }'
  99. ;;
  100. none|*)
  101. awk_script='NR>1 && $1 != "<none>" { '"$repo_print_command"' }'
  102. ;;
  103. esac
  104. local images=$(__docker_q images $images_args | awk "$awk_script")
  105. COMPREPLY=( $(compgen -W "$images" -- "$cur") )
  106. __ltrim_colon_completions "$cur"
  107. }
  108. __docker_image_repos() {
  109. local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')"
  110. COMPREPLY=( $(compgen -W "$repos" -- "$cur") )
  111. }
  112. __docker_image_repos_and_tags() {
  113. local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')"
  114. COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") )
  115. __ltrim_colon_completions "$cur"
  116. }
  117. __docker_containers_and_images() {
  118. __docker_containers_all
  119. local containers=( "${COMPREPLY[@]}" )
  120. __docker_images
  121. COMPREPLY+=( "${containers[@]}" )
  122. }
  123. __docker_networks() {
  124. COMPREPLY=( $(compgen -W "$(__docker_q network ls | awk 'NR>1 {print $2}')" -- "$cur") )
  125. }
  126. __docker_volumes() {
  127. COMPREPLY=( $(compgen -W "$(__docker_q volume ls -q)" -- "$cur") )
  128. }
  129. # Finds the position of the first word that is neither option nor an option's argument.
  130. # If there are options that require arguments, you should pass a glob describing those
  131. # options, e.g. "--option1|-o|--option2"
  132. # Use this function to restrict completions to exact positions after the argument list.
  133. __docker_pos_first_nonflag() {
  134. local argument_flags=$1
  135. local counter=$((${subcommand_pos:-${command_pos}} + 1))
  136. while [ $counter -le $cword ]; do
  137. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  138. (( counter++ ))
  139. # eat "=" in case of --option=arg syntax
  140. [ "${words[$counter]}" = "=" ] && (( counter++ ))
  141. else
  142. case "${words[$counter]}" in
  143. -*)
  144. ;;
  145. *)
  146. break
  147. ;;
  148. esac
  149. fi
  150. # Bash splits words at "=", retaining "=" as a word, examples:
  151. # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
  152. while [ "${words[$counter + 1]}" = "=" ] ; do
  153. counter=$(( counter + 2))
  154. done
  155. (( counter++ ))
  156. done
  157. echo $counter
  158. }
  159. # Returns the value of the first option matching option_glob.
  160. # Valid values for option_glob are option names like '--log-level' and
  161. # globs like '--log-level|-l'
  162. # Only positions between the command and the current word are considered.
  163. __docker_value_of_option() {
  164. local option_extglob=$(__docker_to_extglob "$1")
  165. local counter=$((command_pos + 1))
  166. while [ $counter -lt $cword ]; do
  167. case ${words[$counter]} in
  168. $option_extglob )
  169. echo ${words[$counter + 1]}
  170. break
  171. ;;
  172. esac
  173. (( counter++ ))
  174. done
  175. }
  176. # Transforms a multiline list of strings into a single line string
  177. # with the words separated by "|".
  178. # This is used to prepare arguments to __docker_pos_first_nonflag().
  179. __docker_to_alternatives() {
  180. local parts=( $1 )
  181. local IFS='|'
  182. echo "${parts[*]}"
  183. }
  184. # Transforms a multiline list of options into an extglob pattern
  185. # suitable for use in case statements.
  186. __docker_to_extglob() {
  187. local extglob=$( __docker_to_alternatives "$1" )
  188. echo "@($extglob)"
  189. }
  190. # Subcommand processing.
  191. # Locates the first occurrence of any of the subcommands contained in the
  192. # first argument. In case of a match, calls the corresponding completion
  193. # function and returns 0.
  194. # If no match is found, 1 is returned. The calling function can then
  195. # continue processing its completion.
  196. #
  197. # TODO if the preceding command has options that accept arguments and an
  198. # argument is equal ot one of the subcommands, this is falsely detected as
  199. # a match.
  200. __docker_subcommands() {
  201. local subcommands="$1"
  202. local counter=$(($command_pos + 1))
  203. while [ $counter -lt $cword ]; do
  204. case "${words[$counter]}" in
  205. $(__docker_to_extglob "$subcommands") )
  206. subcommand_pos=$counter
  207. local subcommand=${words[$counter]}
  208. local completions_func=_docker_${command}_${subcommand}
  209. declare -F $completions_func >/dev/null && $completions_func
  210. return 0
  211. ;;
  212. esac
  213. (( counter++ ))
  214. done
  215. return 1
  216. }
  217. # suppress trailing whitespace
  218. __docker_nospace() {
  219. # compopt is not available in ancient bash versions
  220. type compopt &>/dev/null && compopt -o nospace
  221. }
  222. __docker_resolve_hostname() {
  223. command -v host >/dev/null 2>&1 || return
  224. COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
  225. }
  226. __docker_capabilities() {
  227. # The list of capabilities is defined in types.go, ALL was added manually.
  228. COMPREPLY=( $( compgen -W "
  229. ALL
  230. AUDIT_CONTROL
  231. AUDIT_WRITE
  232. AUDIT_READ
  233. BLOCK_SUSPEND
  234. CHOWN
  235. DAC_OVERRIDE
  236. DAC_READ_SEARCH
  237. FOWNER
  238. FSETID
  239. IPC_LOCK
  240. IPC_OWNER
  241. KILL
  242. LEASE
  243. LINUX_IMMUTABLE
  244. MAC_ADMIN
  245. MAC_OVERRIDE
  246. MKNOD
  247. NET_ADMIN
  248. NET_BIND_SERVICE
  249. NET_BROADCAST
  250. NET_RAW
  251. SETFCAP
  252. SETGID
  253. SETPCAP
  254. SETUID
  255. SYS_ADMIN
  256. SYS_BOOT
  257. SYS_CHROOT
  258. SYSLOG
  259. SYS_MODULE
  260. SYS_NICE
  261. SYS_PACCT
  262. SYS_PTRACE
  263. SYS_RAWIO
  264. SYS_RESOURCE
  265. SYS_TIME
  266. SYS_TTY_CONFIG
  267. WAKE_ALARM
  268. " -- "$cur" ) )
  269. }
  270. __docker_log_drivers() {
  271. COMPREPLY=( $( compgen -W "
  272. fluentd
  273. gelf
  274. journald
  275. json-file
  276. none
  277. syslog
  278. " -- "$cur" ) )
  279. }
  280. __docker_log_driver_options() {
  281. # see docs/reference/logging/index.md
  282. local fluentd_options="fluentd-address tag"
  283. local gelf_options="gelf-address tag"
  284. local json_file_options="max-file max-size"
  285. local syslog_options="syslog-address syslog-facility tag"
  286. local awslogs_options="awslogs-region awslogs-group awslogs-stream"
  287. case $(__docker_value_of_option --log-driver) in
  288. '')
  289. COMPREPLY=( $( compgen -W "$fluentd_options $gelf_options $json_file_options $syslog_options" -S = -- "$cur" ) )
  290. ;;
  291. fluentd)
  292. COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) )
  293. ;;
  294. gelf)
  295. COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) )
  296. ;;
  297. json-file)
  298. COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) )
  299. ;;
  300. syslog)
  301. COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) )
  302. ;;
  303. awslogs)
  304. COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) )
  305. ;;
  306. *)
  307. return
  308. ;;
  309. esac
  310. __docker_nospace
  311. }
  312. __docker_complete_log_driver_options() {
  313. # "=" gets parsed to a word and assigned to either $cur or $prev depending on whether
  314. # it is the last character or not. So we search for "xxx=" in the the last two words.
  315. case "${words[$cword-2]}$prev=" in
  316. *gelf-address=*)
  317. COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur#=}" ) )
  318. __docker_nospace
  319. return
  320. ;;
  321. *syslog-address=*)
  322. COMPREPLY=( $( compgen -W "tcp udp unix" -S "://" -- "${cur#=}" ) )
  323. __docker_nospace
  324. return
  325. ;;
  326. *syslog-facility=*)
  327. COMPREPLY=( $( compgen -W "
  328. auth
  329. authpriv
  330. cron
  331. daemon
  332. ftp
  333. kern
  334. local0
  335. local1
  336. local2
  337. local3
  338. local4
  339. local5
  340. local6
  341. local7
  342. lpr
  343. mail
  344. news
  345. syslog
  346. user
  347. uucp
  348. " -- "${cur#=}" ) )
  349. return
  350. ;;
  351. esac
  352. return 1
  353. }
  354. __docker_log_levels() {
  355. COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) )
  356. }
  357. # a selection of the available signals that is most likely of interest in the
  358. # context of docker containers.
  359. __docker_signals() {
  360. local signals=(
  361. SIGCONT
  362. SIGHUP
  363. SIGINT
  364. SIGKILL
  365. SIGQUIT
  366. SIGSTOP
  367. SIGTERM
  368. SIGUSR1
  369. SIGUSR2
  370. )
  371. COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) )
  372. }
  373. # global options that may appear after the docker command
  374. _docker_docker() {
  375. local boolean_options="
  376. $global_boolean_options
  377. --help
  378. --version -v
  379. "
  380. case "$prev" in
  381. --config)
  382. _filedir -d
  383. return
  384. ;;
  385. --log-level|-l)
  386. __docker_log_levels
  387. return
  388. ;;
  389. $(__docker_to_extglob "$global_options_with_args") )
  390. return
  391. ;;
  392. esac
  393. case "$cur" in
  394. -*)
  395. COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) )
  396. ;;
  397. *)
  398. local counter=$( __docker_pos_first_nonflag $(__docker_to_extglob "$global_options_with_args") )
  399. if [ $cword -eq $counter ]; then
  400. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  401. fi
  402. ;;
  403. esac
  404. }
  405. _docker_attach() {
  406. case "$cur" in
  407. -*)
  408. COMPREPLY=( $( compgen -W "--help --no-stdin --sig-proxy" -- "$cur" ) )
  409. ;;
  410. *)
  411. local counter="$(__docker_pos_first_nonflag)"
  412. if [ $cword -eq $counter ]; then
  413. __docker_containers_running
  414. fi
  415. ;;
  416. esac
  417. }
  418. _docker_build() {
  419. local options_with_args="
  420. --build-arg
  421. --cgroup-parent
  422. --cpuset-cpus
  423. --cpuset-mems
  424. --cpu-shares -c
  425. --cpu-period
  426. --cpu-quota
  427. --file -f
  428. --memory -m
  429. --memory-swap
  430. --tag -t
  431. --ulimit
  432. "
  433. local boolean_options="
  434. --disable-content-trust=false
  435. --force-rm
  436. --help
  437. --no-cache
  438. --pull
  439. --quiet -q
  440. --rm
  441. "
  442. local all_options="$options_with_args $boolean_options"
  443. case "$prev" in
  444. --build-arg)
  445. COMPREPLY=( $( compgen -e -- "$cur" ) )
  446. __docker_nospace
  447. return
  448. ;;
  449. --file|-f)
  450. _filedir
  451. return
  452. ;;
  453. --tag|-t)
  454. __docker_image_repos_and_tags
  455. return
  456. ;;
  457. $(__docker_to_extglob "$options_with_args") )
  458. return
  459. ;;
  460. esac
  461. case "$cur" in
  462. -*)
  463. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  464. ;;
  465. *)
  466. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  467. if [ $cword -eq $counter ]; then
  468. _filedir -d
  469. fi
  470. ;;
  471. esac
  472. }
  473. _docker_commit() {
  474. case "$prev" in
  475. --author|-a|--change|-c|--message|-m)
  476. return
  477. ;;
  478. esac
  479. case "$cur" in
  480. -*)
  481. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause -p" -- "$cur" ) )
  482. ;;
  483. *)
  484. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  485. if [ $cword -eq $counter ]; then
  486. __docker_containers_all
  487. return
  488. fi
  489. (( counter++ ))
  490. if [ $cword -eq $counter ]; then
  491. __docker_image_repos_and_tags
  492. return
  493. fi
  494. ;;
  495. esac
  496. }
  497. _docker_cp() {
  498. case "$cur" in
  499. -*)
  500. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  501. ;;
  502. *)
  503. local counter=$(__docker_pos_first_nonflag)
  504. if [ $cword -eq $counter ]; then
  505. case "$cur" in
  506. *:)
  507. return
  508. ;;
  509. *)
  510. __docker_containers_all
  511. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  512. __docker_nospace
  513. return
  514. ;;
  515. esac
  516. fi
  517. (( counter++ ))
  518. if [ $cword -eq $counter ]; then
  519. _filedir -d
  520. return
  521. fi
  522. ;;
  523. esac
  524. }
  525. _docker_create() {
  526. _docker_run
  527. }
  528. _docker_daemon() {
  529. local boolean_options="
  530. $global_boolean_options
  531. --disable-legacy-registry
  532. --help
  533. --icc=false
  534. --ip-forward=false
  535. --ip-masq=false
  536. --iptables=false
  537. --ipv6
  538. --selinux-enabled
  539. --userland-proxy=false
  540. "
  541. local options_with_args="
  542. $global_options_with_args
  543. --api-cors-header
  544. --bip
  545. --bridge -b
  546. --cluster-advertise
  547. --cluster-store
  548. --cluster-store-opt
  549. --default-gateway
  550. --default-gateway-v6
  551. --default-ulimit
  552. --dns
  553. --dns-search
  554. --dns-opt
  555. --exec-driver -e
  556. --exec-opt
  557. --exec-root
  558. --fixed-cidr
  559. --fixed-cidr-v6
  560. --graph -g
  561. --group -G
  562. --insecure-registry
  563. --ip
  564. --label
  565. --log-driver
  566. --log-opt
  567. --mtu
  568. --pidfile -p
  569. --registry-mirror
  570. --storage-driver -s
  571. --storage-opt
  572. "
  573. case "$prev" in
  574. --cluster-store)
  575. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  576. __docker_nospace
  577. return
  578. ;;
  579. --cluster-store-opt)
  580. COMPREPLY=( $( compgen -W "kv.cacertfile kv.certfile kv.keyfile" -S = -- "$cur" ) )
  581. __docker_nospace
  582. return
  583. ;;
  584. --exec-root|--graph|-g)
  585. _filedir -d
  586. return
  587. ;;
  588. --log-driver)
  589. __docker_log_drivers
  590. return
  591. ;;
  592. --pidfile|-p|--tlscacert|--tlscert|--tlskey)
  593. _filedir
  594. return
  595. ;;
  596. --storage-driver|-s)
  597. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  598. return
  599. ;;
  600. --storage-opt)
  601. local devicemapper_options="
  602. dm.basesize
  603. dm.blkdiscard
  604. dm.blocksize
  605. dm.fs
  606. dm.loopdatasize
  607. dm.loopmetadatasize
  608. dm.mkfsarg
  609. dm.mountopt
  610. dm.override_udev_sync_check
  611. dm.thinpooldev
  612. "
  613. local zfs_options="zfs.fsname"
  614. case $(__docker_value_of_option '--storage-driver|-s') in
  615. '')
  616. COMPREPLY=( $( compgen -W "$devicemapper_options $zfs_options" -S = -- "$cur" ) )
  617. ;;
  618. devicemapper)
  619. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  620. ;;
  621. zfs)
  622. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  623. ;;
  624. *)
  625. return
  626. ;;
  627. esac
  628. __docker_nospace
  629. return
  630. ;;
  631. --log-level|-l)
  632. __docker_log_levels
  633. return
  634. ;;
  635. --log-opt)
  636. __docker_log_driver_options
  637. return
  638. ;;
  639. $(__docker_to_extglob "$options_with_args") )
  640. return
  641. ;;
  642. esac
  643. __docker_complete_log_driver_options && return
  644. case "${words[$cword-2]}$prev=" in
  645. # completions for --storage-opt
  646. *dm.blkdiscard=*)
  647. COMPREPLY=( $( compgen -W "false true" -- "${cur#=}" ) )
  648. return
  649. ;;
  650. *dm.fs=*)
  651. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur#=}" ) )
  652. return
  653. ;;
  654. *dm.override_udev_sync_check=*)
  655. COMPREPLY=( $( compgen -W "false true" -- "${cur#=}" ) )
  656. return
  657. ;;
  658. *dm.thinpooldev=*)
  659. _filedir
  660. return
  661. ;;
  662. # completions for --cluster-store-opt
  663. *kv.*file=*)
  664. _filedir
  665. return
  666. ;;
  667. esac
  668. case "$cur" in
  669. -*)
  670. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  671. ;;
  672. esac
  673. }
  674. _docker_diff() {
  675. case "$cur" in
  676. -*)
  677. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  678. ;;
  679. *)
  680. local counter=$(__docker_pos_first_nonflag)
  681. if [ $cword -eq $counter ]; then
  682. __docker_containers_all
  683. fi
  684. ;;
  685. esac
  686. }
  687. _docker_events() {
  688. case "$prev" in
  689. --filter|-f)
  690. COMPREPLY=( $( compgen -S = -W "container event image" -- "$cur" ) )
  691. __docker_nospace
  692. return
  693. ;;
  694. --since|--until)
  695. return
  696. ;;
  697. esac
  698. case "${words[$cword-2]}$prev=" in
  699. *container=*)
  700. cur="${cur#=}"
  701. __docker_containers_all
  702. return
  703. ;;
  704. *event=*)
  705. COMPREPLY=( $( compgen -W "
  706. attach
  707. commit
  708. copy
  709. create
  710. delete
  711. destroy
  712. die
  713. exec_create
  714. exec_start
  715. export
  716. import
  717. kill
  718. oom
  719. pause
  720. pull
  721. push
  722. rename
  723. resize
  724. restart
  725. start
  726. stop
  727. tag
  728. top
  729. unpause
  730. untag
  731. " -- "${cur#=}" ) )
  732. return
  733. ;;
  734. *image=*)
  735. cur="${cur#=}"
  736. __docker_images
  737. return
  738. ;;
  739. esac
  740. case "$cur" in
  741. -*)
  742. COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) )
  743. ;;
  744. esac
  745. }
  746. _docker_exec() {
  747. case "$prev" in
  748. --user|-u)
  749. return
  750. ;;
  751. esac
  752. case "$cur" in
  753. -*)
  754. COMPREPLY=( $( compgen -W "--detach -d --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  755. ;;
  756. *)
  757. __docker_containers_running
  758. ;;
  759. esac
  760. }
  761. _docker_export() {
  762. case "$cur" in
  763. -*)
  764. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  765. ;;
  766. *)
  767. local counter=$(__docker_pos_first_nonflag)
  768. if [ $cword -eq $counter ]; then
  769. __docker_containers_all
  770. fi
  771. ;;
  772. esac
  773. }
  774. _docker_help() {
  775. local counter=$(__docker_pos_first_nonflag)
  776. if [ $cword -eq $counter ]; then
  777. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  778. fi
  779. }
  780. _docker_history() {
  781. case "$cur" in
  782. -*)
  783. COMPREPLY=( $( compgen -W "--help --no-trunc --quiet -q" -- "$cur" ) )
  784. ;;
  785. *)
  786. local counter=$(__docker_pos_first_nonflag)
  787. if [ $cword -eq $counter ]; then
  788. __docker_images
  789. fi
  790. ;;
  791. esac
  792. }
  793. _docker_images() {
  794. case "$prev" in
  795. --filter|-f)
  796. COMPREPLY=( $( compgen -W "dangling=true label=" -- "$cur" ) )
  797. if [ "$COMPREPLY" = "label=" ]; then
  798. __docker_nospace
  799. fi
  800. return
  801. ;;
  802. esac
  803. case "${words[$cword-2]}$prev=" in
  804. *dangling=*)
  805. COMPREPLY=( $( compgen -W "true false" -- "${cur#=}" ) )
  806. return
  807. ;;
  808. *label=*)
  809. return
  810. ;;
  811. esac
  812. case "$cur" in
  813. -*)
  814. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
  815. ;;
  816. =)
  817. return
  818. ;;
  819. *)
  820. __docker_image_repos
  821. ;;
  822. esac
  823. }
  824. _docker_import() {
  825. case "$prev" in
  826. --change|-c|--message|-m)
  827. return
  828. ;;
  829. esac
  830. case "$cur" in
  831. -*)
  832. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  833. ;;
  834. *)
  835. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  836. if [ $cword -eq $counter ]; then
  837. return
  838. fi
  839. (( counter++ ))
  840. if [ $cword -eq $counter ]; then
  841. __docker_image_repos_and_tags
  842. return
  843. fi
  844. ;;
  845. esac
  846. }
  847. _docker_info() {
  848. case "$cur" in
  849. -*)
  850. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  851. ;;
  852. esac
  853. }
  854. _docker_inspect() {
  855. case "$prev" in
  856. --format|-f)
  857. return
  858. ;;
  859. --type)
  860. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  861. return
  862. ;;
  863. esac
  864. case "$cur" in
  865. -*)
  866. COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) )
  867. ;;
  868. *)
  869. case $(__docker_value_of_option --type) in
  870. '')
  871. __docker_containers_and_images
  872. ;;
  873. container)
  874. __docker_containers_all
  875. ;;
  876. image)
  877. __docker_images
  878. ;;
  879. esac
  880. esac
  881. }
  882. _docker_kill() {
  883. case "$prev" in
  884. --signal|-s)
  885. __docker_signals
  886. return
  887. ;;
  888. esac
  889. case "$cur" in
  890. -*)
  891. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  892. ;;
  893. *)
  894. __docker_containers_running
  895. ;;
  896. esac
  897. }
  898. _docker_load() {
  899. case "$prev" in
  900. --input|-i)
  901. _filedir
  902. return
  903. ;;
  904. esac
  905. case "$cur" in
  906. -*)
  907. COMPREPLY=( $( compgen -W "--help --input -i" -- "$cur" ) )
  908. ;;
  909. esac
  910. }
  911. _docker_login() {
  912. case "$prev" in
  913. --email|-e|--password|-p|--username|-u)
  914. return
  915. ;;
  916. esac
  917. case "$cur" in
  918. -*)
  919. COMPREPLY=( $( compgen -W "--email -e --help --password -p --username -u" -- "$cur" ) )
  920. ;;
  921. esac
  922. }
  923. _docker_logout() {
  924. case "$cur" in
  925. -*)
  926. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  927. ;;
  928. esac
  929. }
  930. _docker_logs() {
  931. case "$prev" in
  932. --since|--tail)
  933. return
  934. ;;
  935. esac
  936. case "$cur" in
  937. -*)
  938. COMPREPLY=( $( compgen -W "--follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  939. ;;
  940. *)
  941. local counter=$(__docker_pos_first_nonflag '--tail')
  942. if [ $cword -eq $counter ]; then
  943. __docker_containers_all
  944. fi
  945. ;;
  946. esac
  947. }
  948. _docker_network_connect() {
  949. case "$cur" in
  950. -*)
  951. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  952. ;;
  953. *)
  954. local counter=$(__docker_pos_first_nonflag '--tail')
  955. if [ $cword -eq $counter ]; then
  956. __docker_networks
  957. elif [ $cword -eq $(($counter + 1)) ]; then
  958. __docker_containers_running
  959. fi
  960. ;;
  961. esac
  962. }
  963. _docker_network_create() {
  964. case "$prev" in
  965. --driver|-d)
  966. # no need to suggest drivers that allow one instance only
  967. # (host, null)
  968. COMPREPLY=( $( compgen -W "bridge overlay" -- "$cur" ) )
  969. return
  970. ;;
  971. esac
  972. case "$cur" in
  973. -*)
  974. COMPREPLY=( $( compgen -W "--driver -d --help" -- "$cur" ) )
  975. ;;
  976. esac
  977. }
  978. _docker_network_disconnect() {
  979. # TODO disconnect should only complete running containers connected
  980. # to the specified network.
  981. _docker_network_connect
  982. }
  983. _docker_network_inspect() {
  984. case "$cur" in
  985. -*)
  986. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  987. ;;
  988. *)
  989. local counter=$(__docker_pos_first_nonflag)
  990. if [ $cword -eq $counter ]; then
  991. __docker_networks
  992. fi
  993. ;;
  994. esac
  995. }
  996. _docker_network_ls() {
  997. case "$prev" in
  998. -n)
  999. return
  1000. ;;
  1001. esac
  1002. case "$cur" in
  1003. -*)
  1004. COMPREPLY=( $( compgen -W "--help --no-trunc --quiet -q" -- "$cur" ) )
  1005. ;;
  1006. esac
  1007. }
  1008. _docker_network_rm() {
  1009. _docker_network_inspect
  1010. }
  1011. _docker_network() {
  1012. local subcommands="
  1013. connect
  1014. create
  1015. disconnect
  1016. inspect
  1017. ls
  1018. rm
  1019. "
  1020. __docker_subcommands "$subcommands" && return
  1021. case "$cur" in
  1022. -*)
  1023. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1024. ;;
  1025. *)
  1026. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1027. ;;
  1028. esac
  1029. }
  1030. _docker_pause() {
  1031. case "$cur" in
  1032. -*)
  1033. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1034. ;;
  1035. *)
  1036. local counter=$(__docker_pos_first_nonflag)
  1037. if [ $cword -eq $counter ]; then
  1038. __docker_containers_pauseable
  1039. fi
  1040. ;;
  1041. esac
  1042. }
  1043. _docker_port() {
  1044. case "$cur" in
  1045. -*)
  1046. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1047. ;;
  1048. *)
  1049. local counter=$(__docker_pos_first_nonflag)
  1050. if [ $cword -eq $counter ]; then
  1051. __docker_containers_all
  1052. fi
  1053. ;;
  1054. esac
  1055. }
  1056. _docker_ps() {
  1057. case "$prev" in
  1058. --before|--since)
  1059. __docker_containers_all
  1060. ;;
  1061. --filter|-f)
  1062. COMPREPLY=( $( compgen -S = -W "ancestor exited id label name status" -- "$cur" ) )
  1063. __docker_nospace
  1064. return
  1065. ;;
  1066. --format|-n)
  1067. return
  1068. ;;
  1069. esac
  1070. case "${words[$cword-2]}$prev=" in
  1071. *ancestor=*)
  1072. cur="${cur#=}"
  1073. __docker_images
  1074. return
  1075. ;;
  1076. *id=*)
  1077. cur="${cur#=}"
  1078. __docker_container_ids
  1079. return
  1080. ;;
  1081. *name=*)
  1082. cur="${cur#=}"
  1083. __docker_container_names
  1084. return
  1085. ;;
  1086. *status=*)
  1087. COMPREPLY=( $( compgen -W "exited paused restarting running" -- "${cur#=}" ) )
  1088. return
  1089. ;;
  1090. esac
  1091. case "$cur" in
  1092. -*)
  1093. COMPREPLY=( $( compgen -W "--all -a --before --filter -f --format --help --latest -l -n --no-trunc --quiet -q --size -s --since" -- "$cur" ) )
  1094. ;;
  1095. esac
  1096. }
  1097. _docker_pull() {
  1098. case "$cur" in
  1099. -*)
  1100. COMPREPLY=( $( compgen -W "--all-tags -a --help" -- "$cur" ) )
  1101. ;;
  1102. *)
  1103. local counter=$(__docker_pos_first_nonflag)
  1104. if [ $cword -eq $counter ]; then
  1105. for arg in "${COMP_WORDS[@]}"; do
  1106. case "$arg" in
  1107. --all-tags|-a)
  1108. __docker_image_repos
  1109. return
  1110. ;;
  1111. esac
  1112. done
  1113. __docker_image_repos_and_tags
  1114. fi
  1115. ;;
  1116. esac
  1117. }
  1118. _docker_push() {
  1119. case "$cur" in
  1120. -*)
  1121. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1122. ;;
  1123. *)
  1124. local counter=$(__docker_pos_first_nonflag)
  1125. if [ $cword -eq $counter ]; then
  1126. __docker_image_repos_and_tags
  1127. fi
  1128. ;;
  1129. esac
  1130. }
  1131. _docker_rename() {
  1132. case "$cur" in
  1133. -*)
  1134. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1135. ;;
  1136. *)
  1137. local counter=$(__docker_pos_first_nonflag)
  1138. if [ $cword -eq $counter ]; then
  1139. __docker_containers_all
  1140. fi
  1141. ;;
  1142. esac
  1143. }
  1144. _docker_restart() {
  1145. case "$prev" in
  1146. --time|-t)
  1147. return
  1148. ;;
  1149. esac
  1150. case "$cur" in
  1151. -*)
  1152. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1153. ;;
  1154. *)
  1155. __docker_containers_all
  1156. ;;
  1157. esac
  1158. }
  1159. _docker_rm() {
  1160. case "$cur" in
  1161. -*)
  1162. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  1163. ;;
  1164. *)
  1165. for arg in "${COMP_WORDS[@]}"; do
  1166. case "$arg" in
  1167. --force|-f)
  1168. __docker_containers_all
  1169. return
  1170. ;;
  1171. esac
  1172. done
  1173. __docker_containers_stopped
  1174. ;;
  1175. esac
  1176. }
  1177. _docker_rmi() {
  1178. case "$cur" in
  1179. -*)
  1180. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  1181. ;;
  1182. *)
  1183. __docker_images
  1184. ;;
  1185. esac
  1186. }
  1187. _docker_run() {
  1188. local options_with_args="
  1189. --add-host
  1190. --attach -a
  1191. --blkio-weight
  1192. --cap-add
  1193. --cap-drop
  1194. --cgroup-parent
  1195. --cidfile
  1196. --cpu-period
  1197. --cpu-quota
  1198. --cpuset-cpus
  1199. --cpuset-mems
  1200. --cpu-shares -c
  1201. --device
  1202. --dns
  1203. --dns-opt
  1204. --dns-search
  1205. --entrypoint
  1206. --env -e
  1207. --env-file
  1208. --expose
  1209. --group-add
  1210. --hostname -h
  1211. --ipc
  1212. --kernel-memory
  1213. --label-file
  1214. --label -l
  1215. --link
  1216. --log-driver
  1217. --log-opt
  1218. --lxc-conf
  1219. --mac-address
  1220. --memory -m
  1221. --memory-swap
  1222. --memory-swappiness
  1223. --memory-reservation
  1224. --name
  1225. --net
  1226. --pid
  1227. --publish -p
  1228. --restart
  1229. --security-opt
  1230. --stop-signal
  1231. --ulimit
  1232. --user -u
  1233. --uts
  1234. --volumes-from
  1235. --volume -v
  1236. --workdir -w
  1237. "
  1238. local boolean_options="
  1239. --disable-content-trust=false
  1240. --help
  1241. --interactive -i
  1242. --oom-kill-disable
  1243. --privileged
  1244. --publish-all -P
  1245. --read-only
  1246. --tty -t
  1247. "
  1248. local all_options="$options_with_args $boolean_options"
  1249. [ "$command" = "run" ] && all_options="$all_options
  1250. --detach -d
  1251. --rm
  1252. --sig-proxy=false
  1253. "
  1254. case "$prev" in
  1255. --add-host)
  1256. case "$cur" in
  1257. *:)
  1258. __docker_resolve_hostname
  1259. return
  1260. ;;
  1261. esac
  1262. ;;
  1263. --attach|-a)
  1264. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  1265. return
  1266. ;;
  1267. --cap-add|--cap-drop)
  1268. __docker_capabilities
  1269. return
  1270. ;;
  1271. --cidfile|--env-file|--label-file)
  1272. _filedir
  1273. return
  1274. ;;
  1275. --device|--volume|-v)
  1276. case "$cur" in
  1277. *:*)
  1278. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  1279. ;;
  1280. '')
  1281. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  1282. __docker_nospace
  1283. ;;
  1284. /*)
  1285. _filedir
  1286. __docker_nospace
  1287. ;;
  1288. esac
  1289. return
  1290. ;;
  1291. --env|-e)
  1292. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1293. __docker_nospace
  1294. return
  1295. ;;
  1296. --ipc)
  1297. case "$cur" in
  1298. *:*)
  1299. cur="${cur#*:}"
  1300. __docker_containers_running
  1301. ;;
  1302. *)
  1303. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1304. if [ "$COMPREPLY" = "container:" ]; then
  1305. __docker_nospace
  1306. fi
  1307. ;;
  1308. esac
  1309. return
  1310. ;;
  1311. --link)
  1312. case "$cur" in
  1313. *:*)
  1314. ;;
  1315. *)
  1316. __docker_containers_running
  1317. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1318. __docker_nospace
  1319. ;;
  1320. esac
  1321. return
  1322. ;;
  1323. --log-driver)
  1324. __docker_log_drivers
  1325. return
  1326. ;;
  1327. --log-opt)
  1328. __docker_log_driver_options
  1329. return
  1330. ;;
  1331. --net)
  1332. case "$cur" in
  1333. container:*)
  1334. local cur=${cur#*:}
  1335. __docker_containers_all
  1336. ;;
  1337. *)
  1338. COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") )
  1339. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1340. __docker_nospace
  1341. fi
  1342. ;;
  1343. esac
  1344. return
  1345. ;;
  1346. --restart)
  1347. case "$cur" in
  1348. on-failure:*)
  1349. ;;
  1350. *)
  1351. COMPREPLY=( $( compgen -W "no on-failure on-failure: always" -- "$cur") )
  1352. ;;
  1353. esac
  1354. return
  1355. ;;
  1356. --security-opt)
  1357. case "$cur" in
  1358. label:*:*)
  1359. ;;
  1360. label:*)
  1361. local cur=${cur##*:}
  1362. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") )
  1363. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  1364. __docker_nospace
  1365. fi
  1366. ;;
  1367. *)
  1368. COMPREPLY=( $( compgen -W "label apparmor" -S ":" -- "$cur") )
  1369. __docker_nospace
  1370. ;;
  1371. esac
  1372. return
  1373. ;;
  1374. --volumes-from)
  1375. __docker_containers_all
  1376. return
  1377. ;;
  1378. $(__docker_to_extglob "$options_with_args") )
  1379. return
  1380. ;;
  1381. esac
  1382. __docker_complete_log_driver_options && return
  1383. case "$cur" in
  1384. -*)
  1385. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1386. ;;
  1387. *)
  1388. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1389. if [ $cword -eq $counter ]; then
  1390. __docker_images
  1391. fi
  1392. ;;
  1393. esac
  1394. }
  1395. _docker_save() {
  1396. case "$prev" in
  1397. --output|-o)
  1398. _filedir
  1399. return
  1400. ;;
  1401. esac
  1402. case "$cur" in
  1403. -*)
  1404. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  1405. ;;
  1406. *)
  1407. __docker_images
  1408. ;;
  1409. esac
  1410. }
  1411. _docker_search() {
  1412. case "$prev" in
  1413. --stars|-s)
  1414. return
  1415. ;;
  1416. esac
  1417. case "$cur" in
  1418. -*)
  1419. COMPREPLY=( $( compgen -W "--automated --help --no-trunc --stars -s" -- "$cur" ) )
  1420. ;;
  1421. esac
  1422. }
  1423. _docker_start() {
  1424. case "$cur" in
  1425. -*)
  1426. COMPREPLY=( $( compgen -W "--attach -a --help --interactive -i" -- "$cur" ) )
  1427. ;;
  1428. *)
  1429. __docker_containers_stopped
  1430. ;;
  1431. esac
  1432. }
  1433. _docker_stats() {
  1434. case "$cur" in
  1435. -*)
  1436. COMPREPLY=( $( compgen -W "--no-stream --help" -- "$cur" ) )
  1437. ;;
  1438. *)
  1439. __docker_containers_running
  1440. ;;
  1441. esac
  1442. }
  1443. _docker_stop() {
  1444. case "$prev" in
  1445. --time|-t)
  1446. return
  1447. ;;
  1448. esac
  1449. case "$cur" in
  1450. -*)
  1451. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1452. ;;
  1453. *)
  1454. __docker_containers_running
  1455. ;;
  1456. esac
  1457. }
  1458. _docker_tag() {
  1459. case "$cur" in
  1460. -*)
  1461. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  1462. ;;
  1463. *)
  1464. local counter=$(__docker_pos_first_nonflag)
  1465. if [ $cword -eq $counter ]; then
  1466. __docker_image_repos_and_tags
  1467. return
  1468. fi
  1469. (( counter++ ))
  1470. if [ $cword -eq $counter ]; then
  1471. __docker_image_repos_and_tags
  1472. return
  1473. fi
  1474. ;;
  1475. esac
  1476. }
  1477. _docker_unpause() {
  1478. case "$cur" in
  1479. -*)
  1480. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1481. ;;
  1482. *)
  1483. local counter=$(__docker_pos_first_nonflag)
  1484. if [ $cword -eq $counter ]; then
  1485. __docker_containers_unpauseable
  1486. fi
  1487. ;;
  1488. esac
  1489. }
  1490. _docker_top() {
  1491. case "$cur" in
  1492. -*)
  1493. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1494. ;;
  1495. *)
  1496. local counter=$(__docker_pos_first_nonflag)
  1497. if [ $cword -eq $counter ]; then
  1498. __docker_containers_running
  1499. fi
  1500. ;;
  1501. esac
  1502. }
  1503. _docker_version() {
  1504. case "$cur" in
  1505. -*)
  1506. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1507. ;;
  1508. esac
  1509. }
  1510. _docker_volume_create() {
  1511. case "$prev" in
  1512. --driver|-d)
  1513. COMPREPLY=( $( compgen -W "local" -- "$cur" ) )
  1514. return
  1515. ;;
  1516. --name|--opt|-o)
  1517. return
  1518. ;;
  1519. esac
  1520. case "$cur" in
  1521. -*)
  1522. COMPREPLY=( $( compgen -W "--driver -d --help --name --opt -o" -- "$cur" ) )
  1523. ;;
  1524. esac
  1525. }
  1526. _docker_volume_inspect() {
  1527. case "$prev" in
  1528. --format|-f)
  1529. return
  1530. ;;
  1531. esac
  1532. case "$cur" in
  1533. -*)
  1534. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1535. ;;
  1536. *)
  1537. __docker_volumes
  1538. ;;
  1539. esac
  1540. }
  1541. _docker_volume_ls() {
  1542. case "$prev" in
  1543. --filter|-f)
  1544. COMPREPLY=( $( compgen -W "dangling=true" -- "$cur" ) )
  1545. return
  1546. ;;
  1547. esac
  1548. case "$cur" in
  1549. -*)
  1550. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1551. ;;
  1552. esac
  1553. }
  1554. _docker_volume_rm() {
  1555. case "$cur" in
  1556. -*)
  1557. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1558. ;;
  1559. *)
  1560. __docker_volumes
  1561. ;;
  1562. esac
  1563. }
  1564. _docker_volume() {
  1565. local subcommands="
  1566. create
  1567. inspect
  1568. ls
  1569. rm
  1570. "
  1571. __docker_subcommands "$subcommands" && return
  1572. case "$cur" in
  1573. -*)
  1574. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1575. ;;
  1576. *)
  1577. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1578. ;;
  1579. esac
  1580. }
  1581. _docker_wait() {
  1582. case "$cur" in
  1583. -*)
  1584. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1585. ;;
  1586. *)
  1587. __docker_containers_all
  1588. ;;
  1589. esac
  1590. }
  1591. _docker() {
  1592. local previous_extglob_setting=$(shopt -p extglob)
  1593. shopt -s extglob
  1594. local commands=(
  1595. attach
  1596. build
  1597. commit
  1598. cp
  1599. create
  1600. daemon
  1601. diff
  1602. events
  1603. exec
  1604. export
  1605. history
  1606. images
  1607. import
  1608. info
  1609. inspect
  1610. kill
  1611. load
  1612. login
  1613. logout
  1614. logs
  1615. network
  1616. pause
  1617. port
  1618. ps
  1619. pull
  1620. push
  1621. rename
  1622. restart
  1623. rm
  1624. rmi
  1625. run
  1626. save
  1627. search
  1628. start
  1629. stats
  1630. stop
  1631. tag
  1632. top
  1633. unpause
  1634. version
  1635. volume
  1636. wait
  1637. )
  1638. # These options are valid as global options for all client commands
  1639. # and valid as command options for `docker daemon`
  1640. local global_boolean_options="
  1641. --debug -D
  1642. --tls
  1643. --tlsverify
  1644. "
  1645. local global_options_with_args="
  1646. --config
  1647. --host -H
  1648. --log-level -l
  1649. --tlscacert
  1650. --tlscert
  1651. --tlskey
  1652. "
  1653. local host config
  1654. COMPREPLY=()
  1655. local cur prev words cword
  1656. _get_comp_words_by_ref -n : cur prev words cword
  1657. local command='docker' command_pos=0 subcommand_pos
  1658. local counter=1
  1659. while [ $counter -lt $cword ]; do
  1660. case "${words[$counter]}" in
  1661. # save host so that completion can use custom daemon
  1662. --host|-H)
  1663. (( counter++ ))
  1664. host="${words[$counter]}"
  1665. ;;
  1666. # save config so that completion can use custom configuration directories
  1667. --config)
  1668. (( counter++ ))
  1669. config="${words[$counter]}"
  1670. ;;
  1671. $(__docker_to_extglob "$global_options_with_args") )
  1672. (( counter++ ))
  1673. ;;
  1674. -*)
  1675. ;;
  1676. =)
  1677. (( counter++ ))
  1678. ;;
  1679. *)
  1680. command="${words[$counter]}"
  1681. command_pos=$counter
  1682. break
  1683. ;;
  1684. esac
  1685. (( counter++ ))
  1686. done
  1687. local completions_func=_docker_${command}
  1688. declare -F $completions_func >/dev/null && $completions_func
  1689. eval "$previous_extglob_setting"
  1690. return 0
  1691. }
  1692. complete -F _docker docker