docker 65 KB

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