docker 36 KB

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