docker 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282
  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. local options_with_args="
  753. --build-arg
  754. --cgroup-parent
  755. --cpuset-cpus
  756. --cpuset-mems
  757. --cpu-shares -c
  758. --cpu-period
  759. --cpu-quota
  760. --file -f
  761. --isolation
  762. --label
  763. --memory -m
  764. --memory-swap
  765. --shm-size
  766. --tag -t
  767. --ulimit
  768. "
  769. local boolean_options="
  770. --compress
  771. --disable-content-trust=false
  772. --force-rm
  773. --help
  774. --no-cache
  775. --pull
  776. --quiet -q
  777. --rm
  778. "
  779. local all_options="$options_with_args $boolean_options"
  780. case "$prev" in
  781. --build-arg)
  782. COMPREPLY=( $( compgen -e -- "$cur" ) )
  783. __docker_nospace
  784. return
  785. ;;
  786. --file|-f)
  787. _filedir
  788. return
  789. ;;
  790. --isolation)
  791. __docker_complete_isolation
  792. return
  793. ;;
  794. --tag|-t)
  795. __docker_complete_image_repos_and_tags
  796. return
  797. ;;
  798. $(__docker_to_extglob "$options_with_args") )
  799. return
  800. ;;
  801. esac
  802. case "$cur" in
  803. -*)
  804. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  805. ;;
  806. *)
  807. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  808. if [ $cword -eq $counter ]; then
  809. _filedir -d
  810. fi
  811. ;;
  812. esac
  813. }
  814. _docker_container() {
  815. local subcommands="
  816. attach
  817. commit
  818. cp
  819. create
  820. diff
  821. exec
  822. export
  823. inspect
  824. kill
  825. logs
  826. ls
  827. pause
  828. port
  829. prune
  830. rename
  831. restart
  832. rm
  833. run
  834. start
  835. stats
  836. stop
  837. top
  838. unpause
  839. update
  840. wait
  841. "
  842. local aliases="
  843. list
  844. ps
  845. "
  846. __docker_subcommands "$subcommands $aliases" && return
  847. case "$cur" in
  848. -*)
  849. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  850. ;;
  851. *)
  852. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  853. ;;
  854. esac
  855. }
  856. _docker_container_attach() {
  857. __docker_complete_detach-keys && return
  858. case "$cur" in
  859. -*)
  860. COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) )
  861. ;;
  862. *)
  863. local counter=$(__docker_pos_first_nonflag '--detach-keys')
  864. if [ $cword -eq $counter ]; then
  865. __docker_complete_containers_running
  866. fi
  867. ;;
  868. esac
  869. }
  870. _docker_container_commit() {
  871. case "$prev" in
  872. --author|-a|--change|-c|--message|-m)
  873. return
  874. ;;
  875. esac
  876. case "$cur" in
  877. -*)
  878. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) )
  879. ;;
  880. *)
  881. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  882. if [ $cword -eq $counter ]; then
  883. __docker_complete_containers_all
  884. return
  885. fi
  886. (( counter++ ))
  887. if [ $cword -eq $counter ]; then
  888. __docker_complete_image_repos_and_tags
  889. return
  890. fi
  891. ;;
  892. esac
  893. }
  894. _docker_container_cp() {
  895. case "$cur" in
  896. -*)
  897. COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) )
  898. ;;
  899. *)
  900. local counter=$(__docker_pos_first_nonflag)
  901. if [ $cword -eq $counter ]; then
  902. case "$cur" in
  903. *:)
  904. return
  905. ;;
  906. *)
  907. # combined container and filename completion
  908. _filedir
  909. local files=( ${COMPREPLY[@]} )
  910. __docker_complete_containers_all
  911. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  912. local containers=( ${COMPREPLY[@]} )
  913. COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) )
  914. if [[ "$COMPREPLY" == *: ]]; then
  915. __docker_nospace
  916. fi
  917. return
  918. ;;
  919. esac
  920. fi
  921. (( counter++ ))
  922. if [ $cword -eq $counter ]; then
  923. if [ -e "$prev" ]; then
  924. __docker_complete_containers_all
  925. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  926. __docker_nospace
  927. else
  928. _filedir
  929. fi
  930. return
  931. fi
  932. ;;
  933. esac
  934. }
  935. _docker_container_create() {
  936. _docker_container_run
  937. }
  938. _docker_container_diff() {
  939. case "$cur" in
  940. -*)
  941. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  942. ;;
  943. *)
  944. local counter=$(__docker_pos_first_nonflag)
  945. if [ $cword -eq $counter ]; then
  946. __docker_complete_containers_all
  947. fi
  948. ;;
  949. esac
  950. }
  951. _docker_container_exec() {
  952. __docker_complete_detach-keys && return
  953. case "$prev" in
  954. --user|-u)
  955. __docker_complete_user_group
  956. return
  957. ;;
  958. esac
  959. case "$cur" in
  960. -*)
  961. COMPREPLY=( $( compgen -W "--detach -d --detach-keys -e --env --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  962. ;;
  963. *)
  964. __docker_complete_containers_running
  965. ;;
  966. esac
  967. }
  968. _docker_container_export() {
  969. case "$cur" in
  970. -*)
  971. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  972. ;;
  973. *)
  974. local counter=$(__docker_pos_first_nonflag)
  975. if [ $cword -eq $counter ]; then
  976. __docker_complete_containers_all
  977. fi
  978. ;;
  979. esac
  980. }
  981. _docker_container_inspect() {
  982. case "$prev" in
  983. --format|-f)
  984. return
  985. ;;
  986. --type)
  987. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  988. return
  989. ;;
  990. esac
  991. case "$cur" in
  992. -*)
  993. COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) )
  994. ;;
  995. *)
  996. case $(__docker_value_of_option --type) in
  997. '')
  998. __docker_complete_containers_and_images
  999. ;;
  1000. container)
  1001. __docker_complete_containers_all
  1002. ;;
  1003. image)
  1004. __docker_complete_images
  1005. ;;
  1006. esac
  1007. esac
  1008. }
  1009. _docker_container_kill() {
  1010. case "$prev" in
  1011. --signal|-s)
  1012. __docker_complete_signals
  1013. return
  1014. ;;
  1015. esac
  1016. case "$cur" in
  1017. -*)
  1018. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  1019. ;;
  1020. *)
  1021. __docker_complete_containers_running
  1022. ;;
  1023. esac
  1024. }
  1025. _docker_container_logs() {
  1026. case "$prev" in
  1027. --since|--tail)
  1028. return
  1029. ;;
  1030. esac
  1031. case "$cur" in
  1032. -*)
  1033. COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  1034. ;;
  1035. *)
  1036. local counter=$(__docker_pos_first_nonflag '--since|--tail')
  1037. if [ $cword -eq $counter ]; then
  1038. __docker_complete_containers_all
  1039. fi
  1040. ;;
  1041. esac
  1042. }
  1043. _docker_container_list() {
  1044. _docker_container_ls
  1045. }
  1046. _docker_container_ls() {
  1047. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1048. case "$key" in
  1049. ancestor)
  1050. cur="${cur##*=}"
  1051. __docker_complete_images
  1052. return
  1053. ;;
  1054. before)
  1055. __docker_complete_containers_all --cur "${cur##*=}"
  1056. return
  1057. ;;
  1058. id)
  1059. __docker_complete_containers_all --cur "${cur##*=}" --id
  1060. return
  1061. ;;
  1062. is-task)
  1063. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  1064. return
  1065. ;;
  1066. name)
  1067. __docker_complete_containers_all --cur "${cur##*=}" --name
  1068. return
  1069. ;;
  1070. network)
  1071. __docker_complete_networks --cur "${cur##*=}"
  1072. return
  1073. ;;
  1074. since)
  1075. __docker_complete_containers_all --cur "${cur##*=}"
  1076. return
  1077. ;;
  1078. status)
  1079. COMPREPLY=( $( compgen -W "created dead exited paused restarting running removing" -- "${cur##*=}" ) )
  1080. return
  1081. ;;
  1082. volume)
  1083. __docker_complete_volumes --cur "${cur##*=}"
  1084. return
  1085. ;;
  1086. esac
  1087. case "$prev" in
  1088. --filter|-f)
  1089. COMPREPLY=( $( compgen -S = -W "ancestor before exited id label name network since status volume" -- "$cur" ) )
  1090. __docker_nospace
  1091. return
  1092. ;;
  1093. --format|--last|-n)
  1094. return
  1095. ;;
  1096. esac
  1097. case "$cur" in
  1098. -*)
  1099. COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) )
  1100. ;;
  1101. esac
  1102. }
  1103. _docker_container_pause() {
  1104. case "$cur" in
  1105. -*)
  1106. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1107. ;;
  1108. *)
  1109. local counter=$(__docker_pos_first_nonflag)
  1110. if [ $cword -eq $counter ]; then
  1111. __docker_complete_containers_running
  1112. fi
  1113. ;;
  1114. esac
  1115. }
  1116. _docker_container_port() {
  1117. case "$cur" in
  1118. -*)
  1119. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1120. ;;
  1121. *)
  1122. local counter=$(__docker_pos_first_nonflag)
  1123. if [ $cword -eq $counter ]; then
  1124. __docker_complete_containers_all
  1125. fi
  1126. ;;
  1127. esac
  1128. }
  1129. # TODO new command
  1130. _docker_container_prune() {
  1131. :
  1132. }
  1133. _docker_container_ps() {
  1134. _docker_container_ls
  1135. }
  1136. _docker_container_rename() {
  1137. case "$cur" in
  1138. -*)
  1139. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1140. ;;
  1141. *)
  1142. local counter=$(__docker_pos_first_nonflag)
  1143. if [ $cword -eq $counter ]; then
  1144. __docker_complete_containers_all
  1145. fi
  1146. ;;
  1147. esac
  1148. }
  1149. _docker_container_restart() {
  1150. case "$prev" in
  1151. --time|-t)
  1152. return
  1153. ;;
  1154. esac
  1155. case "$cur" in
  1156. -*)
  1157. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1158. ;;
  1159. *)
  1160. __docker_complete_containers_all
  1161. ;;
  1162. esac
  1163. }
  1164. _docker_container_rm() {
  1165. case "$cur" in
  1166. -*)
  1167. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  1168. ;;
  1169. *)
  1170. for arg in "${COMP_WORDS[@]}"; do
  1171. case "$arg" in
  1172. --force|-f)
  1173. __docker_complete_containers_all
  1174. return
  1175. ;;
  1176. esac
  1177. done
  1178. __docker_complete_containers_stopped
  1179. ;;
  1180. esac
  1181. }
  1182. _docker_container_run() {
  1183. local options_with_args="
  1184. --add-host
  1185. --attach -a
  1186. --blkio-weight
  1187. --blkio-weight-device
  1188. --cap-add
  1189. --cap-drop
  1190. --cgroup-parent
  1191. --cidfile
  1192. --cpu-period
  1193. --cpu-quota
  1194. --cpuset-cpus
  1195. --cpuset-mems
  1196. --cpu-shares -c
  1197. --device
  1198. --device-read-bps
  1199. --device-read-iops
  1200. --device-write-bps
  1201. --device-write-iops
  1202. --dns
  1203. --dns-opt
  1204. --dns-search
  1205. --entrypoint
  1206. --env -e
  1207. --env-file
  1208. --expose
  1209. --group-add
  1210. --hostname -h
  1211. --ip
  1212. --ip6
  1213. --ipc
  1214. --isolation
  1215. --kernel-memory
  1216. --label-file
  1217. --label -l
  1218. --link
  1219. --link-local-ip
  1220. --log-driver
  1221. --log-opt
  1222. --mac-address
  1223. --memory -m
  1224. --memory-swap
  1225. --memory-swappiness
  1226. --memory-reservation
  1227. --name
  1228. --network
  1229. --network-alias
  1230. --oom-score-adj
  1231. --pid
  1232. --pids-limit
  1233. --publish -p
  1234. --restart
  1235. --runtime
  1236. --security-opt
  1237. --shm-size
  1238. --stop-signal
  1239. --stop-timeout
  1240. --storage-opt
  1241. --tmpfs
  1242. --sysctl
  1243. --ulimit
  1244. --user -u
  1245. --userns
  1246. --uts
  1247. --volume-driver
  1248. --volumes-from
  1249. --volume -v
  1250. --workdir -w
  1251. "
  1252. local boolean_options="
  1253. --disable-content-trust=false
  1254. --help
  1255. --interactive -i
  1256. --oom-kill-disable
  1257. --privileged
  1258. --publish-all -P
  1259. --read-only
  1260. --tty -t
  1261. "
  1262. if [ "$command" = "run" -o "$subcommand" = "run" ] ; then
  1263. options_with_args="$options_with_args
  1264. --detach-keys
  1265. --health-cmd
  1266. --health-interval
  1267. --health-retries
  1268. --health-timeout
  1269. "
  1270. boolean_options="$boolean_options
  1271. --detach -d
  1272. --no-healthcheck
  1273. --rm
  1274. --sig-proxy=false
  1275. "
  1276. __docker_complete_detach-keys && return
  1277. fi
  1278. local all_options="$options_with_args $boolean_options"
  1279. __docker_complete_log_driver_options && return
  1280. __docker_complete_restart && return
  1281. local key=$(__docker_map_key_of_current_option '--security-opt')
  1282. case "$key" in
  1283. label)
  1284. [[ $cur == *: ]] && return
  1285. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  1286. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  1287. __docker_nospace
  1288. fi
  1289. return
  1290. ;;
  1291. seccomp)
  1292. local cur=${cur##*=}
  1293. _filedir
  1294. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  1295. return
  1296. ;;
  1297. esac
  1298. case "$prev" in
  1299. --add-host)
  1300. case "$cur" in
  1301. *:)
  1302. __docker_complete_resolved_hostname
  1303. return
  1304. ;;
  1305. esac
  1306. ;;
  1307. --attach|-a)
  1308. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  1309. return
  1310. ;;
  1311. --cap-add|--cap-drop)
  1312. __docker_complete_capabilities
  1313. return
  1314. ;;
  1315. --cidfile|--env-file|--label-file)
  1316. _filedir
  1317. return
  1318. ;;
  1319. --device|--tmpfs|--volume|-v)
  1320. case "$cur" in
  1321. *:*)
  1322. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  1323. ;;
  1324. '')
  1325. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  1326. __docker_nospace
  1327. ;;
  1328. /*)
  1329. _filedir
  1330. __docker_nospace
  1331. ;;
  1332. esac
  1333. return
  1334. ;;
  1335. --env|-e)
  1336. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  1337. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1338. __docker_nospace
  1339. return
  1340. ;;
  1341. --ipc)
  1342. case "$cur" in
  1343. *:*)
  1344. cur="${cur#*:}"
  1345. __docker_complete_containers_running
  1346. ;;
  1347. *)
  1348. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1349. if [ "$COMPREPLY" = "container:" ]; then
  1350. __docker_nospace
  1351. fi
  1352. ;;
  1353. esac
  1354. return
  1355. ;;
  1356. --isolation)
  1357. __docker_complete_isolation
  1358. return
  1359. ;;
  1360. --link)
  1361. case "$cur" in
  1362. *:*)
  1363. ;;
  1364. *)
  1365. __docker_complete_containers_running
  1366. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1367. __docker_nospace
  1368. ;;
  1369. esac
  1370. return
  1371. ;;
  1372. --log-driver)
  1373. __docker_complete_log_drivers
  1374. return
  1375. ;;
  1376. --log-opt)
  1377. __docker_complete_log_options
  1378. return
  1379. ;;
  1380. --network)
  1381. case "$cur" in
  1382. container:*)
  1383. __docker_complete_containers_all --cur "${cur#*:}"
  1384. ;;
  1385. *)
  1386. COMPREPLY=( $( compgen -W "$(__docker_plugins --type Network) $(__docker_networks) container:" -- "$cur") )
  1387. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1388. __docker_nospace
  1389. fi
  1390. ;;
  1391. esac
  1392. return
  1393. ;;
  1394. --pid)
  1395. case "$cur" in
  1396. *:*)
  1397. __docker_complete_containers_running --cur "${cur#*:}"
  1398. ;;
  1399. *)
  1400. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1401. if [ "$COMPREPLY" = "container:" ]; then
  1402. __docker_nospace
  1403. fi
  1404. ;;
  1405. esac
  1406. return
  1407. ;;
  1408. --runtime)
  1409. __docker_complete_runtimes
  1410. return
  1411. ;;
  1412. --security-opt)
  1413. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  1414. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  1415. __docker_nospace
  1416. fi
  1417. return
  1418. ;;
  1419. --storage-opt)
  1420. COMPREPLY=( $( compgen -W "size" -S = -- "$cur") )
  1421. __docker_nospace
  1422. return
  1423. ;;
  1424. --user|-u)
  1425. __docker_complete_user_group
  1426. return
  1427. ;;
  1428. --userns)
  1429. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  1430. return
  1431. ;;
  1432. --volume-driver)
  1433. __docker_complete_plugins --type Volume
  1434. return
  1435. ;;
  1436. --volumes-from)
  1437. __docker_complete_containers_all
  1438. return
  1439. ;;
  1440. $(__docker_to_extglob "$options_with_args") )
  1441. return
  1442. ;;
  1443. esac
  1444. case "$cur" in
  1445. -*)
  1446. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1447. ;;
  1448. *)
  1449. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1450. if [ $cword -eq $counter ]; then
  1451. __docker_complete_images
  1452. fi
  1453. ;;
  1454. esac
  1455. }
  1456. _docker_container_start() {
  1457. __docker_complete_detach-keys && return
  1458. case "$cur" in
  1459. -*)
  1460. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  1461. ;;
  1462. *)
  1463. __docker_complete_containers_stopped
  1464. ;;
  1465. esac
  1466. }
  1467. _docker_container_stats() {
  1468. case "$prev" in
  1469. --format)
  1470. return
  1471. ;;
  1472. esac
  1473. case "$cur" in
  1474. -*)
  1475. COMPREPLY=( $( compgen -W "--all -a --format --help --no-stream" -- "$cur" ) )
  1476. ;;
  1477. *)
  1478. __docker_complete_containers_running
  1479. ;;
  1480. esac
  1481. }
  1482. _docker_container_stop() {
  1483. _docker_stop
  1484. }
  1485. _docker_container_top() {
  1486. _docker_top
  1487. }
  1488. _docker_container_unpause() {
  1489. _docker_unpause
  1490. }
  1491. _docker_container_update() {
  1492. _docker_update
  1493. }
  1494. _docker_container_wait() {
  1495. _docker_wait
  1496. }
  1497. _docker_commit() {
  1498. _docker_container_commit
  1499. }
  1500. _docker_cp() {
  1501. _docker_container_cp
  1502. }
  1503. _docker_create() {
  1504. _docker_container_run
  1505. }
  1506. _docker_daemon() {
  1507. local boolean_options="
  1508. $global_boolean_options
  1509. --disable-legacy-registry
  1510. --help
  1511. --icc=false
  1512. --ip-forward=false
  1513. --ip-masq=false
  1514. --iptables=false
  1515. --ipv6
  1516. --live-restore
  1517. --raw-logs
  1518. --selinux-enabled
  1519. --userland-proxy=false
  1520. "
  1521. local options_with_args="
  1522. $global_options_with_args
  1523. --add-runtime
  1524. --api-cors-header
  1525. --authorization-plugin
  1526. --bip
  1527. --bridge -b
  1528. --cgroup-parent
  1529. --cluster-advertise
  1530. --cluster-store
  1531. --cluster-store-opt
  1532. --config-file
  1533. --containerd
  1534. --default-gateway
  1535. --default-gateway-v6
  1536. --default-ulimit
  1537. --dns
  1538. --dns-search
  1539. --dns-opt
  1540. --exec-opt
  1541. --exec-root
  1542. --fixed-cidr
  1543. --fixed-cidr-v6
  1544. --graph -g
  1545. --group -G
  1546. --init-path
  1547. --insecure-registry
  1548. --ip
  1549. --label
  1550. --log-driver
  1551. --log-opt
  1552. --max-concurrent-downloads
  1553. --max-concurrent-uploads
  1554. --mtu
  1555. --oom-score-adjust
  1556. --pidfile -p
  1557. --registry-mirror
  1558. --shutdown-timeout
  1559. --storage-driver -s
  1560. --storage-opt
  1561. --userns-remap
  1562. "
  1563. __docker_complete_log_driver_options && return
  1564. key=$(__docker_map_key_of_current_option '--cluster-store-opt')
  1565. case "$key" in
  1566. kv.*file)
  1567. cur=${cur##*=}
  1568. _filedir
  1569. return
  1570. ;;
  1571. esac
  1572. local key=$(__docker_map_key_of_current_option '--storage-opt')
  1573. case "$key" in
  1574. dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion)
  1575. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1576. return
  1577. ;;
  1578. dm.fs)
  1579. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) )
  1580. return
  1581. ;;
  1582. dm.thinpooldev)
  1583. cur=${cur##*=}
  1584. _filedir
  1585. return
  1586. ;;
  1587. esac
  1588. case "$prev" in
  1589. --authorization-plugin)
  1590. __docker_complete_plugins --type Authorization
  1591. return
  1592. ;;
  1593. --cluster-store)
  1594. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  1595. __docker_nospace
  1596. return
  1597. ;;
  1598. --cluster-store-opt)
  1599. COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) )
  1600. __docker_nospace
  1601. return
  1602. ;;
  1603. --config-file|--containerd|--init-path|--pidfile|-p|--tlscacert|--tlscert|--tlskey)
  1604. _filedir
  1605. return
  1606. ;;
  1607. --exec-root|--graph|-g)
  1608. _filedir -d
  1609. return
  1610. ;;
  1611. --log-driver)
  1612. __docker_complete_log_drivers
  1613. return
  1614. ;;
  1615. --storage-driver|-s)
  1616. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  1617. return
  1618. ;;
  1619. --storage-opt)
  1620. local btrfs_options="btrfs.min_space"
  1621. local devicemapper_options="
  1622. dm.basesize
  1623. dm.blkdiscard
  1624. dm.blocksize
  1625. dm.fs
  1626. dm.loopdatasize
  1627. dm.loopmetadatasize
  1628. dm.min_free_space
  1629. dm.mkfsarg
  1630. dm.mountopt
  1631. dm.override_udev_sync_check
  1632. dm.thinpooldev
  1633. dm.use_deferred_deletion
  1634. dm.use_deferred_removal
  1635. "
  1636. local zfs_options="zfs.fsname"
  1637. case $(__docker_value_of_option '--storage-driver|-s') in
  1638. '')
  1639. COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) )
  1640. ;;
  1641. btrfs)
  1642. COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) )
  1643. ;;
  1644. devicemapper)
  1645. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  1646. ;;
  1647. zfs)
  1648. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  1649. ;;
  1650. *)
  1651. return
  1652. ;;
  1653. esac
  1654. __docker_nospace
  1655. return
  1656. ;;
  1657. --log-level|-l)
  1658. __docker_complete_log_levels
  1659. return
  1660. ;;
  1661. --log-opt)
  1662. __docker_complete_log_options
  1663. return
  1664. ;;
  1665. --userns-remap)
  1666. __docker_complete_user_group
  1667. return
  1668. ;;
  1669. $(__docker_to_extglob "$options_with_args") )
  1670. return
  1671. ;;
  1672. esac
  1673. case "$cur" in
  1674. -*)
  1675. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1676. ;;
  1677. esac
  1678. }
  1679. _docker_diff() {
  1680. _docker_container_diff
  1681. }
  1682. _docker_events() {
  1683. local key=$(__docker_map_key_of_current_option '-f|--filter')
  1684. case "$key" in
  1685. container)
  1686. __docker_complete_containers_all --cur "${cur##*=}"
  1687. return
  1688. ;;
  1689. daemon)
  1690. local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
  1691. COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
  1692. return
  1693. ;;
  1694. event)
  1695. COMPREPLY=( $( compgen -W "
  1696. attach
  1697. commit
  1698. connect
  1699. copy
  1700. create
  1701. delete
  1702. destroy
  1703. detach
  1704. die
  1705. disconnect
  1706. exec_create
  1707. exec_detach
  1708. exec_start
  1709. export
  1710. health_status
  1711. import
  1712. kill
  1713. load
  1714. mount
  1715. oom
  1716. pause
  1717. pull
  1718. push
  1719. reload
  1720. rename
  1721. resize
  1722. restart
  1723. save
  1724. start
  1725. stop
  1726. tag
  1727. top
  1728. unmount
  1729. unpause
  1730. untag
  1731. update
  1732. " -- "${cur##*=}" ) )
  1733. return
  1734. ;;
  1735. image)
  1736. cur="${cur##*=}"
  1737. __docker_complete_images
  1738. return
  1739. ;;
  1740. network)
  1741. __docker_complete_networks --cur "${cur##*=}"
  1742. return
  1743. ;;
  1744. type)
  1745. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  1746. return
  1747. ;;
  1748. volume)
  1749. __docker_complete_volumes --cur "${cur##*=}"
  1750. return
  1751. ;;
  1752. esac
  1753. case "$prev" in
  1754. --filter|-f)
  1755. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  1756. __docker_nospace
  1757. return
  1758. ;;
  1759. --since|--until)
  1760. return
  1761. ;;
  1762. esac
  1763. case "$cur" in
  1764. -*)
  1765. COMPREPLY=( $( compgen -W "--filter -f --help --since --until --format" -- "$cur" ) )
  1766. ;;
  1767. esac
  1768. }
  1769. _docker_exec() {
  1770. _docker_container_exec
  1771. }
  1772. _docker_export() {
  1773. _docker_container_export
  1774. }
  1775. _docker_help() {
  1776. local counter=$(__docker_pos_first_nonflag)
  1777. if [ $cword -eq $counter ]; then
  1778. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  1779. fi
  1780. }
  1781. _docker_history() {
  1782. case "$cur" in
  1783. -*)
  1784. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  1785. ;;
  1786. *)
  1787. local counter=$(__docker_pos_first_nonflag)
  1788. if [ $cword -eq $counter ]; then
  1789. __docker_complete_images
  1790. fi
  1791. ;;
  1792. esac
  1793. }
  1794. _docker_images() {
  1795. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1796. case "$key" in
  1797. before)
  1798. cur="${cur##*=}"
  1799. __docker_complete_images
  1800. return
  1801. ;;
  1802. dangling)
  1803. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1804. return
  1805. ;;
  1806. label)
  1807. return
  1808. ;;
  1809. since)
  1810. cur="${cur##*=}"
  1811. __docker_complete_images
  1812. return
  1813. ;;
  1814. esac
  1815. case "$prev" in
  1816. --filter|-f)
  1817. COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) )
  1818. __docker_nospace
  1819. return
  1820. ;;
  1821. --format)
  1822. return
  1823. ;;
  1824. esac
  1825. case "$cur" in
  1826. -*)
  1827. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1828. ;;
  1829. =)
  1830. return
  1831. ;;
  1832. *)
  1833. __docker_complete_image_repos
  1834. ;;
  1835. esac
  1836. }
  1837. _docker_import() {
  1838. case "$prev" in
  1839. --change|-c|--message|-m)
  1840. return
  1841. ;;
  1842. esac
  1843. case "$cur" in
  1844. -*)
  1845. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1846. ;;
  1847. *)
  1848. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1849. if [ $cword -eq $counter ]; then
  1850. return
  1851. fi
  1852. (( counter++ ))
  1853. if [ $cword -eq $counter ]; then
  1854. __docker_complete_image_repos_and_tags
  1855. return
  1856. fi
  1857. ;;
  1858. esac
  1859. }
  1860. _docker_info() {
  1861. case "$prev" in
  1862. --format|-f)
  1863. return
  1864. ;;
  1865. esac
  1866. case "$cur" in
  1867. -*)
  1868. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1869. ;;
  1870. esac
  1871. }
  1872. _docker_inspect() {
  1873. _docker_container_inspect
  1874. }
  1875. _docker_kill() {
  1876. _docker_container_kill
  1877. }
  1878. _docker_load() {
  1879. case "$prev" in
  1880. --input|-i)
  1881. _filedir
  1882. return
  1883. ;;
  1884. esac
  1885. case "$cur" in
  1886. -*)
  1887. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1888. ;;
  1889. esac
  1890. }
  1891. _docker_login() {
  1892. case "$prev" in
  1893. --password|-p|--username|-u)
  1894. return
  1895. ;;
  1896. esac
  1897. case "$cur" in
  1898. -*)
  1899. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  1900. ;;
  1901. esac
  1902. }
  1903. _docker_logout() {
  1904. case "$cur" in
  1905. -*)
  1906. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1907. ;;
  1908. esac
  1909. }
  1910. _docker_logs() {
  1911. _docker_container_logs
  1912. }
  1913. _docker_network_connect() {
  1914. local options_with_args="
  1915. --alias
  1916. --ip
  1917. --ip6
  1918. --link
  1919. --link-local-ip
  1920. "
  1921. local boolean_options="
  1922. --help
  1923. "
  1924. case "$prev" in
  1925. --link)
  1926. case "$cur" in
  1927. *:*)
  1928. ;;
  1929. *)
  1930. __docker_complete_containers_running
  1931. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1932. __docker_nospace
  1933. ;;
  1934. esac
  1935. return
  1936. ;;
  1937. $(__docker_to_extglob "$options_with_args") )
  1938. return
  1939. ;;
  1940. esac
  1941. case "$cur" in
  1942. -*)
  1943. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1944. ;;
  1945. *)
  1946. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1947. if [ $cword -eq $counter ]; then
  1948. __docker_complete_networks
  1949. elif [ $cword -eq $(($counter + 1)) ]; then
  1950. __docker_complete_containers_all
  1951. fi
  1952. ;;
  1953. esac
  1954. }
  1955. _docker_network_create() {
  1956. case "$prev" in
  1957. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  1958. return
  1959. ;;
  1960. --ipam-driver)
  1961. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  1962. return
  1963. ;;
  1964. --driver|-d)
  1965. # remove drivers that allow one instance only, add drivers missing in `docker info`
  1966. __docker_complete_plugins --type Network --remove host --remove null --add macvlan
  1967. return
  1968. ;;
  1969. --label)
  1970. return
  1971. ;;
  1972. esac
  1973. case "$cur" in
  1974. -*)
  1975. COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  1976. ;;
  1977. esac
  1978. }
  1979. _docker_network_disconnect() {
  1980. case "$cur" in
  1981. -*)
  1982. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1983. ;;
  1984. *)
  1985. local counter=$(__docker_pos_first_nonflag)
  1986. if [ $cword -eq $counter ]; then
  1987. __docker_complete_networks
  1988. elif [ $cword -eq $(($counter + 1)) ]; then
  1989. __docker_complete_containers_in_network "$prev"
  1990. fi
  1991. ;;
  1992. esac
  1993. }
  1994. _docker_network_inspect() {
  1995. case "$prev" in
  1996. --format|-f)
  1997. return
  1998. ;;
  1999. esac
  2000. case "$cur" in
  2001. -*)
  2002. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2003. ;;
  2004. *)
  2005. __docker_complete_networks
  2006. esac
  2007. }
  2008. _docker_network_ls() {
  2009. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2010. case "$key" in
  2011. driver)
  2012. __docker_complete_plugins --cur "${cur##*=}" --type Network --add macvlan
  2013. return
  2014. ;;
  2015. id)
  2016. __docker_complete_networks --cur "${cur##*=}" --id
  2017. return
  2018. ;;
  2019. name)
  2020. __docker_complete_networks --cur "${cur##*=}" --name
  2021. return
  2022. ;;
  2023. type)
  2024. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  2025. return
  2026. ;;
  2027. esac
  2028. case "$prev" in
  2029. --filter|-f)
  2030. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  2031. __docker_nospace
  2032. return
  2033. ;;
  2034. --format)
  2035. return
  2036. ;;
  2037. esac
  2038. case "$cur" in
  2039. -*)
  2040. COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  2041. ;;
  2042. esac
  2043. }
  2044. _docker_network_rm() {
  2045. case "$cur" in
  2046. -*)
  2047. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2048. ;;
  2049. *)
  2050. __docker_complete_networks --filter type=custom
  2051. esac
  2052. }
  2053. _docker_network() {
  2054. local subcommands="
  2055. connect
  2056. create
  2057. disconnect
  2058. inspect
  2059. ls
  2060. rm
  2061. "
  2062. __docker_subcommands "$subcommands" && return
  2063. case "$cur" in
  2064. -*)
  2065. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2066. ;;
  2067. *)
  2068. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2069. ;;
  2070. esac
  2071. }
  2072. _docker_service() {
  2073. local subcommands="
  2074. create
  2075. inspect
  2076. ls list
  2077. rm remove
  2078. scale
  2079. ps
  2080. update
  2081. "
  2082. __docker_subcommands "$subcommands" && return
  2083. case "$cur" in
  2084. -*)
  2085. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2086. ;;
  2087. *)
  2088. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2089. ;;
  2090. esac
  2091. }
  2092. _docker_service_create() {
  2093. _docker_service_update
  2094. }
  2095. _docker_service_inspect() {
  2096. case "$prev" in
  2097. --format|-f)
  2098. return
  2099. ;;
  2100. esac
  2101. case "$cur" in
  2102. -*)
  2103. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  2104. ;;
  2105. *)
  2106. __docker_complete_services
  2107. esac
  2108. }
  2109. _docker_service_list() {
  2110. _docker_service_ls
  2111. }
  2112. _docker_service_ls() {
  2113. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2114. case "$key" in
  2115. id)
  2116. __docker_complete_services --cur "${cur##*=}" --id
  2117. return
  2118. ;;
  2119. name)
  2120. __docker_complete_services --cur "${cur##*=}" --name
  2121. return
  2122. ;;
  2123. esac
  2124. case "$prev" in
  2125. --filter|-f)
  2126. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  2127. __docker_nospace
  2128. return
  2129. ;;
  2130. esac
  2131. case "$cur" in
  2132. -*)
  2133. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  2134. ;;
  2135. esac
  2136. }
  2137. _docker_service_remove() {
  2138. _docker_service_rm
  2139. }
  2140. _docker_service_rm() {
  2141. case "$cur" in
  2142. -*)
  2143. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2144. ;;
  2145. *)
  2146. __docker_complete_services
  2147. esac
  2148. }
  2149. _docker_service_scale() {
  2150. case "$cur" in
  2151. -*)
  2152. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2153. ;;
  2154. *)
  2155. __docker_complete_services
  2156. __docker_append_to_completions "="
  2157. __docker_nospace
  2158. ;;
  2159. esac
  2160. }
  2161. _docker_service_ps() {
  2162. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2163. case "$key" in
  2164. desired-state)
  2165. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  2166. return
  2167. ;;
  2168. name)
  2169. __docker_complete_services --cur "${cur##*=}" --name
  2170. return
  2171. ;;
  2172. esac
  2173. case "$prev" in
  2174. --filter|-f)
  2175. COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) )
  2176. __docker_nospace
  2177. return
  2178. ;;
  2179. esac
  2180. case "$cur" in
  2181. -*)
  2182. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  2183. ;;
  2184. *)
  2185. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  2186. if [ $cword -eq $counter ]; then
  2187. __docker_complete_services
  2188. fi
  2189. ;;
  2190. esac
  2191. }
  2192. _docker_service_update() {
  2193. local $subcommand="${words[$subcommand_pos]}"
  2194. local options_with_args="
  2195. --constraint
  2196. --endpoint-mode
  2197. --env -e
  2198. --group-add
  2199. --label -l
  2200. --limit-cpu
  2201. --limit-memory
  2202. --log-driver
  2203. --log-opt
  2204. --mount
  2205. --name
  2206. --network
  2207. --publish -p
  2208. --replicas
  2209. --reserve-cpu
  2210. --reserve-memory
  2211. --restart-condition
  2212. --restart-delay
  2213. --restart-max-attempts
  2214. --restart-window
  2215. --rollback
  2216. --stop-grace-period
  2217. --update-delay
  2218. --update-failure-action
  2219. --update-max-failure-ratio
  2220. --update-monitor
  2221. --update-parallelism
  2222. --user -u
  2223. --workdir -w
  2224. "
  2225. local boolean_options="
  2226. --help
  2227. --with-registry-auth
  2228. "
  2229. __docker_complete_log_driver_options && return
  2230. if [ "$subcommand" = "create" ] ; then
  2231. options_with_args="$options_with_args
  2232. --container-label
  2233. --mode
  2234. "
  2235. case "$prev" in
  2236. --mode)
  2237. COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) )
  2238. return
  2239. ;;
  2240. esac
  2241. fi
  2242. if [ "$subcommand" = "update" ] ; then
  2243. options_with_args="$options_with_args
  2244. --arg
  2245. --container-label-add
  2246. --container-label-rm
  2247. --group-rm
  2248. --image
  2249. "
  2250. case "$prev" in
  2251. --group-rm)
  2252. COMPREPLY=( $(compgen -g -- "$cur") )
  2253. return
  2254. ;;
  2255. --image)
  2256. __docker_complete_image_repos_and_tags
  2257. return
  2258. ;;
  2259. esac
  2260. fi
  2261. case "$prev" in
  2262. --endpoint-mode)
  2263. COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) )
  2264. return
  2265. ;;
  2266. --env|-e)
  2267. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  2268. COMPREPLY=( $( compgen -e -- "$cur" ) )
  2269. __docker_nospace
  2270. return
  2271. ;;
  2272. --group-add)
  2273. COMPREPLY=( $(compgen -g -- "$cur") )
  2274. return
  2275. ;;
  2276. --log-driver)
  2277. __docker_complete_log_drivers
  2278. return
  2279. ;;
  2280. --log-opt)
  2281. __docker_complete_log_options
  2282. return
  2283. ;;
  2284. --network)
  2285. __docker_complete_networks
  2286. return
  2287. ;;
  2288. --restart-condition)
  2289. COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) )
  2290. return
  2291. ;;
  2292. --user|-u)
  2293. __docker_complete_user_group
  2294. return
  2295. ;;
  2296. $(__docker_to_extglob "$options_with_args") )
  2297. return
  2298. ;;
  2299. esac
  2300. case "$cur" in
  2301. -*)
  2302. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  2303. ;;
  2304. *)
  2305. if [ "$subcommand" = "update" ] ; then
  2306. __docker_complete_services
  2307. fi
  2308. esac
  2309. }
  2310. _docker_swarm() {
  2311. local subcommands="
  2312. init
  2313. join
  2314. join-token
  2315. leave
  2316. update
  2317. "
  2318. __docker_subcommands "$subcommands" && return
  2319. case "$cur" in
  2320. -*)
  2321. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2322. ;;
  2323. *)
  2324. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2325. ;;
  2326. esac
  2327. }
  2328. _docker_swarm_init() {
  2329. case "$prev" in
  2330. --advertise-addr)
  2331. if [[ $cur == *: ]] ; then
  2332. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2333. else
  2334. __docker_complete_local_interfaces
  2335. __docker_nospace
  2336. fi
  2337. return
  2338. ;;
  2339. --listen-addr)
  2340. if [[ $cur == *: ]] ; then
  2341. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2342. else
  2343. __docker_complete_local_interfaces --add 0.0.0.0
  2344. __docker_nospace
  2345. fi
  2346. return
  2347. ;;
  2348. esac
  2349. case "$cur" in
  2350. -*)
  2351. COMPREPLY=( $( compgen -W "--advertise-addr --force-new-cluster --help --listen-addr" -- "$cur" ) )
  2352. ;;
  2353. esac
  2354. }
  2355. _docker_swarm_join() {
  2356. case "$prev" in
  2357. --advertise-addr)
  2358. if [[ $cur == *: ]] ; then
  2359. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2360. else
  2361. __docker_complete_local_interfaces
  2362. __docker_nospace
  2363. fi
  2364. return
  2365. ;;
  2366. --listen-addr)
  2367. if [[ $cur == *: ]] ; then
  2368. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2369. else
  2370. __docker_complete_local_interfaces --add 0.0.0.0
  2371. __docker_nospace
  2372. fi
  2373. return
  2374. ;;
  2375. --token)
  2376. return
  2377. ;;
  2378. esac
  2379. case "$cur" in
  2380. -*)
  2381. COMPREPLY=( $( compgen -W "--advertise-addr --help --listen-addr --token" -- "$cur" ) )
  2382. ;;
  2383. *:)
  2384. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2385. ;;
  2386. esac
  2387. }
  2388. _docker_swarm_join-token() {
  2389. case "$cur" in
  2390. -*)
  2391. COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) )
  2392. ;;
  2393. *)
  2394. local counter=$( __docker_pos_first_nonflag )
  2395. if [ $cword -eq $counter ]; then
  2396. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  2397. fi
  2398. ;;
  2399. esac
  2400. }
  2401. _docker_swarm_leave() {
  2402. case "$cur" in
  2403. -*)
  2404. COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) )
  2405. ;;
  2406. esac
  2407. }
  2408. _docker_swarm_update() {
  2409. case "$prev" in
  2410. --cert-expiry|--dispatcher-heartbeat|--task-history-limit)
  2411. return
  2412. ;;
  2413. esac
  2414. case "$cur" in
  2415. -*)
  2416. COMPREPLY=( $( compgen -W "--cert-expiry --dispatcher-heartbeat --help --task-history-limit" -- "$cur" ) )
  2417. ;;
  2418. esac
  2419. }
  2420. _docker_node() {
  2421. local subcommands="
  2422. demote
  2423. inspect
  2424. ls list
  2425. promote
  2426. rm remove
  2427. ps
  2428. update
  2429. "
  2430. __docker_subcommands "$subcommands" && return
  2431. case "$cur" in
  2432. -*)
  2433. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2434. ;;
  2435. *)
  2436. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2437. ;;
  2438. esac
  2439. }
  2440. _docker_node_demote() {
  2441. case "$cur" in
  2442. -*)
  2443. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2444. ;;
  2445. *)
  2446. __docker_complete_nodes --filter role=manager
  2447. esac
  2448. }
  2449. _docker_node_inspect() {
  2450. case "$prev" in
  2451. --format|-f)
  2452. return
  2453. ;;
  2454. esac
  2455. case "$cur" in
  2456. -*)
  2457. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  2458. ;;
  2459. *)
  2460. __docker_complete_nodes_plus_self
  2461. esac
  2462. }
  2463. _docker_node_list() {
  2464. _docker_node_ls
  2465. }
  2466. _docker_node_ls() {
  2467. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2468. case "$key" in
  2469. id)
  2470. __docker_complete_nodes --cur "${cur##*=}" --id
  2471. return
  2472. ;;
  2473. name)
  2474. __docker_complete_nodes --cur "${cur##*=}" --name
  2475. return
  2476. ;;
  2477. esac
  2478. case "$prev" in
  2479. --filter|-f)
  2480. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  2481. __docker_nospace
  2482. return
  2483. ;;
  2484. esac
  2485. case "$cur" in
  2486. -*)
  2487. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  2488. ;;
  2489. esac
  2490. }
  2491. _docker_node_promote() {
  2492. case "$cur" in
  2493. -*)
  2494. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2495. ;;
  2496. *)
  2497. __docker_complete_nodes --filter role=worker
  2498. esac
  2499. }
  2500. _docker_node_remove() {
  2501. _docker_node_rm
  2502. }
  2503. _docker_node_rm() {
  2504. case "$cur" in
  2505. -*)
  2506. COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) )
  2507. ;;
  2508. *)
  2509. __docker_complete_nodes
  2510. esac
  2511. }
  2512. _docker_node_ps() {
  2513. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2514. case "$key" in
  2515. desired-state)
  2516. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  2517. return
  2518. ;;
  2519. name)
  2520. __docker_complete_services --cur "${cur##*=}" --name
  2521. return
  2522. ;;
  2523. esac
  2524. case "$prev" in
  2525. --filter|-f)
  2526. COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) )
  2527. __docker_nospace
  2528. return
  2529. ;;
  2530. esac
  2531. case "$cur" in
  2532. -*)
  2533. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  2534. ;;
  2535. *)
  2536. __docker_complete_nodes_plus_self
  2537. ;;
  2538. esac
  2539. }
  2540. _docker_node_update() {
  2541. case "$prev" in
  2542. --availability)
  2543. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  2544. return
  2545. ;;
  2546. --role)
  2547. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  2548. return
  2549. ;;
  2550. --label-add|--label-rm)
  2551. return
  2552. ;;
  2553. esac
  2554. case "$cur" in
  2555. -*)
  2556. COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) )
  2557. ;;
  2558. *)
  2559. __docker_complete_nodes
  2560. esac
  2561. }
  2562. _docker_pause() {
  2563. _docker_container_pause
  2564. }
  2565. _docker_port() {
  2566. _docker_container_port
  2567. }
  2568. _docker_ps() {
  2569. _docker_container_ls
  2570. }
  2571. _docker_pull() {
  2572. case "$cur" in
  2573. -*)
  2574. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  2575. ;;
  2576. *)
  2577. local counter=$(__docker_pos_first_nonflag)
  2578. if [ $cword -eq $counter ]; then
  2579. for arg in "${COMP_WORDS[@]}"; do
  2580. case "$arg" in
  2581. --all-tags|-a)
  2582. __docker_complete_image_repos
  2583. return
  2584. ;;
  2585. esac
  2586. done
  2587. __docker_complete_image_repos_and_tags
  2588. fi
  2589. ;;
  2590. esac
  2591. }
  2592. _docker_push() {
  2593. case "$cur" in
  2594. -*)
  2595. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  2596. ;;
  2597. *)
  2598. local counter=$(__docker_pos_first_nonflag)
  2599. if [ $cword -eq $counter ]; then
  2600. __docker_complete_image_repos_and_tags
  2601. fi
  2602. ;;
  2603. esac
  2604. }
  2605. _docker_rename() {
  2606. _docker_container_rename
  2607. }
  2608. _docker_restart() {
  2609. _docker_container_restart
  2610. }
  2611. _docker_rm() {
  2612. _docker_container_rm
  2613. }
  2614. _docker_rmi() {
  2615. case "$cur" in
  2616. -*)
  2617. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  2618. ;;
  2619. *)
  2620. __docker_complete_images
  2621. ;;
  2622. esac
  2623. }
  2624. _docker_run() {
  2625. _docker_container_run
  2626. }
  2627. _docker_save() {
  2628. case "$prev" in
  2629. --output|-o)
  2630. _filedir
  2631. return
  2632. ;;
  2633. esac
  2634. case "$cur" in
  2635. -*)
  2636. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  2637. ;;
  2638. *)
  2639. __docker_complete_images
  2640. ;;
  2641. esac
  2642. }
  2643. _docker_search() {
  2644. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2645. case "$key" in
  2646. is-automated)
  2647. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2648. return
  2649. ;;
  2650. is-official)
  2651. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2652. return
  2653. ;;
  2654. esac
  2655. case "$prev" in
  2656. --filter|-f)
  2657. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  2658. __docker_nospace
  2659. return
  2660. ;;
  2661. --limit)
  2662. return
  2663. ;;
  2664. esac
  2665. case "$cur" in
  2666. -*)
  2667. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  2668. ;;
  2669. esac
  2670. }
  2671. _docker_start() {
  2672. _docker_container_start
  2673. }
  2674. _docker_stats() {
  2675. _docker_container_stats
  2676. }
  2677. _docker_stop() {
  2678. case "$prev" in
  2679. --time|-t)
  2680. return
  2681. ;;
  2682. esac
  2683. case "$cur" in
  2684. -*)
  2685. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2686. ;;
  2687. *)
  2688. __docker_complete_containers_running
  2689. ;;
  2690. esac
  2691. }
  2692. _docker_tag() {
  2693. case "$cur" in
  2694. -*)
  2695. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2696. ;;
  2697. *)
  2698. local counter=$(__docker_pos_first_nonflag)
  2699. if [ $cword -eq $counter ]; then
  2700. __docker_complete_image_repos_and_tags
  2701. return
  2702. fi
  2703. (( counter++ ))
  2704. if [ $cword -eq $counter ]; then
  2705. __docker_complete_image_repos_and_tags
  2706. return
  2707. fi
  2708. ;;
  2709. esac
  2710. }
  2711. _docker_unpause() {
  2712. case "$cur" in
  2713. -*)
  2714. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2715. ;;
  2716. *)
  2717. local counter=$(__docker_pos_first_nonflag)
  2718. if [ $cword -eq $counter ]; then
  2719. __docker_complete_containers_unpauseable
  2720. fi
  2721. ;;
  2722. esac
  2723. }
  2724. _docker_update() {
  2725. local options_with_args="
  2726. --blkio-weight
  2727. --cpu-period
  2728. --cpu-quota
  2729. --cpuset-cpus
  2730. --cpuset-mems
  2731. --cpu-shares -c
  2732. --kernel-memory
  2733. --memory -m
  2734. --memory-reservation
  2735. --memory-swap
  2736. --restart
  2737. "
  2738. local boolean_options="
  2739. --help
  2740. "
  2741. local all_options="$options_with_args $boolean_options"
  2742. __docker_complete_restart && return
  2743. case "$prev" in
  2744. $(__docker_to_extglob "$options_with_args") )
  2745. return
  2746. ;;
  2747. esac
  2748. case "$cur" in
  2749. -*)
  2750. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2751. ;;
  2752. *)
  2753. __docker_complete_containers_all
  2754. ;;
  2755. esac
  2756. }
  2757. _docker_top() {
  2758. case "$cur" in
  2759. -*)
  2760. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2761. ;;
  2762. *)
  2763. local counter=$(__docker_pos_first_nonflag)
  2764. if [ $cword -eq $counter ]; then
  2765. __docker_complete_containers_running
  2766. fi
  2767. ;;
  2768. esac
  2769. }
  2770. _docker_version() {
  2771. case "$cur" in
  2772. -*)
  2773. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2774. ;;
  2775. esac
  2776. }
  2777. _docker_volume_create() {
  2778. case "$prev" in
  2779. --driver|-d)
  2780. __docker_complete_plugins --type Volume
  2781. return
  2782. ;;
  2783. --label|--opt|-o)
  2784. return
  2785. ;;
  2786. esac
  2787. case "$cur" in
  2788. -*)
  2789. COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) )
  2790. ;;
  2791. esac
  2792. }
  2793. _docker_volume_inspect() {
  2794. case "$prev" in
  2795. --format|-f)
  2796. return
  2797. ;;
  2798. esac
  2799. case "$cur" in
  2800. -*)
  2801. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2802. ;;
  2803. *)
  2804. __docker_complete_volumes
  2805. ;;
  2806. esac
  2807. }
  2808. _docker_volume_ls() {
  2809. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2810. case "$key" in
  2811. dangling)
  2812. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  2813. return
  2814. ;;
  2815. driver)
  2816. __docker_complete_plugins --cur "${cur##*=}" --type Volume
  2817. return
  2818. ;;
  2819. name)
  2820. __docker_complete_volumes --cur "${cur##*=}"
  2821. return
  2822. ;;
  2823. esac
  2824. case "$prev" in
  2825. --filter|-f)
  2826. COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) )
  2827. __docker_nospace
  2828. return
  2829. ;;
  2830. --format)
  2831. return
  2832. ;;
  2833. esac
  2834. case "$cur" in
  2835. -*)
  2836. COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
  2837. ;;
  2838. esac
  2839. }
  2840. _docker_volume_rm() {
  2841. case "$cur" in
  2842. -*)
  2843. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2844. ;;
  2845. *)
  2846. __docker_complete_volumes
  2847. ;;
  2848. esac
  2849. }
  2850. _docker_volume() {
  2851. local subcommands="
  2852. create
  2853. inspect
  2854. ls
  2855. rm
  2856. "
  2857. __docker_subcommands "$subcommands" && return
  2858. case "$cur" in
  2859. -*)
  2860. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2861. ;;
  2862. *)
  2863. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2864. ;;
  2865. esac
  2866. }
  2867. _docker_wait() {
  2868. case "$cur" in
  2869. -*)
  2870. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2871. ;;
  2872. *)
  2873. __docker_complete_containers_all
  2874. ;;
  2875. esac
  2876. }
  2877. _docker() {
  2878. local previous_extglob_setting=$(shopt -p extglob)
  2879. shopt -s extglob
  2880. local commands=(
  2881. attach
  2882. build
  2883. commit
  2884. container
  2885. cp
  2886. create
  2887. daemon
  2888. diff
  2889. events
  2890. exec
  2891. export
  2892. history
  2893. images
  2894. import
  2895. info
  2896. inspect
  2897. kill
  2898. load
  2899. login
  2900. logout
  2901. logs
  2902. network
  2903. node
  2904. pause
  2905. port
  2906. ps
  2907. pull
  2908. push
  2909. rename
  2910. restart
  2911. rm
  2912. rmi
  2913. run
  2914. save
  2915. search
  2916. service
  2917. start
  2918. stats
  2919. stop
  2920. swarm
  2921. tag
  2922. top
  2923. unpause
  2924. update
  2925. version
  2926. volume
  2927. wait
  2928. )
  2929. # These options are valid as global options for all client commands
  2930. # and valid as command options for `docker daemon`
  2931. local global_boolean_options="
  2932. --debug -D
  2933. --tls
  2934. --tlsverify
  2935. "
  2936. local global_options_with_args="
  2937. --config
  2938. --host -H
  2939. --log-level -l
  2940. --tlscacert
  2941. --tlscert
  2942. --tlskey
  2943. "
  2944. local host config
  2945. COMPREPLY=()
  2946. local cur prev words cword
  2947. _get_comp_words_by_ref -n : cur prev words cword
  2948. local command='docker' command_pos=0 subcommand_pos
  2949. local counter=1
  2950. while [ $counter -lt $cword ]; do
  2951. case "${words[$counter]}" in
  2952. # save host so that completion can use custom daemon
  2953. --host|-H)
  2954. (( counter++ ))
  2955. host="${words[$counter]}"
  2956. ;;
  2957. # save config so that completion can use custom configuration directories
  2958. --config)
  2959. (( counter++ ))
  2960. config="${words[$counter]}"
  2961. ;;
  2962. $(__docker_to_extglob "$global_options_with_args") )
  2963. (( counter++ ))
  2964. ;;
  2965. -*)
  2966. ;;
  2967. =)
  2968. (( counter++ ))
  2969. ;;
  2970. *)
  2971. command="${words[$counter]}"
  2972. command_pos=$counter
  2973. break
  2974. ;;
  2975. esac
  2976. (( counter++ ))
  2977. done
  2978. local binary="${words[0]}"
  2979. if [[ $binary == ?(*/)dockerd ]] ; then
  2980. # for the dockerd binary, we reuse completion of `docker daemon`.
  2981. # dockerd does not have subcommands and global options.
  2982. command=daemon
  2983. command_pos=0
  2984. fi
  2985. local completions_func=_docker_${command}
  2986. declare -F $completions_func >/dev/null && $completions_func
  2987. eval "$previous_extglob_setting"
  2988. return 0
  2989. }
  2990. eval "$__docker_previous_extglob_setting"
  2991. unset __docker_previous_extglob_setting
  2992. complete -F _docker docker dockerd