docker 61 KB

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