docker 35 KB

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