docker 31 KB

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