docker 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674
  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. --memory-reservation
  1059. --name
  1060. --net
  1061. --pid
  1062. --publish -p
  1063. --restart
  1064. --security-opt
  1065. --stop-signal
  1066. --ulimit
  1067. --user -u
  1068. --uts
  1069. --volumes-from
  1070. --volume -v
  1071. --workdir -w
  1072. "
  1073. local all_options="$options_with_args
  1074. --disable-content-trust=false
  1075. --help
  1076. --interactive -i
  1077. --oom-kill-disable
  1078. --privileged
  1079. --publish-all -P
  1080. --read-only
  1081. --tty -t
  1082. "
  1083. [ "$command" = "run" ] && all_options="$all_options
  1084. --detach -d
  1085. --rm
  1086. --sig-proxy=false
  1087. "
  1088. local options_with_args_glob=$(__docker_to_extglob "$options_with_args")
  1089. case "$prev" in
  1090. --add-host)
  1091. case "$cur" in
  1092. *:)
  1093. __docker_resolve_hostname
  1094. return
  1095. ;;
  1096. esac
  1097. ;;
  1098. --attach|-a)
  1099. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  1100. return
  1101. ;;
  1102. --cap-add|--cap-drop)
  1103. __docker_capabilities
  1104. return
  1105. ;;
  1106. --cidfile|--env-file|--label-file)
  1107. _filedir
  1108. return
  1109. ;;
  1110. --device|--volume|-v)
  1111. case "$cur" in
  1112. *:*)
  1113. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  1114. ;;
  1115. '')
  1116. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  1117. __docker_nospace
  1118. ;;
  1119. /*)
  1120. _filedir
  1121. __docker_nospace
  1122. ;;
  1123. esac
  1124. return
  1125. ;;
  1126. --env|-e)
  1127. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1128. __docker_nospace
  1129. return
  1130. ;;
  1131. --ipc)
  1132. case "$cur" in
  1133. *:*)
  1134. cur="${cur#*:}"
  1135. __docker_containers_running
  1136. ;;
  1137. *)
  1138. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1139. if [ "$COMPREPLY" = "container:" ]; then
  1140. __docker_nospace
  1141. fi
  1142. ;;
  1143. esac
  1144. return
  1145. ;;
  1146. --link)
  1147. case "$cur" in
  1148. *:*)
  1149. ;;
  1150. *)
  1151. __docker_containers_running
  1152. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1153. __docker_nospace
  1154. ;;
  1155. esac
  1156. return
  1157. ;;
  1158. --log-driver)
  1159. __docker_log_drivers
  1160. return
  1161. ;;
  1162. --log-opt)
  1163. __docker_log_driver_options
  1164. return
  1165. ;;
  1166. --net)
  1167. case "$cur" in
  1168. container:*)
  1169. local cur=${cur#*:}
  1170. __docker_containers_all
  1171. ;;
  1172. *)
  1173. COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") )
  1174. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1175. __docker_nospace
  1176. fi
  1177. ;;
  1178. esac
  1179. return
  1180. ;;
  1181. --restart)
  1182. case "$cur" in
  1183. on-failure:*)
  1184. ;;
  1185. *)
  1186. COMPREPLY=( $( compgen -W "no on-failure on-failure: always" -- "$cur") )
  1187. ;;
  1188. esac
  1189. return
  1190. ;;
  1191. --security-opt)
  1192. case "$cur" in
  1193. label:*:*)
  1194. ;;
  1195. label:*)
  1196. local cur=${cur##*:}
  1197. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") )
  1198. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  1199. __docker_nospace
  1200. fi
  1201. ;;
  1202. *)
  1203. COMPREPLY=( $( compgen -W "label apparmor" -S ":" -- "$cur") )
  1204. __docker_nospace
  1205. ;;
  1206. esac
  1207. return
  1208. ;;
  1209. --volumes-from)
  1210. __docker_containers_all
  1211. return
  1212. ;;
  1213. $options_with_args_glob )
  1214. return
  1215. ;;
  1216. esac
  1217. __docker_complete_log_driver_options && return
  1218. case "$cur" in
  1219. -*)
  1220. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1221. ;;
  1222. *)
  1223. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1224. if [ $cword -eq $counter ]; then
  1225. __docker_images
  1226. fi
  1227. ;;
  1228. esac
  1229. }
  1230. _docker_save() {
  1231. case "$prev" in
  1232. --output|-o)
  1233. _filedir
  1234. return
  1235. ;;
  1236. esac
  1237. case "$cur" in
  1238. -*)
  1239. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  1240. ;;
  1241. *)
  1242. __docker_images
  1243. ;;
  1244. esac
  1245. }
  1246. _docker_search() {
  1247. case "$prev" in
  1248. --stars|-s)
  1249. return
  1250. ;;
  1251. esac
  1252. case "$cur" in
  1253. -*)
  1254. COMPREPLY=( $( compgen -W "--automated --help --no-trunc --stars -s" -- "$cur" ) )
  1255. ;;
  1256. esac
  1257. }
  1258. _docker_start() {
  1259. case "$cur" in
  1260. -*)
  1261. COMPREPLY=( $( compgen -W "--attach -a --help --interactive -i" -- "$cur" ) )
  1262. ;;
  1263. *)
  1264. __docker_containers_stopped
  1265. ;;
  1266. esac
  1267. }
  1268. _docker_stats() {
  1269. case "$cur" in
  1270. -*)
  1271. COMPREPLY=( $( compgen -W "--no-stream --help" -- "$cur" ) )
  1272. ;;
  1273. *)
  1274. __docker_containers_running
  1275. ;;
  1276. esac
  1277. }
  1278. _docker_stop() {
  1279. case "$prev" in
  1280. --time|-t)
  1281. return
  1282. ;;
  1283. esac
  1284. case "$cur" in
  1285. -*)
  1286. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1287. ;;
  1288. *)
  1289. __docker_containers_running
  1290. ;;
  1291. esac
  1292. }
  1293. _docker_tag() {
  1294. case "$cur" in
  1295. -*)
  1296. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  1297. ;;
  1298. *)
  1299. local counter=$(__docker_pos_first_nonflag)
  1300. if [ $cword -eq $counter ]; then
  1301. __docker_image_repos_and_tags
  1302. return
  1303. fi
  1304. (( counter++ ))
  1305. if [ $cword -eq $counter ]; then
  1306. __docker_image_repos_and_tags
  1307. return
  1308. fi
  1309. ;;
  1310. esac
  1311. }
  1312. _docker_unpause() {
  1313. case "$cur" in
  1314. -*)
  1315. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1316. ;;
  1317. *)
  1318. local counter=$(__docker_pos_first_nonflag)
  1319. if [ $cword -eq $counter ]; then
  1320. __docker_containers_unpauseable
  1321. fi
  1322. ;;
  1323. esac
  1324. }
  1325. _docker_top() {
  1326. case "$cur" in
  1327. -*)
  1328. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1329. ;;
  1330. *)
  1331. local counter=$(__docker_pos_first_nonflag)
  1332. if [ $cword -eq $counter ]; then
  1333. __docker_containers_running
  1334. fi
  1335. ;;
  1336. esac
  1337. }
  1338. _docker_version() {
  1339. case "$cur" in
  1340. -*)
  1341. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1342. ;;
  1343. esac
  1344. }
  1345. _docker_volume_create() {
  1346. case "$prev" in
  1347. --driver|-d)
  1348. COMPREPLY=( $( compgen -W "local" -- "$cur" ) )
  1349. return
  1350. ;;
  1351. --name|--opt|-o)
  1352. return
  1353. ;;
  1354. esac
  1355. case "$cur" in
  1356. -*)
  1357. COMPREPLY=( $( compgen -W "--driver -d --help --name --opt -o" -- "$cur" ) )
  1358. ;;
  1359. esac
  1360. }
  1361. _docker_volume_inspect() {
  1362. case "$prev" in
  1363. --format|-f)
  1364. return
  1365. ;;
  1366. esac
  1367. case "$cur" in
  1368. -*)
  1369. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1370. ;;
  1371. *)
  1372. __docker_volumes
  1373. ;;
  1374. esac
  1375. }
  1376. _docker_volume_ls() {
  1377. case "$prev" in
  1378. --filter|-f)
  1379. COMPREPLY=( $( compgen -W "dangling=true" -- "$cur" ) )
  1380. return
  1381. ;;
  1382. esac
  1383. case "$cur" in
  1384. -*)
  1385. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1386. ;;
  1387. esac
  1388. }
  1389. _docker_volume_rm() {
  1390. case "$cur" in
  1391. -*)
  1392. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1393. ;;
  1394. *)
  1395. __docker_volumes
  1396. ;;
  1397. esac
  1398. }
  1399. _docker_volume() {
  1400. local subcommands=(
  1401. create
  1402. inspect
  1403. ls
  1404. rm
  1405. )
  1406. local counter=$(($command_pos + 1))
  1407. while [ $counter -lt $cword ]; do
  1408. case "${words[$counter]}" in
  1409. $(__docker_to_extglob "${subcommands[*]}") )
  1410. local subcommand=${words[$counter]}
  1411. local completions_func=_docker_volume_$subcommand
  1412. declare -F $completions_func >/dev/null && $completions_func
  1413. return
  1414. ;;
  1415. esac
  1416. (( counter++ ))
  1417. done
  1418. case "$cur" in
  1419. -*)
  1420. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1421. ;;
  1422. *)
  1423. COMPREPLY=( $( compgen -W "${subcommands[*]}" -- "$cur" ) )
  1424. ;;
  1425. esac
  1426. }
  1427. _docker_wait() {
  1428. case "$cur" in
  1429. -*)
  1430. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1431. ;;
  1432. *)
  1433. __docker_containers_all
  1434. ;;
  1435. esac
  1436. }
  1437. _docker() {
  1438. local previous_extglob_setting=$(shopt -p extglob)
  1439. shopt -s extglob
  1440. local commands=(
  1441. attach
  1442. build
  1443. commit
  1444. cp
  1445. create
  1446. daemon
  1447. diff
  1448. events
  1449. exec
  1450. export
  1451. history
  1452. images
  1453. import
  1454. info
  1455. inspect
  1456. kill
  1457. load
  1458. login
  1459. logout
  1460. logs
  1461. pause
  1462. port
  1463. ps
  1464. pull
  1465. push
  1466. rename
  1467. restart
  1468. rm
  1469. rmi
  1470. run
  1471. save
  1472. search
  1473. start
  1474. stats
  1475. stop
  1476. tag
  1477. top
  1478. unpause
  1479. version
  1480. volume
  1481. wait
  1482. )
  1483. # These options are valid as global options for all client commands
  1484. # and valid as command options for `docker daemon`
  1485. local global_boolean_options="
  1486. --debug -D
  1487. --tls
  1488. --tlsverify
  1489. "
  1490. local global_options_with_args="
  1491. --config
  1492. --host -H
  1493. --log-level -l
  1494. --tlscacert
  1495. --tlscert
  1496. --tlskey
  1497. "
  1498. local host config
  1499. COMPREPLY=()
  1500. local cur prev words cword
  1501. _get_comp_words_by_ref -n : cur prev words cword
  1502. local command='docker' command_pos=0
  1503. local counter=1
  1504. while [ $counter -lt $cword ]; do
  1505. case "${words[$counter]}" in
  1506. # save host so that completion can use custom daemon
  1507. --host|-H)
  1508. (( counter++ ))
  1509. host="${words[$counter]}"
  1510. ;;
  1511. # save config so that completion can use custom configuration directories
  1512. --config)
  1513. (( counter++ ))
  1514. config="${words[$counter]}"
  1515. ;;
  1516. $(__docker_to_extglob "$global_options_with_args") )
  1517. (( counter++ ))
  1518. ;;
  1519. -*)
  1520. ;;
  1521. =)
  1522. (( counter++ ))
  1523. ;;
  1524. *)
  1525. command="${words[$counter]}"
  1526. command_pos=$counter
  1527. break
  1528. ;;
  1529. esac
  1530. (( counter++ ))
  1531. done
  1532. local completions_func=_docker_${command}
  1533. declare -F $completions_func >/dev/null && $completions_func
  1534. eval "$previous_extglob_setting"
  1535. return 0
  1536. }
  1537. complete -F _docker docker