docker 72 KB

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