docker 42 KB

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