docker 66 KB

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