docker 67 KB

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