docker 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304
  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. # Finds the position of the first word that is neither option nor an option's argument.
  166. # If there are options that require arguments, you should pass a glob describing those
  167. # options, e.g. "--option1|-o|--option2"
  168. # Use this function to restrict completions to exact positions after the argument list.
  169. __docker_pos_first_nonflag() {
  170. local argument_flags=$1
  171. local counter=$((${subcommand_pos:-${command_pos}} + 1))
  172. while [ $counter -le $cword ]; do
  173. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  174. (( counter++ ))
  175. # eat "=" in case of --option=arg syntax
  176. [ "${words[$counter]}" = "=" ] && (( counter++ ))
  177. else
  178. case "${words[$counter]}" in
  179. -*)
  180. ;;
  181. *)
  182. break
  183. ;;
  184. esac
  185. fi
  186. # Bash splits words at "=", retaining "=" as a word, examples:
  187. # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
  188. while [ "${words[$counter + 1]}" = "=" ] ; do
  189. counter=$(( counter + 2))
  190. done
  191. (( counter++ ))
  192. done
  193. echo $counter
  194. }
  195. # If we are currently completing the value of a map option (key=value)
  196. # which matches the extglob given as an argument, returns key.
  197. # This function is needed for key-specific completions.
  198. __docker_map_key_of_current_option() {
  199. local glob="$1"
  200. local key glob_pos
  201. if [ "$cur" = "=" ] ; then # key= case
  202. key="$prev"
  203. glob_pos=$((cword - 2))
  204. elif [[ $cur == *=* ]] ; then # key=value case (OSX)
  205. key=${cur%=*}
  206. glob_pos=$((cword - 1))
  207. elif [ "$prev" = "=" ] ; then
  208. key=${words[$cword - 2]} # key=value case
  209. glob_pos=$((cword - 3))
  210. else
  211. return
  212. fi
  213. [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax
  214. [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key"
  215. }
  216. # Returns the value of the first option matching option_glob.
  217. # Valid values for option_glob are option names like '--log-level' and
  218. # globs like '--log-level|-l'
  219. # Only positions between the command and the current word are considered.
  220. __docker_value_of_option() {
  221. local option_extglob=$(__docker_to_extglob "$1")
  222. local counter=$((command_pos + 1))
  223. while [ $counter -lt $cword ]; do
  224. case ${words[$counter]} in
  225. $option_extglob )
  226. echo ${words[$counter + 1]}
  227. break
  228. ;;
  229. esac
  230. (( counter++ ))
  231. done
  232. }
  233. # Transforms a multiline list of strings into a single line string
  234. # with the words separated by "|".
  235. # This is used to prepare arguments to __docker_pos_first_nonflag().
  236. __docker_to_alternatives() {
  237. local parts=( $1 )
  238. local IFS='|'
  239. echo "${parts[*]}"
  240. }
  241. # Transforms a multiline list of options into an extglob pattern
  242. # suitable for use in case statements.
  243. __docker_to_extglob() {
  244. local extglob=$( __docker_to_alternatives "$1" )
  245. echo "@($extglob)"
  246. }
  247. # Subcommand processing.
  248. # Locates the first occurrence of any of the subcommands contained in the
  249. # first argument. In case of a match, calls the corresponding completion
  250. # function and returns 0.
  251. # If no match is found, 1 is returned. The calling function can then
  252. # continue processing its completion.
  253. #
  254. # TODO if the preceding command has options that accept arguments and an
  255. # argument is equal ot one of the subcommands, this is falsely detected as
  256. # a match.
  257. __docker_subcommands() {
  258. local subcommands="$1"
  259. local counter=$(($command_pos + 1))
  260. while [ $counter -lt $cword ]; do
  261. case "${words[$counter]}" in
  262. $(__docker_to_extglob "$subcommands") )
  263. subcommand_pos=$counter
  264. local subcommand=${words[$counter]}
  265. local completions_func=_docker_${command}_${subcommand}
  266. declare -F $completions_func >/dev/null && $completions_func
  267. return 0
  268. ;;
  269. esac
  270. (( counter++ ))
  271. done
  272. return 1
  273. }
  274. # suppress trailing whitespace
  275. __docker_nospace() {
  276. # compopt is not available in ancient bash versions
  277. type compopt &>/dev/null && compopt -o nospace
  278. }
  279. __docker_complete_resolved_hostname() {
  280. command -v host >/dev/null 2>&1 || return
  281. COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
  282. }
  283. __docker_complete_capabilities() {
  284. # The list of capabilities is defined in types.go, ALL was added manually.
  285. COMPREPLY=( $( compgen -W "
  286. ALL
  287. AUDIT_CONTROL
  288. AUDIT_WRITE
  289. AUDIT_READ
  290. BLOCK_SUSPEND
  291. CHOWN
  292. DAC_OVERRIDE
  293. DAC_READ_SEARCH
  294. FOWNER
  295. FSETID
  296. IPC_LOCK
  297. IPC_OWNER
  298. KILL
  299. LEASE
  300. LINUX_IMMUTABLE
  301. MAC_ADMIN
  302. MAC_OVERRIDE
  303. MKNOD
  304. NET_ADMIN
  305. NET_BIND_SERVICE
  306. NET_BROADCAST
  307. NET_RAW
  308. SETFCAP
  309. SETGID
  310. SETPCAP
  311. SETUID
  312. SYS_ADMIN
  313. SYS_BOOT
  314. SYS_CHROOT
  315. SYSLOG
  316. SYS_MODULE
  317. SYS_NICE
  318. SYS_PACCT
  319. SYS_PTRACE
  320. SYS_RAWIO
  321. SYS_RESOURCE
  322. SYS_TIME
  323. SYS_TTY_CONFIG
  324. WAKE_ALARM
  325. " -- "$cur" ) )
  326. }
  327. __docker_complete_detach-keys() {
  328. case "$prev" in
  329. --detach-keys)
  330. case "$cur" in
  331. *,)
  332. COMPREPLY=( $( compgen -W "${cur}ctrl-" -- "$cur" ) )
  333. ;;
  334. *)
  335. COMPREPLY=( $( compgen -W "ctrl-" -- "$cur" ) )
  336. ;;
  337. esac
  338. __docker_nospace
  339. return
  340. ;;
  341. esac
  342. return 1
  343. }
  344. __docker_complete_isolation() {
  345. COMPREPLY=( $( compgen -W "default hyperv process" -- "$cur" ) )
  346. }
  347. __docker_complete_log_drivers() {
  348. COMPREPLY=( $( compgen -W "
  349. awslogs
  350. etwlogs
  351. fluentd
  352. gcplogs
  353. gelf
  354. journald
  355. json-file
  356. none
  357. splunk
  358. syslog
  359. " -- "$cur" ) )
  360. }
  361. __docker_complete_log_options() {
  362. # see docs/reference/logging/index.md
  363. local awslogs_options="awslogs-region awslogs-group awslogs-stream"
  364. local fluentd_options="env fluentd-address fluentd-async-connect fluentd-buffer-limit fluentd-retry-wait fluentd-max-retries labels tag"
  365. local gcplogs_options="env gcp-log-cmd gcp-project labels"
  366. local gelf_options="env gelf-address gelf-compression-level gelf-compression-type labels tag"
  367. local journald_options="env labels tag"
  368. local json_file_options="env labels max-file max-size"
  369. local syslog_options="syslog-address syslog-format syslog-tls-ca-cert syslog-tls-cert syslog-tls-key syslog-tls-skip-verify syslog-facility tag"
  370. local splunk_options="env labels splunk-caname splunk-capath splunk-index splunk-insecureskipverify splunk-source splunk-sourcetype splunk-token splunk-url tag"
  371. local all_options="$fluentd_options $gcplogs_options $gelf_options $journald_options $json_file_options $syslog_options $splunk_options"
  372. case $(__docker_value_of_option --log-driver) in
  373. '')
  374. COMPREPLY=( $( compgen -W "$all_options" -S = -- "$cur" ) )
  375. ;;
  376. awslogs)
  377. COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) )
  378. ;;
  379. fluentd)
  380. COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) )
  381. ;;
  382. gcplogs)
  383. COMPREPLY=( $( compgen -W "$gcplogs_options" -S = -- "$cur" ) )
  384. ;;
  385. gelf)
  386. COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) )
  387. ;;
  388. journald)
  389. COMPREPLY=( $( compgen -W "$journald_options" -S = -- "$cur" ) )
  390. ;;
  391. json-file)
  392. COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) )
  393. ;;
  394. syslog)
  395. COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) )
  396. ;;
  397. splunk)
  398. COMPREPLY=( $( compgen -W "$splunk_options" -S = -- "$cur" ) )
  399. ;;
  400. *)
  401. return
  402. ;;
  403. esac
  404. __docker_nospace
  405. }
  406. __docker_complete_log_driver_options() {
  407. local key=$(__docker_map_key_of_current_option '--log-opt')
  408. case "$key" in
  409. fluentd-async-connect)
  410. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  411. return
  412. ;;
  413. gelf-address)
  414. COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur##*=}" ) )
  415. __docker_nospace
  416. return
  417. ;;
  418. gelf-compression-level)
  419. COMPREPLY=( $( compgen -W "1 2 3 4 5 6 7 8 9" -- "${cur##*=}" ) )
  420. return
  421. ;;
  422. gelf-compression-type)
  423. COMPREPLY=( $( compgen -W "gzip none zlib" -- "${cur##*=}" ) )
  424. return
  425. ;;
  426. syslog-address)
  427. COMPREPLY=( $( compgen -W "tcp:// tcp+tls:// udp:// unix://" -- "${cur##*=}" ) )
  428. __docker_nospace
  429. __ltrim_colon_completions "${cur}"
  430. return
  431. ;;
  432. syslog-facility)
  433. COMPREPLY=( $( compgen -W "
  434. auth
  435. authpriv
  436. cron
  437. daemon
  438. ftp
  439. kern
  440. local0
  441. local1
  442. local2
  443. local3
  444. local4
  445. local5
  446. local6
  447. local7
  448. lpr
  449. mail
  450. news
  451. syslog
  452. user
  453. uucp
  454. " -- "${cur##*=}" ) )
  455. return
  456. ;;
  457. syslog-format)
  458. COMPREPLY=( $( compgen -W "rfc3164 rfc5424 rfc5424micro" -- "${cur##*=}" ) )
  459. return
  460. ;;
  461. syslog-tls-@(ca-cert|cert|key))
  462. _filedir
  463. return
  464. ;;
  465. syslog-tls-skip-verify)
  466. COMPREPLY=( $( compgen -W "true" -- "${cur##*=}" ) )
  467. return
  468. ;;
  469. splunk-url)
  470. COMPREPLY=( $( compgen -W "http:// https://" -- "${cur##*=}" ) )
  471. __docker_nospace
  472. __ltrim_colon_completions "${cur}"
  473. return
  474. ;;
  475. splunk-insecureskipverify)
  476. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  477. return
  478. ;;
  479. esac
  480. return 1
  481. }
  482. __docker_complete_log_levels() {
  483. COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) )
  484. }
  485. __docker_complete_restart() {
  486. case "$prev" in
  487. --restart)
  488. case "$cur" in
  489. on-failure:*)
  490. ;;
  491. *)
  492. COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") )
  493. ;;
  494. esac
  495. return
  496. ;;
  497. esac
  498. return 1
  499. }
  500. # a selection of the available signals that is most likely of interest in the
  501. # context of docker containers.
  502. __docker_complete_signals() {
  503. local signals=(
  504. SIGCONT
  505. SIGHUP
  506. SIGINT
  507. SIGKILL
  508. SIGQUIT
  509. SIGSTOP
  510. SIGTERM
  511. SIGUSR1
  512. SIGUSR2
  513. )
  514. COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) )
  515. }
  516. __docker_complete_user_group() {
  517. if [[ $cur == *:* ]] ; then
  518. COMPREPLY=( $(compgen -g -- "${cur#*:}") )
  519. else
  520. COMPREPLY=( $(compgen -u -S : -- "$cur") )
  521. __docker_nospace
  522. fi
  523. }
  524. # global options that may appear after the docker command
  525. _docker_docker() {
  526. local boolean_options="
  527. $global_boolean_options
  528. --help
  529. --version -v
  530. "
  531. case "$prev" in
  532. --config)
  533. _filedir -d
  534. return
  535. ;;
  536. --log-level|-l)
  537. __docker_complete_log_levels
  538. return
  539. ;;
  540. $(__docker_to_extglob "$global_options_with_args") )
  541. return
  542. ;;
  543. esac
  544. case "$cur" in
  545. -*)
  546. COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) )
  547. ;;
  548. *)
  549. local counter=$( __docker_pos_first_nonflag "$(__docker_to_extglob "$global_options_with_args")" )
  550. if [ $cword -eq $counter ]; then
  551. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  552. fi
  553. ;;
  554. esac
  555. }
  556. _docker_attach() {
  557. __docker_complete_detach-keys && return
  558. case "$cur" in
  559. -*)
  560. COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) )
  561. ;;
  562. *)
  563. local counter=$(__docker_pos_first_nonflag '--detach-keys')
  564. if [ $cword -eq $counter ]; then
  565. __docker_complete_containers_running
  566. fi
  567. ;;
  568. esac
  569. }
  570. _docker_build() {
  571. local options_with_args="
  572. --build-arg
  573. --cgroup-parent
  574. --cpuset-cpus
  575. --cpuset-mems
  576. --cpu-shares
  577. --cpu-period
  578. --cpu-quota
  579. --file -f
  580. --isolation
  581. --label
  582. --memory -m
  583. --memory-swap
  584. --shm-size
  585. --tag -t
  586. --ulimit
  587. "
  588. local boolean_options="
  589. --disable-content-trust=false
  590. --force-rm
  591. --help
  592. --no-cache
  593. --pull
  594. --quiet -q
  595. --rm
  596. "
  597. local all_options="$options_with_args $boolean_options"
  598. case "$prev" in
  599. --build-arg)
  600. COMPREPLY=( $( compgen -e -- "$cur" ) )
  601. __docker_nospace
  602. return
  603. ;;
  604. --file|-f)
  605. _filedir
  606. return
  607. ;;
  608. --isolation)
  609. __docker_complete_isolation
  610. return
  611. ;;
  612. --tag|-t)
  613. __docker_complete_image_repos_and_tags
  614. return
  615. ;;
  616. $(__docker_to_extglob "$options_with_args") )
  617. return
  618. ;;
  619. esac
  620. case "$cur" in
  621. -*)
  622. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  623. ;;
  624. *)
  625. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  626. if [ $cword -eq $counter ]; then
  627. _filedir -d
  628. fi
  629. ;;
  630. esac
  631. }
  632. _docker_commit() {
  633. case "$prev" in
  634. --author|-a|--change|-c|--message|-m)
  635. return
  636. ;;
  637. esac
  638. case "$cur" in
  639. -*)
  640. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) )
  641. ;;
  642. *)
  643. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  644. if [ $cword -eq $counter ]; then
  645. __docker_complete_containers_all
  646. return
  647. fi
  648. (( counter++ ))
  649. if [ $cword -eq $counter ]; then
  650. __docker_complete_image_repos_and_tags
  651. return
  652. fi
  653. ;;
  654. esac
  655. }
  656. _docker_cp() {
  657. case "$cur" in
  658. -*)
  659. COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) )
  660. ;;
  661. *)
  662. local counter=$(__docker_pos_first_nonflag)
  663. if [ $cword -eq $counter ]; then
  664. case "$cur" in
  665. *:)
  666. return
  667. ;;
  668. *)
  669. # combined container and filename completion
  670. _filedir
  671. local files=( ${COMPREPLY[@]} )
  672. __docker_complete_containers_all
  673. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  674. local containers=( ${COMPREPLY[@]} )
  675. COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) )
  676. if [[ "$COMPREPLY" == *: ]]; then
  677. __docker_nospace
  678. fi
  679. return
  680. ;;
  681. esac
  682. fi
  683. (( counter++ ))
  684. if [ $cword -eq $counter ]; then
  685. if [ -e "$prev" ]; then
  686. __docker_complete_containers_all
  687. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  688. __docker_nospace
  689. else
  690. _filedir
  691. fi
  692. return
  693. fi
  694. ;;
  695. esac
  696. }
  697. _docker_create() {
  698. _docker_run
  699. }
  700. _docker_daemon() {
  701. local boolean_options="
  702. $global_boolean_options
  703. --disable-legacy-registry
  704. --help
  705. --icc=false
  706. --ip-forward=false
  707. --ip-masq=false
  708. --iptables=false
  709. --ipv6
  710. --raw-logs
  711. --selinux-enabled
  712. --userland-proxy=false
  713. "
  714. local options_with_args="
  715. $global_options_with_args
  716. --api-cors-header
  717. --authorization-plugin
  718. --bip
  719. --bridge -b
  720. --cgroup-parent
  721. --cluster-advertise
  722. --cluster-store
  723. --cluster-store-opt
  724. --containerd
  725. --default-gateway
  726. --default-gateway-v6
  727. --default-ulimit
  728. --dns
  729. --dns-search
  730. --dns-opt
  731. --exec-opt
  732. --exec-root
  733. --fixed-cidr
  734. --fixed-cidr-v6
  735. --graph -g
  736. --group -G
  737. --insecure-registry
  738. --ip
  739. --label
  740. --log-driver
  741. --log-opt
  742. --max-concurrent-downloads
  743. --max-concurrent-uploads
  744. --mtu
  745. --pidfile -p
  746. --registry-mirror
  747. --storage-driver -s
  748. --storage-opt
  749. --userns-remap
  750. "
  751. __docker_complete_log_driver_options && return
  752. key=$(__docker_map_key_of_current_option '--cluster-store-opt')
  753. case "$key" in
  754. kv.*file)
  755. cur=${cur##*=}
  756. _filedir
  757. return
  758. ;;
  759. esac
  760. local key=$(__docker_map_key_of_current_option '--storage-opt')
  761. case "$key" in
  762. dm.@(blkdiscard|override_udev_sync_check|use_deferred_@(removal|deletion)))
  763. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  764. return
  765. ;;
  766. dm.fs)
  767. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) )
  768. return
  769. ;;
  770. dm.thinpooldev)
  771. cur=${cur##*=}
  772. _filedir
  773. return
  774. ;;
  775. esac
  776. case "$prev" in
  777. --authorization-plugin)
  778. __docker_complete_plugins Authorization
  779. return
  780. ;;
  781. --cluster-store)
  782. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  783. __docker_nospace
  784. return
  785. ;;
  786. --cluster-store-opt)
  787. COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) )
  788. __docker_nospace
  789. return
  790. ;;
  791. --exec-root|--graph|-g)
  792. _filedir -d
  793. return
  794. ;;
  795. --log-driver)
  796. __docker_complete_log_drivers
  797. return
  798. ;;
  799. --containerd|--pidfile|-p|--tlscacert|--tlscert|--tlskey)
  800. _filedir
  801. return
  802. ;;
  803. --storage-driver|-s)
  804. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  805. return
  806. ;;
  807. --storage-opt)
  808. local devicemapper_options="
  809. dm.basesize
  810. dm.blkdiscard
  811. dm.blocksize
  812. dm.fs
  813. dm.loopdatasize
  814. dm.loopmetadatasize
  815. dm.min_free_space
  816. dm.mkfsarg
  817. dm.mountopt
  818. dm.override_udev_sync_check
  819. dm.thinpooldev
  820. dm.use_deferred_deletion
  821. dm.use_deferred_removal
  822. "
  823. local zfs_options="zfs.fsname"
  824. case $(__docker_value_of_option '--storage-driver|-s') in
  825. '')
  826. COMPREPLY=( $( compgen -W "$devicemapper_options $zfs_options" -S = -- "$cur" ) )
  827. ;;
  828. devicemapper)
  829. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  830. ;;
  831. zfs)
  832. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  833. ;;
  834. *)
  835. return
  836. ;;
  837. esac
  838. __docker_nospace
  839. return
  840. ;;
  841. --log-level|-l)
  842. __docker_complete_log_levels
  843. return
  844. ;;
  845. --log-opt)
  846. __docker_complete_log_options
  847. return
  848. ;;
  849. --userns-remap)
  850. __docker_complete_user_group
  851. return
  852. ;;
  853. $(__docker_to_extglob "$options_with_args") )
  854. return
  855. ;;
  856. esac
  857. case "$cur" in
  858. -*)
  859. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  860. ;;
  861. esac
  862. }
  863. _docker_diff() {
  864. case "$cur" in
  865. -*)
  866. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  867. ;;
  868. *)
  869. local counter=$(__docker_pos_first_nonflag)
  870. if [ $cword -eq $counter ]; then
  871. __docker_complete_containers_all
  872. fi
  873. ;;
  874. esac
  875. }
  876. _docker_events() {
  877. local key=$(__docker_map_key_of_current_option '-f|--filter')
  878. case "$key" in
  879. container)
  880. cur="${cur##*=}"
  881. __docker_complete_containers_all
  882. return
  883. ;;
  884. daemon)
  885. local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
  886. COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
  887. return
  888. ;;
  889. event)
  890. COMPREPLY=( $( compgen -W "
  891. attach
  892. commit
  893. connect
  894. copy
  895. create
  896. delete
  897. destroy
  898. die
  899. disconnect
  900. exec_create
  901. exec_start
  902. export
  903. import
  904. kill
  905. mount
  906. oom
  907. pause
  908. pull
  909. push
  910. reload
  911. rename
  912. resize
  913. restart
  914. start
  915. stop
  916. tag
  917. top
  918. unmount
  919. unpause
  920. untag
  921. update
  922. " -- "${cur##*=}" ) )
  923. return
  924. ;;
  925. image)
  926. cur="${cur##*=}"
  927. __docker_complete_images
  928. return
  929. ;;
  930. network)
  931. cur="${cur##*=}"
  932. __docker_complete_networks
  933. return
  934. ;;
  935. type)
  936. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  937. return
  938. ;;
  939. volume)
  940. cur="${cur##*=}"
  941. __docker_complete_volumes
  942. return
  943. ;;
  944. esac
  945. case "$prev" in
  946. --filter|-f)
  947. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  948. __docker_nospace
  949. return
  950. ;;
  951. --since|--until)
  952. return
  953. ;;
  954. esac
  955. case "$cur" in
  956. -*)
  957. COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) )
  958. ;;
  959. esac
  960. }
  961. _docker_exec() {
  962. __docker_complete_detach-keys && return
  963. case "$prev" in
  964. --user|-u)
  965. __docker_complete_user_group
  966. return
  967. ;;
  968. esac
  969. case "$cur" in
  970. -*)
  971. COMPREPLY=( $( compgen -W "--detach -d --detach-keys --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  972. ;;
  973. *)
  974. __docker_complete_containers_running
  975. ;;
  976. esac
  977. }
  978. _docker_export() {
  979. case "$cur" in
  980. -*)
  981. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  982. ;;
  983. *)
  984. local counter=$(__docker_pos_first_nonflag)
  985. if [ $cword -eq $counter ]; then
  986. __docker_complete_containers_all
  987. fi
  988. ;;
  989. esac
  990. }
  991. _docker_help() {
  992. local counter=$(__docker_pos_first_nonflag)
  993. if [ $cword -eq $counter ]; then
  994. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  995. fi
  996. }
  997. _docker_history() {
  998. case "$cur" in
  999. -*)
  1000. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  1001. ;;
  1002. *)
  1003. local counter=$(__docker_pos_first_nonflag)
  1004. if [ $cword -eq $counter ]; then
  1005. __docker_complete_images
  1006. fi
  1007. ;;
  1008. esac
  1009. }
  1010. _docker_images() {
  1011. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1012. case "$key" in
  1013. dangling)
  1014. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1015. return
  1016. ;;
  1017. label)
  1018. return
  1019. ;;
  1020. esac
  1021. case "$prev" in
  1022. --filter|-f)
  1023. COMPREPLY=( $( compgen -S = -W "dangling label" -- "$cur" ) )
  1024. __docker_nospace
  1025. return
  1026. ;;
  1027. --format)
  1028. return
  1029. ;;
  1030. esac
  1031. case "$cur" in
  1032. -*)
  1033. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1034. ;;
  1035. =)
  1036. return
  1037. ;;
  1038. *)
  1039. __docker_complete_image_repos
  1040. ;;
  1041. esac
  1042. }
  1043. _docker_import() {
  1044. case "$prev" in
  1045. --change|-c|--message|-m)
  1046. return
  1047. ;;
  1048. esac
  1049. case "$cur" in
  1050. -*)
  1051. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1052. ;;
  1053. *)
  1054. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1055. if [ $cword -eq $counter ]; then
  1056. return
  1057. fi
  1058. (( counter++ ))
  1059. if [ $cword -eq $counter ]; then
  1060. __docker_complete_image_repos_and_tags
  1061. return
  1062. fi
  1063. ;;
  1064. esac
  1065. }
  1066. _docker_info() {
  1067. case "$cur" in
  1068. -*)
  1069. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1070. ;;
  1071. esac
  1072. }
  1073. _docker_inspect() {
  1074. case "$prev" in
  1075. --format|-f)
  1076. return
  1077. ;;
  1078. --type)
  1079. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  1080. return
  1081. ;;
  1082. esac
  1083. case "$cur" in
  1084. -*)
  1085. COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) )
  1086. ;;
  1087. *)
  1088. case $(__docker_value_of_option --type) in
  1089. '')
  1090. __docker_complete_containers_and_images
  1091. ;;
  1092. container)
  1093. __docker_complete_containers_all
  1094. ;;
  1095. image)
  1096. __docker_complete_images
  1097. ;;
  1098. esac
  1099. esac
  1100. }
  1101. _docker_kill() {
  1102. case "$prev" in
  1103. --signal|-s)
  1104. __docker_complete_signals
  1105. return
  1106. ;;
  1107. esac
  1108. case "$cur" in
  1109. -*)
  1110. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  1111. ;;
  1112. *)
  1113. __docker_complete_containers_running
  1114. ;;
  1115. esac
  1116. }
  1117. _docker_load() {
  1118. case "$prev" in
  1119. --input|-i)
  1120. _filedir
  1121. return
  1122. ;;
  1123. esac
  1124. case "$cur" in
  1125. -*)
  1126. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1127. ;;
  1128. esac
  1129. }
  1130. _docker_login() {
  1131. case "$prev" in
  1132. --password|-p|--username|-u)
  1133. return
  1134. ;;
  1135. esac
  1136. case "$cur" in
  1137. -*)
  1138. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  1139. ;;
  1140. esac
  1141. }
  1142. _docker_logout() {
  1143. case "$cur" in
  1144. -*)
  1145. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1146. ;;
  1147. esac
  1148. }
  1149. _docker_logs() {
  1150. case "$prev" in
  1151. --since|--tail)
  1152. return
  1153. ;;
  1154. esac
  1155. case "$cur" in
  1156. -*)
  1157. COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  1158. ;;
  1159. *)
  1160. local counter=$(__docker_pos_first_nonflag '--tail')
  1161. if [ $cword -eq $counter ]; then
  1162. __docker_complete_containers_all
  1163. fi
  1164. ;;
  1165. esac
  1166. }
  1167. _docker_network_connect() {
  1168. local options_with_args="
  1169. --alias
  1170. --ip
  1171. --ip6
  1172. --link
  1173. "
  1174. local boolean_options="
  1175. --help
  1176. "
  1177. case "$prev" in
  1178. --link)
  1179. case "$cur" in
  1180. *:*)
  1181. ;;
  1182. *)
  1183. __docker_complete_containers_running
  1184. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1185. __docker_nospace
  1186. ;;
  1187. esac
  1188. return
  1189. ;;
  1190. $(__docker_to_extglob "$options_with_args") )
  1191. return
  1192. ;;
  1193. esac
  1194. case "$cur" in
  1195. -*)
  1196. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1197. ;;
  1198. *)
  1199. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1200. if [ $cword -eq $counter ]; then
  1201. __docker_complete_networks
  1202. elif [ $cword -eq $(($counter + 1)) ]; then
  1203. __docker_complete_containers_all
  1204. fi
  1205. ;;
  1206. esac
  1207. }
  1208. _docker_network_create() {
  1209. case "$prev" in
  1210. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  1211. return
  1212. ;;
  1213. --ipam-driver)
  1214. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  1215. return
  1216. ;;
  1217. --driver|-d)
  1218. local plugins=" $(__docker_plugins Network) "
  1219. # remove drivers that allow one instance only
  1220. plugins=${plugins/ host / }
  1221. plugins=${plugins/ null / }
  1222. COMPREPLY=( $(compgen -W "$plugins" -- "$cur") )
  1223. return
  1224. ;;
  1225. --label)
  1226. return
  1227. ;;
  1228. esac
  1229. case "$cur" in
  1230. -*)
  1231. COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  1232. ;;
  1233. esac
  1234. }
  1235. _docker_network_disconnect() {
  1236. case "$cur" in
  1237. -*)
  1238. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1239. ;;
  1240. *)
  1241. local counter=$(__docker_pos_first_nonflag)
  1242. if [ $cword -eq $counter ]; then
  1243. __docker_complete_networks
  1244. elif [ $cword -eq $(($counter + 1)) ]; then
  1245. __docker_complete_containers_in_network "$prev"
  1246. fi
  1247. ;;
  1248. esac
  1249. }
  1250. _docker_network_inspect() {
  1251. case "$prev" in
  1252. --format|-f)
  1253. return
  1254. ;;
  1255. esac
  1256. case "$cur" in
  1257. -*)
  1258. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1259. ;;
  1260. *)
  1261. __docker_complete_networks
  1262. esac
  1263. }
  1264. _docker_network_ls() {
  1265. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1266. case "$key" in
  1267. driver)
  1268. local plugins=" $(__docker_plugins Network) "
  1269. COMPREPLY=( $(compgen -W "$plugins" -- "${cur##*=}") )
  1270. return
  1271. ;;
  1272. id)
  1273. cur="${cur##*=}"
  1274. __docker_complete_network_ids
  1275. return
  1276. ;;
  1277. name)
  1278. cur="${cur##*=}"
  1279. __docker_complete_network_names
  1280. return
  1281. ;;
  1282. type)
  1283. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  1284. return
  1285. ;;
  1286. esac
  1287. case "$prev" in
  1288. --filter|-f)
  1289. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  1290. __docker_nospace
  1291. return
  1292. ;;
  1293. esac
  1294. case "$cur" in
  1295. -*)
  1296. COMPREPLY=( $( compgen -W "--filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
  1297. ;;
  1298. esac
  1299. }
  1300. _docker_network_rm() {
  1301. case "$cur" in
  1302. -*)
  1303. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1304. ;;
  1305. *)
  1306. __docker_complete_networks type=custom
  1307. esac
  1308. }
  1309. _docker_network() {
  1310. local subcommands="
  1311. connect
  1312. create
  1313. disconnect
  1314. inspect
  1315. ls
  1316. rm
  1317. "
  1318. __docker_subcommands "$subcommands" && return
  1319. case "$cur" in
  1320. -*)
  1321. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1322. ;;
  1323. *)
  1324. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1325. ;;
  1326. esac
  1327. }
  1328. _docker_pause() {
  1329. case "$cur" in
  1330. -*)
  1331. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1332. ;;
  1333. *)
  1334. local counter=$(__docker_pos_first_nonflag)
  1335. if [ $cword -eq $counter ]; then
  1336. __docker_complete_containers_pauseable
  1337. fi
  1338. ;;
  1339. esac
  1340. }
  1341. _docker_port() {
  1342. case "$cur" in
  1343. -*)
  1344. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1345. ;;
  1346. *)
  1347. local counter=$(__docker_pos_first_nonflag)
  1348. if [ $cword -eq $counter ]; then
  1349. __docker_complete_containers_all
  1350. fi
  1351. ;;
  1352. esac
  1353. }
  1354. _docker_ps() {
  1355. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1356. case "$key" in
  1357. ancestor)
  1358. cur="${cur##*=}"
  1359. __docker_complete_images
  1360. return
  1361. ;;
  1362. id)
  1363. cur="${cur##*=}"
  1364. __docker_complete_container_ids
  1365. return
  1366. ;;
  1367. name)
  1368. cur="${cur##*=}"
  1369. __docker_complete_container_names
  1370. return
  1371. ;;
  1372. status)
  1373. COMPREPLY=( $( compgen -W "created dead exited paused restarting running" -- "${cur##*=}" ) )
  1374. return
  1375. ;;
  1376. volume)
  1377. cur="${cur##*=}"
  1378. __docker_complete_volumes
  1379. return
  1380. ;;
  1381. esac
  1382. case "$prev" in
  1383. --before|--since)
  1384. __docker_complete_containers_all
  1385. ;;
  1386. --filter|-f)
  1387. COMPREPLY=( $( compgen -S = -W "ancestor exited id label name status volume" -- "$cur" ) )
  1388. __docker_nospace
  1389. return
  1390. ;;
  1391. --format|-n)
  1392. return
  1393. ;;
  1394. esac
  1395. case "$cur" in
  1396. -*)
  1397. COMPREPLY=( $( compgen -W "--all -a --before --filter -f --format --help --latest -l -n --no-trunc --quiet -q --size -s --since" -- "$cur" ) )
  1398. ;;
  1399. esac
  1400. }
  1401. _docker_pull() {
  1402. case "$cur" in
  1403. -*)
  1404. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  1405. ;;
  1406. *)
  1407. local counter=$(__docker_pos_first_nonflag)
  1408. if [ $cword -eq $counter ]; then
  1409. for arg in "${COMP_WORDS[@]}"; do
  1410. case "$arg" in
  1411. --all-tags|-a)
  1412. __docker_complete_image_repos
  1413. return
  1414. ;;
  1415. esac
  1416. done
  1417. __docker_complete_image_repos_and_tags
  1418. fi
  1419. ;;
  1420. esac
  1421. }
  1422. _docker_push() {
  1423. case "$cur" in
  1424. -*)
  1425. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  1426. ;;
  1427. *)
  1428. local counter=$(__docker_pos_first_nonflag)
  1429. if [ $cword -eq $counter ]; then
  1430. __docker_complete_image_repos_and_tags
  1431. fi
  1432. ;;
  1433. esac
  1434. }
  1435. _docker_rename() {
  1436. case "$cur" in
  1437. -*)
  1438. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1439. ;;
  1440. *)
  1441. local counter=$(__docker_pos_first_nonflag)
  1442. if [ $cword -eq $counter ]; then
  1443. __docker_complete_containers_all
  1444. fi
  1445. ;;
  1446. esac
  1447. }
  1448. _docker_restart() {
  1449. case "$prev" in
  1450. --time|-t)
  1451. return
  1452. ;;
  1453. esac
  1454. case "$cur" in
  1455. -*)
  1456. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1457. ;;
  1458. *)
  1459. __docker_complete_containers_all
  1460. ;;
  1461. esac
  1462. }
  1463. _docker_rm() {
  1464. case "$cur" in
  1465. -*)
  1466. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  1467. ;;
  1468. *)
  1469. for arg in "${COMP_WORDS[@]}"; do
  1470. case "$arg" in
  1471. --force|-f)
  1472. __docker_complete_containers_all
  1473. return
  1474. ;;
  1475. esac
  1476. done
  1477. __docker_complete_containers_stopped
  1478. ;;
  1479. esac
  1480. }
  1481. _docker_rmi() {
  1482. case "$cur" in
  1483. -*)
  1484. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  1485. ;;
  1486. *)
  1487. __docker_complete_images
  1488. ;;
  1489. esac
  1490. }
  1491. _docker_run() {
  1492. local options_with_args="
  1493. --add-host
  1494. --attach -a
  1495. --blkio-weight
  1496. --blkio-weight-device
  1497. --cap-add
  1498. --cap-drop
  1499. --cgroup-parent
  1500. --cidfile
  1501. --cpu-period
  1502. --cpu-quota
  1503. --cpuset-cpus
  1504. --cpuset-mems
  1505. --cpu-shares
  1506. --device
  1507. --device-read-bps
  1508. --device-read-iops
  1509. --device-write-bps
  1510. --device-write-iops
  1511. --dns
  1512. --dns-opt
  1513. --dns-search
  1514. --entrypoint
  1515. --env -e
  1516. --env-file
  1517. --expose
  1518. --group-add
  1519. --hostname -h
  1520. --ip
  1521. --ip6
  1522. --ipc
  1523. --isolation
  1524. --kernel-memory
  1525. --label-file
  1526. --label -l
  1527. --link
  1528. --log-driver
  1529. --log-opt
  1530. --mac-address
  1531. --memory -m
  1532. --memory-swap
  1533. --memory-swappiness
  1534. --memory-reservation
  1535. --name
  1536. --net
  1537. --net-alias
  1538. --oom-score-adj
  1539. --pid
  1540. --pids-limit
  1541. --publish -p
  1542. --restart
  1543. --security-opt
  1544. --shm-size
  1545. --stop-signal
  1546. --tmpfs
  1547. --sysctl
  1548. --ulimit
  1549. --user -u
  1550. --userns
  1551. --uts
  1552. --volume-driver
  1553. --volumes-from
  1554. --volume -v
  1555. --workdir -w
  1556. "
  1557. local boolean_options="
  1558. --disable-content-trust=false
  1559. --help
  1560. --interactive -i
  1561. --oom-kill-disable
  1562. --privileged
  1563. --publish-all -P
  1564. --read-only
  1565. --tty -t
  1566. "
  1567. if [ "$command" = "run" ] ; then
  1568. options_with_args="$options_with_args
  1569. --detach-keys
  1570. "
  1571. boolean_options="$boolean_options
  1572. --detach -d
  1573. --rm
  1574. --sig-proxy=false
  1575. "
  1576. __docker_complete_detach-keys && return
  1577. fi
  1578. local all_options="$options_with_args $boolean_options"
  1579. __docker_complete_log_driver_options && return
  1580. __docker_complete_restart && return
  1581. local key=$(__docker_map_key_of_current_option '--security-opt')
  1582. case "$key" in
  1583. label)
  1584. [[ $cur == *: ]] && return
  1585. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  1586. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  1587. __docker_nospace
  1588. fi
  1589. return
  1590. ;;
  1591. seccomp)
  1592. local cur=${cur##*=}
  1593. _filedir
  1594. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  1595. return
  1596. ;;
  1597. esac
  1598. case "$prev" in
  1599. --add-host)
  1600. case "$cur" in
  1601. *:)
  1602. __docker_complete_resolved_hostname
  1603. return
  1604. ;;
  1605. esac
  1606. ;;
  1607. --attach|-a)
  1608. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  1609. return
  1610. ;;
  1611. --cap-add|--cap-drop)
  1612. __docker_complete_capabilities
  1613. return
  1614. ;;
  1615. --cidfile|--env-file|--label-file)
  1616. _filedir
  1617. return
  1618. ;;
  1619. --device|--tmpfs|--volume|-v)
  1620. case "$cur" in
  1621. *:*)
  1622. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  1623. ;;
  1624. '')
  1625. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  1626. __docker_nospace
  1627. ;;
  1628. /*)
  1629. _filedir
  1630. __docker_nospace
  1631. ;;
  1632. esac
  1633. return
  1634. ;;
  1635. --env|-e)
  1636. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1637. __docker_nospace
  1638. return
  1639. ;;
  1640. --ipc)
  1641. case "$cur" in
  1642. *:*)
  1643. cur="${cur#*:}"
  1644. __docker_complete_containers_running
  1645. ;;
  1646. *)
  1647. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1648. if [ "$COMPREPLY" = "container:" ]; then
  1649. __docker_nospace
  1650. fi
  1651. ;;
  1652. esac
  1653. return
  1654. ;;
  1655. --isolation)
  1656. __docker_complete_isolation
  1657. return
  1658. ;;
  1659. --link)
  1660. case "$cur" in
  1661. *:*)
  1662. ;;
  1663. *)
  1664. __docker_complete_containers_running
  1665. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1666. __docker_nospace
  1667. ;;
  1668. esac
  1669. return
  1670. ;;
  1671. --log-driver)
  1672. __docker_complete_log_drivers
  1673. return
  1674. ;;
  1675. --log-opt)
  1676. __docker_complete_log_options
  1677. return
  1678. ;;
  1679. --net)
  1680. case "$cur" in
  1681. container:*)
  1682. local cur=${cur#*:}
  1683. __docker_complete_containers_all
  1684. ;;
  1685. *)
  1686. COMPREPLY=( $( compgen -W "$(__docker_plugins Network) $(__docker_networks) container:" -- "$cur") )
  1687. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1688. __docker_nospace
  1689. fi
  1690. ;;
  1691. esac
  1692. return
  1693. ;;
  1694. --pid)
  1695. case "$cur" in
  1696. *:*)
  1697. cur="${cur#*:}"
  1698. __docker_complete_containers_running
  1699. ;;
  1700. *)
  1701. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1702. if [ "$COMPREPLY" = "container:" ]; then
  1703. __docker_nospace
  1704. fi
  1705. ;;
  1706. esac
  1707. return
  1708. ;;
  1709. --security-opt)
  1710. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  1711. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  1712. __docker_nospace
  1713. fi
  1714. return
  1715. ;;
  1716. --user|-u)
  1717. __docker_complete_user_group
  1718. return
  1719. ;;
  1720. --userns)
  1721. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  1722. return
  1723. ;;
  1724. --volume-driver)
  1725. __docker_complete_plugins Volume
  1726. return
  1727. ;;
  1728. --volumes-from)
  1729. __docker_complete_containers_all
  1730. return
  1731. ;;
  1732. $(__docker_to_extglob "$options_with_args") )
  1733. return
  1734. ;;
  1735. esac
  1736. case "$cur" in
  1737. -*)
  1738. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1739. ;;
  1740. *)
  1741. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1742. if [ $cword -eq $counter ]; then
  1743. __docker_complete_images
  1744. fi
  1745. ;;
  1746. esac
  1747. }
  1748. _docker_save() {
  1749. case "$prev" in
  1750. --output|-o)
  1751. _filedir
  1752. return
  1753. ;;
  1754. esac
  1755. case "$cur" in
  1756. -*)
  1757. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  1758. ;;
  1759. *)
  1760. __docker_complete_images
  1761. ;;
  1762. esac
  1763. }
  1764. _docker_search() {
  1765. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1766. case "$key" in
  1767. is-automated)
  1768. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1769. return
  1770. ;;
  1771. is-official)
  1772. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1773. return
  1774. ;;
  1775. esac
  1776. case "$prev" in
  1777. --filter|-f)
  1778. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  1779. __docker_nospace
  1780. return
  1781. ;;
  1782. esac
  1783. case "$cur" in
  1784. -*)
  1785. COMPREPLY=( $( compgen -W "--filter --help --no-trunc" -- "$cur" ) )
  1786. ;;
  1787. esac
  1788. }
  1789. _docker_start() {
  1790. __docker_complete_detach-keys && return
  1791. case "$cur" in
  1792. -*)
  1793. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  1794. ;;
  1795. *)
  1796. __docker_complete_containers_stopped
  1797. ;;
  1798. esac
  1799. }
  1800. _docker_stats() {
  1801. case "$cur" in
  1802. -*)
  1803. COMPREPLY=( $( compgen -W "--all -a --help --no-stream" -- "$cur" ) )
  1804. ;;
  1805. *)
  1806. __docker_complete_containers_running
  1807. ;;
  1808. esac
  1809. }
  1810. _docker_stop() {
  1811. case "$prev" in
  1812. --time|-t)
  1813. return
  1814. ;;
  1815. esac
  1816. case "$cur" in
  1817. -*)
  1818. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1819. ;;
  1820. *)
  1821. __docker_complete_containers_running
  1822. ;;
  1823. esac
  1824. }
  1825. _docker_tag() {
  1826. case "$cur" in
  1827. -*)
  1828. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1829. ;;
  1830. *)
  1831. local counter=$(__docker_pos_first_nonflag)
  1832. if [ $cword -eq $counter ]; then
  1833. __docker_complete_image_repos_and_tags
  1834. return
  1835. fi
  1836. (( counter++ ))
  1837. if [ $cword -eq $counter ]; then
  1838. __docker_complete_image_repos_and_tags
  1839. return
  1840. fi
  1841. ;;
  1842. esac
  1843. }
  1844. _docker_unpause() {
  1845. case "$cur" in
  1846. -*)
  1847. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1848. ;;
  1849. *)
  1850. local counter=$(__docker_pos_first_nonflag)
  1851. if [ $cword -eq $counter ]; then
  1852. __docker_complete_containers_unpauseable
  1853. fi
  1854. ;;
  1855. esac
  1856. }
  1857. _docker_update() {
  1858. local options_with_args="
  1859. --blkio-weight
  1860. --cpu-period
  1861. --cpu-quota
  1862. --cpuset-cpus
  1863. --cpuset-mems
  1864. --cpu-shares
  1865. --kernel-memory
  1866. --memory -m
  1867. --memory-reservation
  1868. --memory-swap
  1869. --restart
  1870. "
  1871. local boolean_options="
  1872. --help
  1873. "
  1874. local all_options="$options_with_args $boolean_options"
  1875. __docker_complete_restart && return
  1876. case "$prev" in
  1877. $(__docker_to_extglob "$options_with_args") )
  1878. return
  1879. ;;
  1880. esac
  1881. case "$cur" in
  1882. -*)
  1883. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1884. ;;
  1885. *)
  1886. __docker_complete_containers_all
  1887. ;;
  1888. esac
  1889. }
  1890. _docker_top() {
  1891. case "$cur" in
  1892. -*)
  1893. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1894. ;;
  1895. *)
  1896. local counter=$(__docker_pos_first_nonflag)
  1897. if [ $cword -eq $counter ]; then
  1898. __docker_complete_containers_running
  1899. fi
  1900. ;;
  1901. esac
  1902. }
  1903. _docker_version() {
  1904. case "$cur" in
  1905. -*)
  1906. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1907. ;;
  1908. esac
  1909. }
  1910. _docker_volume_create() {
  1911. case "$prev" in
  1912. --driver|-d)
  1913. __docker_complete_plugins Volume
  1914. return
  1915. ;;
  1916. --label|--name|--opt|-o)
  1917. return
  1918. ;;
  1919. esac
  1920. case "$cur" in
  1921. -*)
  1922. COMPREPLY=( $( compgen -W "--driver -d --help --label --name --opt -o" -- "$cur" ) )
  1923. ;;
  1924. esac
  1925. }
  1926. _docker_volume_inspect() {
  1927. case "$prev" in
  1928. --format|-f)
  1929. return
  1930. ;;
  1931. esac
  1932. case "$cur" in
  1933. -*)
  1934. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1935. ;;
  1936. *)
  1937. __docker_complete_volumes
  1938. ;;
  1939. esac
  1940. }
  1941. _docker_volume_ls() {
  1942. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1943. case "$key" in
  1944. dangling)
  1945. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  1946. return
  1947. ;;
  1948. driver)
  1949. cur=${cur##*=}
  1950. __docker_complete_plugins Volume
  1951. return
  1952. ;;
  1953. name)
  1954. cur=${cur##*=}
  1955. __docker_complete_volumes
  1956. return
  1957. ;;
  1958. esac
  1959. case "$prev" in
  1960. --filter|-f)
  1961. COMPREPLY=( $( compgen -S = -W "dangling driver name" -- "$cur" ) )
  1962. __docker_nospace
  1963. return
  1964. ;;
  1965. esac
  1966. case "$cur" in
  1967. -*)
  1968. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1969. ;;
  1970. esac
  1971. }
  1972. _docker_volume_rm() {
  1973. case "$cur" in
  1974. -*)
  1975. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1976. ;;
  1977. *)
  1978. __docker_complete_volumes
  1979. ;;
  1980. esac
  1981. }
  1982. _docker_volume() {
  1983. local subcommands="
  1984. create
  1985. inspect
  1986. ls
  1987. rm
  1988. "
  1989. __docker_subcommands "$subcommands" && return
  1990. case "$cur" in
  1991. -*)
  1992. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1993. ;;
  1994. *)
  1995. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1996. ;;
  1997. esac
  1998. }
  1999. _docker_wait() {
  2000. case "$cur" in
  2001. -*)
  2002. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2003. ;;
  2004. *)
  2005. __docker_complete_containers_all
  2006. ;;
  2007. esac
  2008. }
  2009. _docker() {
  2010. local previous_extglob_setting=$(shopt -p extglob)
  2011. shopt -s extglob
  2012. local commands=(
  2013. attach
  2014. build
  2015. commit
  2016. cp
  2017. create
  2018. daemon
  2019. diff
  2020. events
  2021. exec
  2022. export
  2023. history
  2024. images
  2025. import
  2026. info
  2027. inspect
  2028. kill
  2029. load
  2030. login
  2031. logout
  2032. logs
  2033. network
  2034. pause
  2035. port
  2036. ps
  2037. pull
  2038. push
  2039. rename
  2040. restart
  2041. rm
  2042. rmi
  2043. run
  2044. save
  2045. search
  2046. start
  2047. stats
  2048. stop
  2049. tag
  2050. top
  2051. unpause
  2052. update
  2053. version
  2054. volume
  2055. wait
  2056. )
  2057. # These options are valid as global options for all client commands
  2058. # and valid as command options for `docker daemon`
  2059. local global_boolean_options="
  2060. --debug -D
  2061. --tls
  2062. --tlsverify
  2063. "
  2064. local global_options_with_args="
  2065. --config
  2066. --host -H
  2067. --log-level -l
  2068. --tlscacert
  2069. --tlscert
  2070. --tlskey
  2071. "
  2072. local host config
  2073. COMPREPLY=()
  2074. local cur prev words cword
  2075. _get_comp_words_by_ref -n : cur prev words cword
  2076. local command='docker' command_pos=0 subcommand_pos
  2077. local counter=1
  2078. while [ $counter -lt $cword ]; do
  2079. case "${words[$counter]}" in
  2080. # save host so that completion can use custom daemon
  2081. --host|-H)
  2082. (( counter++ ))
  2083. host="${words[$counter]}"
  2084. ;;
  2085. # save config so that completion can use custom configuration directories
  2086. --config)
  2087. (( counter++ ))
  2088. config="${words[$counter]}"
  2089. ;;
  2090. $(__docker_to_extglob "$global_options_with_args") )
  2091. (( counter++ ))
  2092. ;;
  2093. -*)
  2094. ;;
  2095. =)
  2096. (( counter++ ))
  2097. ;;
  2098. *)
  2099. command="${words[$counter]}"
  2100. command_pos=$counter
  2101. break
  2102. ;;
  2103. esac
  2104. (( counter++ ))
  2105. done
  2106. local completions_func=_docker_${command}
  2107. declare -F $completions_func >/dev/null && $completions_func
  2108. eval "$previous_extglob_setting"
  2109. return 0
  2110. }
  2111. eval "$__docker_previous_extglob_setting"
  2112. unset __docker_previous_extglob_setting
  2113. complete -F _docker docker