docker 53 KB

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