docker 42 KB

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