docker 42 KB

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