docker 69 KB

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