docker 52 KB

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