docker 67 KB

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