docker 58 KB

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