docker 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529
  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. --userns-remap
  1570. "
  1571. __docker_complete_log_driver_options && return
  1572. key=$(__docker_map_key_of_current_option '--cluster-store-opt')
  1573. case "$key" in
  1574. kv.*file)
  1575. cur=${cur##*=}
  1576. _filedir
  1577. return
  1578. ;;
  1579. esac
  1580. local key=$(__docker_map_key_of_current_option '--storage-opt')
  1581. case "$key" in
  1582. dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion)
  1583. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1584. return
  1585. ;;
  1586. dm.fs)
  1587. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) )
  1588. return
  1589. ;;
  1590. dm.thinpooldev)
  1591. cur=${cur##*=}
  1592. _filedir
  1593. return
  1594. ;;
  1595. esac
  1596. case "$prev" in
  1597. --authorization-plugin)
  1598. __docker_complete_plugins --type Authorization
  1599. return
  1600. ;;
  1601. --cluster-store)
  1602. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  1603. __docker_nospace
  1604. return
  1605. ;;
  1606. --cluster-store-opt)
  1607. COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) )
  1608. __docker_nospace
  1609. return
  1610. ;;
  1611. --config-file|--containerd|--init-path|--pidfile|-p|--tlscacert|--tlscert|--tlskey)
  1612. _filedir
  1613. return
  1614. ;;
  1615. --exec-root|--graph|-g)
  1616. _filedir -d
  1617. return
  1618. ;;
  1619. --log-driver)
  1620. __docker_complete_log_drivers
  1621. return
  1622. ;;
  1623. --storage-driver|-s)
  1624. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  1625. return
  1626. ;;
  1627. --storage-opt)
  1628. local btrfs_options="btrfs.min_space"
  1629. local devicemapper_options="
  1630. dm.basesize
  1631. dm.blkdiscard
  1632. dm.blocksize
  1633. dm.fs
  1634. dm.loopdatasize
  1635. dm.loopmetadatasize
  1636. dm.min_free_space
  1637. dm.mkfsarg
  1638. dm.mountopt
  1639. dm.override_udev_sync_check
  1640. dm.thinpooldev
  1641. dm.use_deferred_deletion
  1642. dm.use_deferred_removal
  1643. "
  1644. local zfs_options="zfs.fsname"
  1645. case $(__docker_value_of_option '--storage-driver|-s') in
  1646. '')
  1647. COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) )
  1648. ;;
  1649. btrfs)
  1650. COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) )
  1651. ;;
  1652. devicemapper)
  1653. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  1654. ;;
  1655. zfs)
  1656. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  1657. ;;
  1658. *)
  1659. return
  1660. ;;
  1661. esac
  1662. __docker_nospace
  1663. return
  1664. ;;
  1665. --log-level|-l)
  1666. __docker_complete_log_levels
  1667. return
  1668. ;;
  1669. --log-opt)
  1670. __docker_complete_log_options
  1671. return
  1672. ;;
  1673. --seccomp-profile)
  1674. _filedir json
  1675. return
  1676. ;;
  1677. --userns-remap)
  1678. __docker_complete_user_group
  1679. return
  1680. ;;
  1681. $(__docker_to_extglob "$options_with_args") )
  1682. return
  1683. ;;
  1684. esac
  1685. case "$cur" in
  1686. -*)
  1687. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1688. ;;
  1689. esac
  1690. }
  1691. _docker_diff() {
  1692. _docker_container_diff
  1693. }
  1694. _docker_events() {
  1695. _docker_system_events
  1696. }
  1697. _docker_exec() {
  1698. _docker_container_exec
  1699. }
  1700. _docker_export() {
  1701. _docker_container_export
  1702. }
  1703. _docker_help() {
  1704. local counter=$(__docker_pos_first_nonflag)
  1705. if [ $cword -eq $counter ]; then
  1706. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  1707. fi
  1708. }
  1709. _docker_history() {
  1710. _docker_image_history
  1711. }
  1712. _docker_image() {
  1713. local subcommands="
  1714. build
  1715. history
  1716. import
  1717. inspect
  1718. load
  1719. ls
  1720. prune
  1721. pull
  1722. push
  1723. rm
  1724. save
  1725. tag
  1726. "
  1727. local aliases="
  1728. images
  1729. list
  1730. remove
  1731. rmi
  1732. "
  1733. __docker_subcommands "$subcommands $aliases" && return
  1734. case "$cur" in
  1735. -*)
  1736. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1737. ;;
  1738. *)
  1739. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1740. ;;
  1741. esac
  1742. }
  1743. _docker_image_build() {
  1744. local options_with_args="
  1745. --build-arg
  1746. --cache-from
  1747. --cgroup-parent
  1748. --cpuset-cpus
  1749. --cpuset-mems
  1750. --cpu-shares -c
  1751. --cpu-period
  1752. --cpu-quota
  1753. --file -f
  1754. --isolation
  1755. --label
  1756. --memory -m
  1757. --memory-swap
  1758. --shm-size
  1759. --tag -t
  1760. --ulimit
  1761. "
  1762. local boolean_options="
  1763. --compress
  1764. --disable-content-trust=false
  1765. --force-rm
  1766. --help
  1767. --no-cache
  1768. --pull
  1769. --quiet -q
  1770. --rm
  1771. "
  1772. local all_options="$options_with_args $boolean_options"
  1773. case "$prev" in
  1774. --build-arg)
  1775. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1776. __docker_nospace
  1777. return
  1778. ;;
  1779. --cache-from)
  1780. __docker_complete_image_repos_and_tags
  1781. return
  1782. ;;
  1783. --file|-f)
  1784. _filedir
  1785. return
  1786. ;;
  1787. --isolation)
  1788. __docker_complete_isolation
  1789. return
  1790. ;;
  1791. --tag|-t)
  1792. __docker_complete_image_repos_and_tags
  1793. return
  1794. ;;
  1795. $(__docker_to_extglob "$options_with_args") )
  1796. return
  1797. ;;
  1798. esac
  1799. case "$cur" in
  1800. -*)
  1801. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1802. ;;
  1803. *)
  1804. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1805. if [ $cword -eq $counter ]; then
  1806. _filedir -d
  1807. fi
  1808. ;;
  1809. esac
  1810. }
  1811. _docker_image_history() {
  1812. case "$cur" in
  1813. -*)
  1814. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  1815. ;;
  1816. *)
  1817. local counter=$(__docker_pos_first_nonflag)
  1818. if [ $cword -eq $counter ]; then
  1819. __docker_complete_images
  1820. fi
  1821. ;;
  1822. esac
  1823. }
  1824. _docker_image_images() {
  1825. _docker_image_ls
  1826. }
  1827. _docker_image_import() {
  1828. case "$prev" in
  1829. --change|-c|--message|-m)
  1830. return
  1831. ;;
  1832. esac
  1833. case "$cur" in
  1834. -*)
  1835. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1836. ;;
  1837. *)
  1838. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1839. if [ $cword -eq $counter ]; then
  1840. return
  1841. fi
  1842. (( counter++ ))
  1843. if [ $cword -eq $counter ]; then
  1844. __docker_complete_image_repos_and_tags
  1845. return
  1846. fi
  1847. ;;
  1848. esac
  1849. }
  1850. _docker_image_inspect() {
  1851. _docker_inspect --type image
  1852. }
  1853. _docker_image_load() {
  1854. case "$prev" in
  1855. --input|-i)
  1856. _filedir
  1857. return
  1858. ;;
  1859. esac
  1860. case "$cur" in
  1861. -*)
  1862. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1863. ;;
  1864. esac
  1865. }
  1866. _docker_image_list() {
  1867. _docker_image_ls
  1868. }
  1869. _docker_image_ls() {
  1870. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1871. case "$key" in
  1872. before)
  1873. cur="${cur##*=}"
  1874. __docker_complete_images
  1875. return
  1876. ;;
  1877. dangling)
  1878. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1879. return
  1880. ;;
  1881. label)
  1882. return
  1883. ;;
  1884. since)
  1885. cur="${cur##*=}"
  1886. __docker_complete_images
  1887. return
  1888. ;;
  1889. esac
  1890. case "$prev" in
  1891. --filter|-f)
  1892. COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) )
  1893. __docker_nospace
  1894. return
  1895. ;;
  1896. --format)
  1897. return
  1898. ;;
  1899. esac
  1900. case "$cur" in
  1901. -*)
  1902. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1903. ;;
  1904. =)
  1905. return
  1906. ;;
  1907. *)
  1908. __docker_complete_image_repos
  1909. ;;
  1910. esac
  1911. }
  1912. _docker_image_prune() {
  1913. case "$cur" in
  1914. -*)
  1915. COMPREPLY=( $( compgen -W "--all -a --force -f --help" -- "$cur" ) )
  1916. ;;
  1917. esac
  1918. }
  1919. _docker_image_pull() {
  1920. case "$cur" in
  1921. -*)
  1922. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  1923. ;;
  1924. *)
  1925. local counter=$(__docker_pos_first_nonflag)
  1926. if [ $cword -eq $counter ]; then
  1927. for arg in "${COMP_WORDS[@]}"; do
  1928. case "$arg" in
  1929. --all-tags|-a)
  1930. __docker_complete_image_repos
  1931. return
  1932. ;;
  1933. esac
  1934. done
  1935. __docker_complete_image_repos_and_tags
  1936. fi
  1937. ;;
  1938. esac
  1939. }
  1940. _docker_image_push() {
  1941. case "$cur" in
  1942. -*)
  1943. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  1944. ;;
  1945. *)
  1946. local counter=$(__docker_pos_first_nonflag)
  1947. if [ $cword -eq $counter ]; then
  1948. __docker_complete_image_repos_and_tags
  1949. fi
  1950. ;;
  1951. esac
  1952. }
  1953. _docker_image_remove() {
  1954. _docker_image_rm
  1955. }
  1956. _docker_image_rm() {
  1957. case "$cur" in
  1958. -*)
  1959. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  1960. ;;
  1961. *)
  1962. __docker_complete_images
  1963. ;;
  1964. esac
  1965. }
  1966. _docker_image_rmi() {
  1967. _docker_image_rm
  1968. }
  1969. _docker_image_save() {
  1970. case "$prev" in
  1971. --output|-o)
  1972. _filedir
  1973. return
  1974. ;;
  1975. esac
  1976. case "$cur" in
  1977. -*)
  1978. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  1979. ;;
  1980. *)
  1981. __docker_complete_images
  1982. ;;
  1983. esac
  1984. }
  1985. _docker_image_tag() {
  1986. case "$cur" in
  1987. -*)
  1988. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1989. ;;
  1990. *)
  1991. local counter=$(__docker_pos_first_nonflag)
  1992. if [ $cword -eq $counter ]; then
  1993. __docker_complete_image_repos_and_tags
  1994. return
  1995. fi
  1996. (( counter++ ))
  1997. if [ $cword -eq $counter ]; then
  1998. __docker_complete_image_repos_and_tags
  1999. return
  2000. fi
  2001. ;;
  2002. esac
  2003. }
  2004. _docker_images() {
  2005. _docker_image_ls
  2006. }
  2007. _docker_import() {
  2008. _docker_image_import
  2009. }
  2010. _docker_info() {
  2011. _docker_system_info
  2012. }
  2013. _docker_inspect() {
  2014. local preselected_type
  2015. local type
  2016. if [ "$1" = "--type" ] ; then
  2017. preselected_type=yes
  2018. type="$2"
  2019. else
  2020. type=$(__docker_value_of_option --type)
  2021. fi
  2022. case "$prev" in
  2023. --format|-f)
  2024. return
  2025. ;;
  2026. --type)
  2027. if [ -z "$preselected_type" ] ; then
  2028. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  2029. return
  2030. fi
  2031. ;;
  2032. esac
  2033. case "$cur" in
  2034. -*)
  2035. local options="--format -f --help --size -s"
  2036. if [ -z "$preselected_type" ] ; then
  2037. options+=" --type"
  2038. fi
  2039. COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
  2040. ;;
  2041. *)
  2042. case "$type" in
  2043. '')
  2044. __docker_complete_containers_and_images
  2045. ;;
  2046. container)
  2047. __docker_complete_containers_all
  2048. ;;
  2049. image)
  2050. __docker_complete_images
  2051. ;;
  2052. esac
  2053. esac
  2054. }
  2055. _docker_kill() {
  2056. _docker_container_kill
  2057. }
  2058. _docker_load() {
  2059. _docker_image_load
  2060. }
  2061. _docker_login() {
  2062. case "$prev" in
  2063. --password|-p|--username|-u)
  2064. return
  2065. ;;
  2066. esac
  2067. case "$cur" in
  2068. -*)
  2069. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  2070. ;;
  2071. esac
  2072. }
  2073. _docker_logout() {
  2074. case "$cur" in
  2075. -*)
  2076. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2077. ;;
  2078. esac
  2079. }
  2080. _docker_logs() {
  2081. _docker_container_logs
  2082. }
  2083. _docker_network_connect() {
  2084. local options_with_args="
  2085. --alias
  2086. --ip
  2087. --ip6
  2088. --link
  2089. --link-local-ip
  2090. "
  2091. local boolean_options="
  2092. --help
  2093. "
  2094. case "$prev" in
  2095. --link)
  2096. case "$cur" in
  2097. *:*)
  2098. ;;
  2099. *)
  2100. __docker_complete_containers_running
  2101. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  2102. __docker_nospace
  2103. ;;
  2104. esac
  2105. return
  2106. ;;
  2107. $(__docker_to_extglob "$options_with_args") )
  2108. return
  2109. ;;
  2110. esac
  2111. case "$cur" in
  2112. -*)
  2113. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  2114. ;;
  2115. *)
  2116. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2117. if [ $cword -eq $counter ]; then
  2118. __docker_complete_networks
  2119. elif [ $cword -eq $(($counter + 1)) ]; then
  2120. __docker_complete_containers_all
  2121. fi
  2122. ;;
  2123. esac
  2124. }
  2125. _docker_network_create() {
  2126. case "$prev" in
  2127. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  2128. return
  2129. ;;
  2130. --ipam-driver)
  2131. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  2132. return
  2133. ;;
  2134. --driver|-d)
  2135. # remove drivers that allow one instance only, add drivers missing in `docker info`
  2136. __docker_complete_plugins --type Network --remove host --remove null --add macvlan
  2137. return
  2138. ;;
  2139. --label)
  2140. return
  2141. ;;
  2142. esac
  2143. case "$cur" in
  2144. -*)
  2145. COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  2146. ;;
  2147. esac
  2148. }
  2149. _docker_network_disconnect() {
  2150. case "$cur" in
  2151. -*)
  2152. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2153. ;;
  2154. *)
  2155. local counter=$(__docker_pos_first_nonflag)
  2156. if [ $cword -eq $counter ]; then
  2157. __docker_complete_networks
  2158. elif [ $cword -eq $(($counter + 1)) ]; then
  2159. __docker_complete_containers_in_network "$prev"
  2160. fi
  2161. ;;
  2162. esac
  2163. }
  2164. _docker_network_inspect() {
  2165. case "$prev" in
  2166. --format|-f)
  2167. return
  2168. ;;
  2169. esac
  2170. case "$cur" in
  2171. -*)
  2172. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2173. ;;
  2174. *)
  2175. __docker_complete_networks
  2176. esac
  2177. }
  2178. _docker_network_ls() {
  2179. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2180. case "$key" in
  2181. driver)
  2182. __docker_complete_plugins --cur "${cur##*=}" --type Network --add macvlan
  2183. return
  2184. ;;
  2185. id)
  2186. __docker_complete_networks --cur "${cur##*=}" --id
  2187. return
  2188. ;;
  2189. name)
  2190. __docker_complete_networks --cur "${cur##*=}" --name
  2191. return
  2192. ;;
  2193. type)
  2194. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  2195. return
  2196. ;;
  2197. esac
  2198. case "$prev" in
  2199. --filter|-f)
  2200. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  2201. __docker_nospace
  2202. return
  2203. ;;
  2204. --format)
  2205. return
  2206. ;;
  2207. esac
  2208. case "$cur" in
  2209. -*)
  2210. COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  2211. ;;
  2212. esac
  2213. }
  2214. _docker_network_prune() {
  2215. case "$cur" in
  2216. -*)
  2217. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2218. ;;
  2219. esac
  2220. }
  2221. _docker_network_rm() {
  2222. case "$cur" in
  2223. -*)
  2224. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2225. ;;
  2226. *)
  2227. __docker_complete_networks --filter type=custom
  2228. esac
  2229. }
  2230. _docker_network() {
  2231. local subcommands="
  2232. connect
  2233. create
  2234. disconnect
  2235. inspect
  2236. ls
  2237. prune
  2238. rm
  2239. "
  2240. __docker_subcommands "$subcommands" && return
  2241. case "$cur" in
  2242. -*)
  2243. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2244. ;;
  2245. *)
  2246. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2247. ;;
  2248. esac
  2249. }
  2250. _docker_service() {
  2251. local subcommands="
  2252. create
  2253. inspect
  2254. ls list
  2255. rm remove
  2256. scale
  2257. ps
  2258. update
  2259. "
  2260. __docker_subcommands "$subcommands" && return
  2261. case "$cur" in
  2262. -*)
  2263. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2264. ;;
  2265. *)
  2266. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2267. ;;
  2268. esac
  2269. }
  2270. _docker_service_create() {
  2271. _docker_service_update
  2272. }
  2273. _docker_service_inspect() {
  2274. case "$prev" in
  2275. --format|-f)
  2276. return
  2277. ;;
  2278. esac
  2279. case "$cur" in
  2280. -*)
  2281. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  2282. ;;
  2283. *)
  2284. __docker_complete_services
  2285. esac
  2286. }
  2287. _docker_service_list() {
  2288. _docker_service_ls
  2289. }
  2290. _docker_service_ls() {
  2291. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2292. case "$key" in
  2293. id)
  2294. __docker_complete_services --cur "${cur##*=}" --id
  2295. return
  2296. ;;
  2297. name)
  2298. __docker_complete_services --cur "${cur##*=}" --name
  2299. return
  2300. ;;
  2301. esac
  2302. case "$prev" in
  2303. --filter|-f)
  2304. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  2305. __docker_nospace
  2306. return
  2307. ;;
  2308. esac
  2309. case "$cur" in
  2310. -*)
  2311. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  2312. ;;
  2313. esac
  2314. }
  2315. _docker_service_remove() {
  2316. _docker_service_rm
  2317. }
  2318. _docker_service_rm() {
  2319. case "$cur" in
  2320. -*)
  2321. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2322. ;;
  2323. *)
  2324. __docker_complete_services
  2325. esac
  2326. }
  2327. _docker_service_scale() {
  2328. case "$cur" in
  2329. -*)
  2330. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2331. ;;
  2332. *)
  2333. __docker_complete_services
  2334. __docker_append_to_completions "="
  2335. __docker_nospace
  2336. ;;
  2337. esac
  2338. }
  2339. _docker_service_ps() {
  2340. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2341. case "$key" in
  2342. desired-state)
  2343. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  2344. return
  2345. ;;
  2346. name)
  2347. __docker_complete_services --cur "${cur##*=}" --name
  2348. return
  2349. ;;
  2350. esac
  2351. case "$prev" in
  2352. --filter|-f)
  2353. COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) )
  2354. __docker_nospace
  2355. return
  2356. ;;
  2357. esac
  2358. case "$cur" in
  2359. -*)
  2360. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc --quiet -q" -- "$cur" ) )
  2361. ;;
  2362. *)
  2363. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  2364. if [ $cword -eq $counter ]; then
  2365. __docker_complete_services
  2366. fi
  2367. ;;
  2368. esac
  2369. }
  2370. _docker_service_update() {
  2371. local $subcommand="${words[$subcommand_pos]}"
  2372. local options_with_args="
  2373. --constraint
  2374. --endpoint-mode
  2375. --env -e
  2376. --force
  2377. --health-cmd
  2378. --health-interval
  2379. --health-retries
  2380. --health-timeout
  2381. --label -l
  2382. --limit-cpu
  2383. --limit-memory
  2384. --log-driver
  2385. --log-opt
  2386. --mount
  2387. --network
  2388. --no-healthcheck
  2389. --publish -p
  2390. --replicas
  2391. --reserve-cpu
  2392. --reserve-memory
  2393. --restart-condition
  2394. --restart-delay
  2395. --restart-max-attempts
  2396. --restart-window
  2397. --rollback
  2398. --stop-grace-period
  2399. --update-delay
  2400. --update-failure-action
  2401. --update-max-failure-ratio
  2402. --update-monitor
  2403. --update-parallelism
  2404. --user -u
  2405. --workdir -w
  2406. "
  2407. local boolean_options="
  2408. --help
  2409. --tty -t
  2410. --with-registry-auth
  2411. "
  2412. __docker_complete_log_driver_options && return
  2413. if [ "$subcommand" = "create" ] ; then
  2414. options_with_args="$options_with_args
  2415. --container-label
  2416. --dns
  2417. --dns-option
  2418. --dns-search
  2419. --env-file
  2420. --group
  2421. --hostname
  2422. --mode
  2423. --name
  2424. --port
  2425. "
  2426. case "$prev" in
  2427. --env-file)
  2428. _filedir
  2429. return
  2430. ;;
  2431. --mode)
  2432. COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) )
  2433. return
  2434. ;;
  2435. --group)
  2436. COMPREPLY=( $(compgen -g -- "$cur") )
  2437. return
  2438. ;;
  2439. esac
  2440. fi
  2441. if [ "$subcommand" = "update" ] ; then
  2442. options_with_args="$options_with_args
  2443. --arg
  2444. --container-label-add
  2445. --container-label-rm
  2446. --dns-add
  2447. --dns-options-add
  2448. --dns-options-rm
  2449. --dns-rm
  2450. --dns-search-add
  2451. --dns-search-rm
  2452. --group-add
  2453. --group-rm
  2454. --image
  2455. --port-add
  2456. --port-rm
  2457. "
  2458. case "$prev" in
  2459. --group-add)
  2460. COMPREPLY=( $(compgen -g -- "$cur") )
  2461. return
  2462. ;;
  2463. --group-rm)
  2464. COMPREPLY=( $(compgen -g -- "$cur") )
  2465. return
  2466. ;;
  2467. --image)
  2468. __docker_complete_image_repos_and_tags
  2469. return
  2470. ;;
  2471. esac
  2472. fi
  2473. case "$prev" in
  2474. --endpoint-mode)
  2475. COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) )
  2476. return
  2477. ;;
  2478. --env|-e)
  2479. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  2480. COMPREPLY=( $( compgen -e -- "$cur" ) )
  2481. __docker_nospace
  2482. return
  2483. ;;
  2484. --log-driver)
  2485. __docker_complete_log_drivers
  2486. return
  2487. ;;
  2488. --log-opt)
  2489. __docker_complete_log_options
  2490. return
  2491. ;;
  2492. --network)
  2493. __docker_complete_networks
  2494. return
  2495. ;;
  2496. --restart-condition)
  2497. COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) )
  2498. return
  2499. ;;
  2500. --user|-u)
  2501. __docker_complete_user_group
  2502. return
  2503. ;;
  2504. $(__docker_to_extglob "$options_with_args") )
  2505. return
  2506. ;;
  2507. esac
  2508. case "$cur" in
  2509. -*)
  2510. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  2511. ;;
  2512. *)
  2513. if [ "$subcommand" = "update" ] ; then
  2514. __docker_complete_services
  2515. fi
  2516. esac
  2517. }
  2518. _docker_swarm() {
  2519. local subcommands="
  2520. init
  2521. join
  2522. join-token
  2523. leave
  2524. update
  2525. "
  2526. __docker_subcommands "$subcommands" && return
  2527. case "$cur" in
  2528. -*)
  2529. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2530. ;;
  2531. *)
  2532. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2533. ;;
  2534. esac
  2535. }
  2536. _docker_swarm_init() {
  2537. case "$prev" in
  2538. --advertise-addr)
  2539. if [[ $cur == *: ]] ; then
  2540. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2541. else
  2542. __docker_complete_local_interfaces
  2543. __docker_nospace
  2544. fi
  2545. return
  2546. ;;
  2547. --listen-addr)
  2548. if [[ $cur == *: ]] ; then
  2549. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2550. else
  2551. __docker_complete_local_interfaces --add 0.0.0.0
  2552. __docker_nospace
  2553. fi
  2554. return
  2555. ;;
  2556. esac
  2557. case "$cur" in
  2558. -*)
  2559. COMPREPLY=( $( compgen -W "--advertise-addr --force-new-cluster --help --listen-addr" -- "$cur" ) )
  2560. ;;
  2561. esac
  2562. }
  2563. _docker_swarm_join() {
  2564. case "$prev" in
  2565. --advertise-addr)
  2566. if [[ $cur == *: ]] ; then
  2567. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2568. else
  2569. __docker_complete_local_interfaces
  2570. __docker_nospace
  2571. fi
  2572. return
  2573. ;;
  2574. --listen-addr)
  2575. if [[ $cur == *: ]] ; then
  2576. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2577. else
  2578. __docker_complete_local_interfaces --add 0.0.0.0
  2579. __docker_nospace
  2580. fi
  2581. return
  2582. ;;
  2583. --token)
  2584. return
  2585. ;;
  2586. esac
  2587. case "$cur" in
  2588. -*)
  2589. COMPREPLY=( $( compgen -W "--advertise-addr --help --listen-addr --token" -- "$cur" ) )
  2590. ;;
  2591. *:)
  2592. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2593. ;;
  2594. esac
  2595. }
  2596. _docker_swarm_join-token() {
  2597. case "$cur" in
  2598. -*)
  2599. COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) )
  2600. ;;
  2601. *)
  2602. local counter=$( __docker_pos_first_nonflag )
  2603. if [ $cword -eq $counter ]; then
  2604. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  2605. fi
  2606. ;;
  2607. esac
  2608. }
  2609. _docker_swarm_leave() {
  2610. case "$cur" in
  2611. -*)
  2612. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2613. ;;
  2614. esac
  2615. }
  2616. _docker_swarm_update() {
  2617. case "$prev" in
  2618. --cert-expiry|--dispatcher-heartbeat|--max-snapshots|--snapshot-interval|--task-history-limit)
  2619. return
  2620. ;;
  2621. esac
  2622. case "$cur" in
  2623. -*)
  2624. COMPREPLY=( $( compgen -W "--cert-expiry --dispatcher-heartbeat --help --max-snapshots --snapshot-interval --task-history-limit" -- "$cur" ) )
  2625. ;;
  2626. esac
  2627. }
  2628. _docker_node() {
  2629. local subcommands="
  2630. demote
  2631. inspect
  2632. ls list
  2633. promote
  2634. rm remove
  2635. ps
  2636. update
  2637. "
  2638. __docker_subcommands "$subcommands" && return
  2639. case "$cur" in
  2640. -*)
  2641. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2642. ;;
  2643. *)
  2644. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2645. ;;
  2646. esac
  2647. }
  2648. _docker_node_demote() {
  2649. case "$cur" in
  2650. -*)
  2651. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2652. ;;
  2653. *)
  2654. __docker_complete_nodes --filter role=manager
  2655. esac
  2656. }
  2657. _docker_node_inspect() {
  2658. case "$prev" in
  2659. --format|-f)
  2660. return
  2661. ;;
  2662. esac
  2663. case "$cur" in
  2664. -*)
  2665. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  2666. ;;
  2667. *)
  2668. __docker_complete_nodes_plus_self
  2669. esac
  2670. }
  2671. _docker_node_list() {
  2672. _docker_node_ls
  2673. }
  2674. _docker_node_ls() {
  2675. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2676. case "$key" in
  2677. id)
  2678. __docker_complete_nodes --cur "${cur##*=}" --id
  2679. return
  2680. ;;
  2681. name)
  2682. __docker_complete_nodes --cur "${cur##*=}" --name
  2683. return
  2684. ;;
  2685. esac
  2686. case "$prev" in
  2687. --filter|-f)
  2688. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  2689. __docker_nospace
  2690. return
  2691. ;;
  2692. esac
  2693. case "$cur" in
  2694. -*)
  2695. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  2696. ;;
  2697. esac
  2698. }
  2699. _docker_node_promote() {
  2700. case "$cur" in
  2701. -*)
  2702. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2703. ;;
  2704. *)
  2705. __docker_complete_nodes --filter role=worker
  2706. esac
  2707. }
  2708. _docker_node_remove() {
  2709. _docker_node_rm
  2710. }
  2711. _docker_node_rm() {
  2712. case "$cur" in
  2713. -*)
  2714. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2715. ;;
  2716. *)
  2717. __docker_complete_nodes
  2718. esac
  2719. }
  2720. _docker_node_ps() {
  2721. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2722. case "$key" in
  2723. desired-state)
  2724. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  2725. return
  2726. ;;
  2727. name)
  2728. __docker_complete_services --cur "${cur##*=}" --name
  2729. return
  2730. ;;
  2731. esac
  2732. case "$prev" in
  2733. --filter|-f)
  2734. COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) )
  2735. __docker_nospace
  2736. return
  2737. ;;
  2738. esac
  2739. case "$cur" in
  2740. -*)
  2741. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  2742. ;;
  2743. *)
  2744. __docker_complete_nodes_plus_self
  2745. ;;
  2746. esac
  2747. }
  2748. _docker_node_update() {
  2749. case "$prev" in
  2750. --availability)
  2751. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  2752. return
  2753. ;;
  2754. --role)
  2755. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  2756. return
  2757. ;;
  2758. --label-add|--label-rm)
  2759. return
  2760. ;;
  2761. esac
  2762. case "$cur" in
  2763. -*)
  2764. COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) )
  2765. ;;
  2766. *)
  2767. __docker_complete_nodes
  2768. esac
  2769. }
  2770. _docker_pause() {
  2771. _docker_container_pause
  2772. }
  2773. _docker_port() {
  2774. _docker_container_port
  2775. }
  2776. _docker_ps() {
  2777. _docker_container_ls
  2778. }
  2779. _docker_pull() {
  2780. _docker_image_pull
  2781. }
  2782. _docker_push() {
  2783. _docker_image_push
  2784. }
  2785. _docker_rename() {
  2786. _docker_container_rename
  2787. }
  2788. _docker_restart() {
  2789. _docker_container_restart
  2790. }
  2791. _docker_rm() {
  2792. _docker_container_rm
  2793. }
  2794. _docker_rmi() {
  2795. _docker_image_rm
  2796. }
  2797. _docker_run() {
  2798. _docker_container_run
  2799. }
  2800. _docker_save() {
  2801. _docker_image_save
  2802. }
  2803. _docker_search() {
  2804. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2805. case "$key" in
  2806. is-automated)
  2807. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2808. return
  2809. ;;
  2810. is-official)
  2811. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2812. return
  2813. ;;
  2814. esac
  2815. case "$prev" in
  2816. --filter|-f)
  2817. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  2818. __docker_nospace
  2819. return
  2820. ;;
  2821. --limit)
  2822. return
  2823. ;;
  2824. esac
  2825. case "$cur" in
  2826. -*)
  2827. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  2828. ;;
  2829. esac
  2830. }
  2831. _docker_start() {
  2832. _docker_container_start
  2833. }
  2834. _docker_stats() {
  2835. _docker_container_stats
  2836. }
  2837. _docker_stop() {
  2838. _docker_container_stop
  2839. }
  2840. _docker_system() {
  2841. local subcommands="
  2842. df
  2843. events
  2844. info
  2845. prune
  2846. "
  2847. __docker_subcommands "$subcommands $aliases" && return
  2848. case "$cur" in
  2849. -*)
  2850. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2851. ;;
  2852. *)
  2853. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2854. ;;
  2855. esac
  2856. }
  2857. _docker_system_df() {
  2858. case "$cur" in
  2859. -*)
  2860. COMPREPLY=( $( compgen -W "--help --verbose -v" -- "$cur" ) )
  2861. ;;
  2862. esac
  2863. }
  2864. _docker_system_events() {
  2865. local key=$(__docker_map_key_of_current_option '-f|--filter')
  2866. case "$key" in
  2867. container)
  2868. __docker_complete_containers_all --cur "${cur##*=}"
  2869. return
  2870. ;;
  2871. daemon)
  2872. local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
  2873. COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
  2874. return
  2875. ;;
  2876. event)
  2877. COMPREPLY=( $( compgen -W "
  2878. attach
  2879. commit
  2880. connect
  2881. copy
  2882. create
  2883. delete
  2884. destroy
  2885. detach
  2886. die
  2887. disconnect
  2888. exec_create
  2889. exec_detach
  2890. exec_start
  2891. export
  2892. health_status
  2893. import
  2894. kill
  2895. load
  2896. mount
  2897. oom
  2898. pause
  2899. pull
  2900. push
  2901. reload
  2902. rename
  2903. resize
  2904. restart
  2905. save
  2906. start
  2907. stop
  2908. tag
  2909. top
  2910. unmount
  2911. unpause
  2912. untag
  2913. update
  2914. " -- "${cur##*=}" ) )
  2915. return
  2916. ;;
  2917. image)
  2918. cur="${cur##*=}"
  2919. __docker_complete_images
  2920. return
  2921. ;;
  2922. network)
  2923. __docker_complete_networks --cur "${cur##*=}"
  2924. return
  2925. ;;
  2926. type)
  2927. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  2928. return
  2929. ;;
  2930. volume)
  2931. __docker_complete_volumes --cur "${cur##*=}"
  2932. return
  2933. ;;
  2934. esac
  2935. case "$prev" in
  2936. --filter|-f)
  2937. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  2938. __docker_nospace
  2939. return
  2940. ;;
  2941. --since|--until)
  2942. return
  2943. ;;
  2944. esac
  2945. case "$cur" in
  2946. -*)
  2947. COMPREPLY=( $( compgen -W "--filter -f --help --since --until --format" -- "$cur" ) )
  2948. ;;
  2949. esac
  2950. }
  2951. _docker_system_info() {
  2952. case "$prev" in
  2953. --format|-f)
  2954. return
  2955. ;;
  2956. esac
  2957. case "$cur" in
  2958. -*)
  2959. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2960. ;;
  2961. esac
  2962. }
  2963. _docker_system_prune() {
  2964. case "$cur" in
  2965. -*)
  2966. COMPREPLY=( $( compgen -W "--all -a --force -f --help" -- "$cur" ) )
  2967. ;;
  2968. esac
  2969. }
  2970. _docker_tag() {
  2971. _docker_image_tag
  2972. }
  2973. _docker_unpause() {
  2974. _docker_container_unpause
  2975. }
  2976. _docker_update() {
  2977. _docker_container_update
  2978. }
  2979. _docker_top() {
  2980. _docker_container_top
  2981. }
  2982. _docker_version() {
  2983. case "$cur" in
  2984. -*)
  2985. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2986. ;;
  2987. esac
  2988. }
  2989. _docker_volume_create() {
  2990. case "$prev" in
  2991. --driver|-d)
  2992. __docker_complete_plugins --type Volume
  2993. return
  2994. ;;
  2995. --label|--opt|-o)
  2996. return
  2997. ;;
  2998. esac
  2999. case "$cur" in
  3000. -*)
  3001. COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) )
  3002. ;;
  3003. esac
  3004. }
  3005. _docker_volume_inspect() {
  3006. case "$prev" in
  3007. --format|-f)
  3008. return
  3009. ;;
  3010. esac
  3011. case "$cur" in
  3012. -*)
  3013. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3014. ;;
  3015. *)
  3016. __docker_complete_volumes
  3017. ;;
  3018. esac
  3019. }
  3020. _docker_volume_ls() {
  3021. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3022. case "$key" in
  3023. dangling)
  3024. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  3025. return
  3026. ;;
  3027. driver)
  3028. __docker_complete_plugins --cur "${cur##*=}" --type Volume
  3029. return
  3030. ;;
  3031. name)
  3032. __docker_complete_volumes --cur "${cur##*=}"
  3033. return
  3034. ;;
  3035. esac
  3036. case "$prev" in
  3037. --filter|-f)
  3038. COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) )
  3039. __docker_nospace
  3040. return
  3041. ;;
  3042. --format)
  3043. return
  3044. ;;
  3045. esac
  3046. case "$cur" in
  3047. -*)
  3048. COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
  3049. ;;
  3050. esac
  3051. }
  3052. _docker_volume_prune() {
  3053. case "$cur" in
  3054. -*)
  3055. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3056. ;;
  3057. esac
  3058. }
  3059. _docker_volume_rm() {
  3060. case "$cur" in
  3061. -*)
  3062. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3063. ;;
  3064. *)
  3065. __docker_complete_volumes
  3066. ;;
  3067. esac
  3068. }
  3069. _docker_volume() {
  3070. local subcommands="
  3071. create
  3072. inspect
  3073. ls
  3074. prune
  3075. rm
  3076. "
  3077. __docker_subcommands "$subcommands" && return
  3078. case "$cur" in
  3079. -*)
  3080. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3081. ;;
  3082. *)
  3083. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3084. ;;
  3085. esac
  3086. }
  3087. _docker_wait() {
  3088. _docker_container_wait
  3089. }
  3090. _docker() {
  3091. local previous_extglob_setting=$(shopt -p extglob)
  3092. shopt -s extglob
  3093. local commands=(
  3094. attach
  3095. build
  3096. commit
  3097. container
  3098. cp
  3099. create
  3100. daemon
  3101. diff
  3102. events
  3103. exec
  3104. export
  3105. history
  3106. image
  3107. images
  3108. import
  3109. info
  3110. inspect
  3111. kill
  3112. load
  3113. login
  3114. logout
  3115. logs
  3116. network
  3117. node
  3118. pause
  3119. port
  3120. ps
  3121. pull
  3122. push
  3123. rename
  3124. restart
  3125. rm
  3126. rmi
  3127. run
  3128. save
  3129. search
  3130. service
  3131. start
  3132. stats
  3133. stop
  3134. swarm
  3135. system
  3136. tag
  3137. top
  3138. unpause
  3139. update
  3140. version
  3141. volume
  3142. wait
  3143. )
  3144. # These options are valid as global options for all client commands
  3145. # and valid as command options for `docker daemon`
  3146. local global_boolean_options="
  3147. --debug -D
  3148. --tls
  3149. --tlsverify
  3150. "
  3151. local global_options_with_args="
  3152. --config
  3153. --host -H
  3154. --log-level -l
  3155. --tlscacert
  3156. --tlscert
  3157. --tlskey
  3158. "
  3159. local host config
  3160. COMPREPLY=()
  3161. local cur prev words cword
  3162. _get_comp_words_by_ref -n : cur prev words cword
  3163. local command='docker' command_pos=0 subcommand_pos
  3164. local counter=1
  3165. while [ $counter -lt $cword ]; do
  3166. case "${words[$counter]}" in
  3167. # save host so that completion can use custom daemon
  3168. --host|-H)
  3169. (( counter++ ))
  3170. host="${words[$counter]}"
  3171. ;;
  3172. # save config so that completion can use custom configuration directories
  3173. --config)
  3174. (( counter++ ))
  3175. config="${words[$counter]}"
  3176. ;;
  3177. $(__docker_to_extglob "$global_options_with_args") )
  3178. (( counter++ ))
  3179. ;;
  3180. -*)
  3181. ;;
  3182. =)
  3183. (( counter++ ))
  3184. ;;
  3185. *)
  3186. command="${words[$counter]}"
  3187. command_pos=$counter
  3188. break
  3189. ;;
  3190. esac
  3191. (( counter++ ))
  3192. done
  3193. local binary="${words[0]}"
  3194. if [[ $binary == ?(*/)dockerd ]] ; then
  3195. # for the dockerd binary, we reuse completion of `docker daemon`.
  3196. # dockerd does not have subcommands and global options.
  3197. command=daemon
  3198. command_pos=0
  3199. fi
  3200. local completions_func=_docker_${command}
  3201. declare -F $completions_func >/dev/null && $completions_func
  3202. eval "$previous_extglob_setting"
  3203. return 0
  3204. }
  3205. eval "$__docker_previous_extglob_setting"
  3206. unset __docker_previous_extglob_setting
  3207. complete -F _docker docker dockerd