docker 58 KB

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