docker 67 KB

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