docker 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344
  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|syslog-tls-cert|syslog-tls-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|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_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. detach
  899. die
  900. disconnect
  901. exec_create
  902. exec_detach
  903. exec_start
  904. export
  905. import
  906. kill
  907. mount
  908. oom
  909. pause
  910. pull
  911. push
  912. reload
  913. rename
  914. resize
  915. restart
  916. start
  917. stop
  918. tag
  919. top
  920. unmount
  921. unpause
  922. untag
  923. update
  924. " -- "${cur##*=}" ) )
  925. return
  926. ;;
  927. image)
  928. cur="${cur##*=}"
  929. __docker_complete_images
  930. return
  931. ;;
  932. network)
  933. cur="${cur##*=}"
  934. __docker_complete_networks
  935. return
  936. ;;
  937. type)
  938. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  939. return
  940. ;;
  941. volume)
  942. cur="${cur##*=}"
  943. __docker_complete_volumes
  944. return
  945. ;;
  946. esac
  947. case "$prev" in
  948. --filter|-f)
  949. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  950. __docker_nospace
  951. return
  952. ;;
  953. --since|--until)
  954. return
  955. ;;
  956. esac
  957. case "$cur" in
  958. -*)
  959. COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) )
  960. ;;
  961. esac
  962. }
  963. _docker_exec() {
  964. __docker_complete_detach-keys && return
  965. case "$prev" in
  966. --user|-u)
  967. __docker_complete_user_group
  968. return
  969. ;;
  970. esac
  971. case "$cur" in
  972. -*)
  973. COMPREPLY=( $( compgen -W "--detach -d --detach-keys --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  974. ;;
  975. *)
  976. __docker_complete_containers_running
  977. ;;
  978. esac
  979. }
  980. _docker_export() {
  981. case "$cur" in
  982. -*)
  983. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  984. ;;
  985. *)
  986. local counter=$(__docker_pos_first_nonflag)
  987. if [ $cword -eq $counter ]; then
  988. __docker_complete_containers_all
  989. fi
  990. ;;
  991. esac
  992. }
  993. _docker_help() {
  994. local counter=$(__docker_pos_first_nonflag)
  995. if [ $cword -eq $counter ]; then
  996. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  997. fi
  998. }
  999. _docker_history() {
  1000. case "$cur" in
  1001. -*)
  1002. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  1003. ;;
  1004. *)
  1005. local counter=$(__docker_pos_first_nonflag)
  1006. if [ $cword -eq $counter ]; then
  1007. __docker_complete_images
  1008. fi
  1009. ;;
  1010. esac
  1011. }
  1012. _docker_images() {
  1013. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1014. case "$key" in
  1015. before)
  1016. cur="${cur##*=}"
  1017. __docker_complete_images
  1018. return
  1019. ;;
  1020. dangling)
  1021. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1022. return
  1023. ;;
  1024. label)
  1025. return
  1026. ;;
  1027. since)
  1028. cur="${cur##*=}"
  1029. __docker_complete_images
  1030. return
  1031. ;;
  1032. esac
  1033. case "$prev" in
  1034. --filter|-f)
  1035. COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) )
  1036. __docker_nospace
  1037. return
  1038. ;;
  1039. --format)
  1040. return
  1041. ;;
  1042. esac
  1043. case "$cur" in
  1044. -*)
  1045. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1046. ;;
  1047. =)
  1048. return
  1049. ;;
  1050. *)
  1051. __docker_complete_image_repos
  1052. ;;
  1053. esac
  1054. }
  1055. _docker_import() {
  1056. case "$prev" in
  1057. --change|-c|--message|-m)
  1058. return
  1059. ;;
  1060. esac
  1061. case "$cur" in
  1062. -*)
  1063. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1064. ;;
  1065. *)
  1066. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1067. if [ $cword -eq $counter ]; then
  1068. return
  1069. fi
  1070. (( counter++ ))
  1071. if [ $cword -eq $counter ]; then
  1072. __docker_complete_image_repos_and_tags
  1073. return
  1074. fi
  1075. ;;
  1076. esac
  1077. }
  1078. _docker_info() {
  1079. case "$cur" in
  1080. -*)
  1081. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1082. ;;
  1083. esac
  1084. }
  1085. _docker_inspect() {
  1086. case "$prev" in
  1087. --format|-f)
  1088. return
  1089. ;;
  1090. --type)
  1091. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  1092. return
  1093. ;;
  1094. esac
  1095. case "$cur" in
  1096. -*)
  1097. COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) )
  1098. ;;
  1099. *)
  1100. case $(__docker_value_of_option --type) in
  1101. '')
  1102. __docker_complete_containers_and_images
  1103. ;;
  1104. container)
  1105. __docker_complete_containers_all
  1106. ;;
  1107. image)
  1108. __docker_complete_images
  1109. ;;
  1110. esac
  1111. esac
  1112. }
  1113. _docker_kill() {
  1114. case "$prev" in
  1115. --signal|-s)
  1116. __docker_complete_signals
  1117. return
  1118. ;;
  1119. esac
  1120. case "$cur" in
  1121. -*)
  1122. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  1123. ;;
  1124. *)
  1125. __docker_complete_containers_running
  1126. ;;
  1127. esac
  1128. }
  1129. _docker_load() {
  1130. case "$prev" in
  1131. --input|-i)
  1132. _filedir
  1133. return
  1134. ;;
  1135. esac
  1136. case "$cur" in
  1137. -*)
  1138. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1139. ;;
  1140. esac
  1141. }
  1142. _docker_login() {
  1143. case "$prev" in
  1144. --password|-p|--username|-u)
  1145. return
  1146. ;;
  1147. esac
  1148. case "$cur" in
  1149. -*)
  1150. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  1151. ;;
  1152. esac
  1153. }
  1154. _docker_logout() {
  1155. case "$cur" in
  1156. -*)
  1157. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1158. ;;
  1159. esac
  1160. }
  1161. _docker_logs() {
  1162. case "$prev" in
  1163. --since|--tail)
  1164. return
  1165. ;;
  1166. esac
  1167. case "$cur" in
  1168. -*)
  1169. COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  1170. ;;
  1171. *)
  1172. local counter=$(__docker_pos_first_nonflag '--tail')
  1173. if [ $cword -eq $counter ]; then
  1174. __docker_complete_containers_all
  1175. fi
  1176. ;;
  1177. esac
  1178. }
  1179. _docker_network_connect() {
  1180. local options_with_args="
  1181. --alias
  1182. --ip
  1183. --ip6
  1184. --link
  1185. "
  1186. local boolean_options="
  1187. --help
  1188. "
  1189. case "$prev" in
  1190. --link)
  1191. case "$cur" in
  1192. *:*)
  1193. ;;
  1194. *)
  1195. __docker_complete_containers_running
  1196. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1197. __docker_nospace
  1198. ;;
  1199. esac
  1200. return
  1201. ;;
  1202. $(__docker_to_extglob "$options_with_args") )
  1203. return
  1204. ;;
  1205. esac
  1206. case "$cur" in
  1207. -*)
  1208. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1209. ;;
  1210. *)
  1211. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1212. if [ $cword -eq $counter ]; then
  1213. __docker_complete_networks
  1214. elif [ $cword -eq $(($counter + 1)) ]; then
  1215. __docker_complete_containers_all
  1216. fi
  1217. ;;
  1218. esac
  1219. }
  1220. _docker_network_create() {
  1221. case "$prev" in
  1222. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  1223. return
  1224. ;;
  1225. --ipam-driver)
  1226. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  1227. return
  1228. ;;
  1229. --driver|-d)
  1230. local plugins=" $(__docker_plugins Network) "
  1231. # remove drivers that allow one instance only
  1232. plugins=${plugins/ host / }
  1233. plugins=${plugins/ null / }
  1234. COMPREPLY=( $(compgen -W "$plugins" -- "$cur") )
  1235. return
  1236. ;;
  1237. --label)
  1238. return
  1239. ;;
  1240. esac
  1241. case "$cur" in
  1242. -*)
  1243. COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  1244. ;;
  1245. esac
  1246. }
  1247. _docker_network_disconnect() {
  1248. case "$cur" in
  1249. -*)
  1250. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1251. ;;
  1252. *)
  1253. local counter=$(__docker_pos_first_nonflag)
  1254. if [ $cword -eq $counter ]; then
  1255. __docker_complete_networks
  1256. elif [ $cword -eq $(($counter + 1)) ]; then
  1257. __docker_complete_containers_in_network "$prev"
  1258. fi
  1259. ;;
  1260. esac
  1261. }
  1262. _docker_network_inspect() {
  1263. case "$prev" in
  1264. --format|-f)
  1265. return
  1266. ;;
  1267. esac
  1268. case "$cur" in
  1269. -*)
  1270. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1271. ;;
  1272. *)
  1273. __docker_complete_networks
  1274. esac
  1275. }
  1276. _docker_network_ls() {
  1277. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1278. case "$key" in
  1279. driver)
  1280. local plugins=" $(__docker_plugins Network) "
  1281. COMPREPLY=( $(compgen -W "$plugins" -- "${cur##*=}") )
  1282. return
  1283. ;;
  1284. id)
  1285. cur="${cur##*=}"
  1286. __docker_complete_network_ids
  1287. return
  1288. ;;
  1289. name)
  1290. cur="${cur##*=}"
  1291. __docker_complete_network_names
  1292. return
  1293. ;;
  1294. type)
  1295. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  1296. return
  1297. ;;
  1298. esac
  1299. case "$prev" in
  1300. --filter|-f)
  1301. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  1302. __docker_nospace
  1303. return
  1304. ;;
  1305. esac
  1306. case "$cur" in
  1307. -*)
  1308. COMPREPLY=( $( compgen -W "--filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
  1309. ;;
  1310. esac
  1311. }
  1312. _docker_network_rm() {
  1313. case "$cur" in
  1314. -*)
  1315. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1316. ;;
  1317. *)
  1318. __docker_complete_networks type=custom
  1319. esac
  1320. }
  1321. _docker_network() {
  1322. local subcommands="
  1323. connect
  1324. create
  1325. disconnect
  1326. inspect
  1327. ls
  1328. rm
  1329. "
  1330. __docker_subcommands "$subcommands" && return
  1331. case "$cur" in
  1332. -*)
  1333. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1334. ;;
  1335. *)
  1336. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1337. ;;
  1338. esac
  1339. }
  1340. _docker_pause() {
  1341. case "$cur" in
  1342. -*)
  1343. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1344. ;;
  1345. *)
  1346. local counter=$(__docker_pos_first_nonflag)
  1347. if [ $cword -eq $counter ]; then
  1348. __docker_complete_containers_pauseable
  1349. fi
  1350. ;;
  1351. esac
  1352. }
  1353. _docker_port() {
  1354. case "$cur" in
  1355. -*)
  1356. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1357. ;;
  1358. *)
  1359. local counter=$(__docker_pos_first_nonflag)
  1360. if [ $cword -eq $counter ]; then
  1361. __docker_complete_containers_all
  1362. fi
  1363. ;;
  1364. esac
  1365. }
  1366. _docker_ps() {
  1367. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1368. case "$key" in
  1369. ancestor)
  1370. cur="${cur##*=}"
  1371. __docker_complete_images
  1372. return
  1373. ;;
  1374. before)
  1375. cur="${cur##*=}"
  1376. __docker_complete_containers_all
  1377. return
  1378. ;;
  1379. id)
  1380. cur="${cur##*=}"
  1381. __docker_complete_container_ids
  1382. return
  1383. ;;
  1384. name)
  1385. cur="${cur##*=}"
  1386. __docker_complete_container_names
  1387. return
  1388. ;;
  1389. network)
  1390. cur="${cur##*=}"
  1391. __docker_complete_networks
  1392. return
  1393. ;;
  1394. since)
  1395. cur="${cur##*=}"
  1396. __docker_complete_containers_all
  1397. return
  1398. ;;
  1399. status)
  1400. COMPREPLY=( $( compgen -W "created dead exited paused restarting running" -- "${cur##*=}" ) )
  1401. return
  1402. ;;
  1403. volume)
  1404. cur="${cur##*=}"
  1405. __docker_complete_volumes
  1406. return
  1407. ;;
  1408. esac
  1409. case "$prev" in
  1410. --filter|-f)
  1411. COMPREPLY=( $( compgen -S = -W "ancestor before exited id label name network since status volume" -- "$cur" ) )
  1412. __docker_nospace
  1413. return
  1414. ;;
  1415. --format|-n)
  1416. return
  1417. ;;
  1418. esac
  1419. case "$cur" in
  1420. -*)
  1421. COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --latest -l -n --no-trunc --quiet -q --size -s" -- "$cur" ) )
  1422. ;;
  1423. esac
  1424. }
  1425. _docker_pull() {
  1426. case "$cur" in
  1427. -*)
  1428. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  1429. ;;
  1430. *)
  1431. local counter=$(__docker_pos_first_nonflag)
  1432. if [ $cword -eq $counter ]; then
  1433. for arg in "${COMP_WORDS[@]}"; do
  1434. case "$arg" in
  1435. --all-tags|-a)
  1436. __docker_complete_image_repos
  1437. return
  1438. ;;
  1439. esac
  1440. done
  1441. __docker_complete_image_repos_and_tags
  1442. fi
  1443. ;;
  1444. esac
  1445. }
  1446. _docker_push() {
  1447. case "$cur" in
  1448. -*)
  1449. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  1450. ;;
  1451. *)
  1452. local counter=$(__docker_pos_first_nonflag)
  1453. if [ $cword -eq $counter ]; then
  1454. __docker_complete_image_repos_and_tags
  1455. fi
  1456. ;;
  1457. esac
  1458. }
  1459. _docker_rename() {
  1460. case "$cur" in
  1461. -*)
  1462. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1463. ;;
  1464. *)
  1465. local counter=$(__docker_pos_first_nonflag)
  1466. if [ $cword -eq $counter ]; then
  1467. __docker_complete_containers_all
  1468. fi
  1469. ;;
  1470. esac
  1471. }
  1472. _docker_restart() {
  1473. case "$prev" in
  1474. --time|-t)
  1475. return
  1476. ;;
  1477. esac
  1478. case "$cur" in
  1479. -*)
  1480. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1481. ;;
  1482. *)
  1483. __docker_complete_containers_all
  1484. ;;
  1485. esac
  1486. }
  1487. _docker_rm() {
  1488. case "$cur" in
  1489. -*)
  1490. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  1491. ;;
  1492. *)
  1493. for arg in "${COMP_WORDS[@]}"; do
  1494. case "$arg" in
  1495. --force|-f)
  1496. __docker_complete_containers_all
  1497. return
  1498. ;;
  1499. esac
  1500. done
  1501. __docker_complete_containers_stopped
  1502. ;;
  1503. esac
  1504. }
  1505. _docker_rmi() {
  1506. case "$cur" in
  1507. -*)
  1508. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  1509. ;;
  1510. *)
  1511. __docker_complete_images
  1512. ;;
  1513. esac
  1514. }
  1515. _docker_run() {
  1516. local options_with_args="
  1517. --add-host
  1518. --attach -a
  1519. --blkio-weight
  1520. --blkio-weight-device
  1521. --cap-add
  1522. --cap-drop
  1523. --cgroup-parent
  1524. --cidfile
  1525. --cpu-period
  1526. --cpu-quota
  1527. --cpuset-cpus
  1528. --cpuset-mems
  1529. --cpu-shares
  1530. --device
  1531. --device-read-bps
  1532. --device-read-iops
  1533. --device-write-bps
  1534. --device-write-iops
  1535. --dns
  1536. --dns-opt
  1537. --dns-search
  1538. --entrypoint
  1539. --env -e
  1540. --env-file
  1541. --expose
  1542. --group-add
  1543. --hostname -h
  1544. --ip
  1545. --ip6
  1546. --ipc
  1547. --isolation
  1548. --kernel-memory
  1549. --label-file
  1550. --label -l
  1551. --link
  1552. --log-driver
  1553. --log-opt
  1554. --mac-address
  1555. --memory -m
  1556. --memory-swap
  1557. --memory-swappiness
  1558. --memory-reservation
  1559. --name
  1560. --net
  1561. --net-alias
  1562. --oom-score-adj
  1563. --pid
  1564. --pids-limit
  1565. --publish -p
  1566. --restart
  1567. --security-opt
  1568. --shm-size
  1569. --stop-signal
  1570. --tmpfs
  1571. --sysctl
  1572. --ulimit
  1573. --user -u
  1574. --userns
  1575. --uts
  1576. --volume-driver
  1577. --volumes-from
  1578. --volume -v
  1579. --workdir -w
  1580. "
  1581. local boolean_options="
  1582. --disable-content-trust=false
  1583. --help
  1584. --interactive -i
  1585. --oom-kill-disable
  1586. --privileged
  1587. --publish-all -P
  1588. --read-only
  1589. --tty -t
  1590. "
  1591. if [ "$command" = "run" ] ; then
  1592. options_with_args="$options_with_args
  1593. --detach-keys
  1594. --health-cmd
  1595. --health-interval
  1596. --health-retries
  1597. --health-timeout
  1598. "
  1599. boolean_options="$boolean_options
  1600. --detach -d
  1601. --no-healthcheck
  1602. --rm
  1603. --sig-proxy=false
  1604. "
  1605. __docker_complete_detach-keys && return
  1606. fi
  1607. local all_options="$options_with_args $boolean_options"
  1608. __docker_complete_log_driver_options && return
  1609. __docker_complete_restart && return
  1610. local key=$(__docker_map_key_of_current_option '--security-opt')
  1611. case "$key" in
  1612. label)
  1613. [[ $cur == *: ]] && return
  1614. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  1615. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  1616. __docker_nospace
  1617. fi
  1618. return
  1619. ;;
  1620. seccomp)
  1621. local cur=${cur##*=}
  1622. _filedir
  1623. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  1624. return
  1625. ;;
  1626. esac
  1627. case "$prev" in
  1628. --add-host)
  1629. case "$cur" in
  1630. *:)
  1631. __docker_complete_resolved_hostname
  1632. return
  1633. ;;
  1634. esac
  1635. ;;
  1636. --attach|-a)
  1637. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  1638. return
  1639. ;;
  1640. --cap-add|--cap-drop)
  1641. __docker_complete_capabilities
  1642. return
  1643. ;;
  1644. --cidfile|--env-file|--label-file)
  1645. _filedir
  1646. return
  1647. ;;
  1648. --device|--tmpfs|--volume|-v)
  1649. case "$cur" in
  1650. *:*)
  1651. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  1652. ;;
  1653. '')
  1654. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  1655. __docker_nospace
  1656. ;;
  1657. /*)
  1658. _filedir
  1659. __docker_nospace
  1660. ;;
  1661. esac
  1662. return
  1663. ;;
  1664. --env|-e)
  1665. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1666. __docker_nospace
  1667. return
  1668. ;;
  1669. --ipc)
  1670. case "$cur" in
  1671. *:*)
  1672. cur="${cur#*:}"
  1673. __docker_complete_containers_running
  1674. ;;
  1675. *)
  1676. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1677. if [ "$COMPREPLY" = "container:" ]; then
  1678. __docker_nospace
  1679. fi
  1680. ;;
  1681. esac
  1682. return
  1683. ;;
  1684. --isolation)
  1685. __docker_complete_isolation
  1686. return
  1687. ;;
  1688. --link)
  1689. case "$cur" in
  1690. *:*)
  1691. ;;
  1692. *)
  1693. __docker_complete_containers_running
  1694. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1695. __docker_nospace
  1696. ;;
  1697. esac
  1698. return
  1699. ;;
  1700. --log-driver)
  1701. __docker_complete_log_drivers
  1702. return
  1703. ;;
  1704. --log-opt)
  1705. __docker_complete_log_options
  1706. return
  1707. ;;
  1708. --net)
  1709. case "$cur" in
  1710. container:*)
  1711. local cur=${cur#*:}
  1712. __docker_complete_containers_all
  1713. ;;
  1714. *)
  1715. COMPREPLY=( $( compgen -W "$(__docker_plugins Network) $(__docker_networks) container:" -- "$cur") )
  1716. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1717. __docker_nospace
  1718. fi
  1719. ;;
  1720. esac
  1721. return
  1722. ;;
  1723. --pid)
  1724. case "$cur" in
  1725. *:*)
  1726. cur="${cur#*:}"
  1727. __docker_complete_containers_running
  1728. ;;
  1729. *)
  1730. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1731. if [ "$COMPREPLY" = "container:" ]; then
  1732. __docker_nospace
  1733. fi
  1734. ;;
  1735. esac
  1736. return
  1737. ;;
  1738. --security-opt)
  1739. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  1740. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  1741. __docker_nospace
  1742. fi
  1743. return
  1744. ;;
  1745. --user|-u)
  1746. __docker_complete_user_group
  1747. return
  1748. ;;
  1749. --userns)
  1750. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  1751. return
  1752. ;;
  1753. --volume-driver)
  1754. __docker_complete_plugins Volume
  1755. return
  1756. ;;
  1757. --volumes-from)
  1758. __docker_complete_containers_all
  1759. return
  1760. ;;
  1761. $(__docker_to_extglob "$options_with_args") )
  1762. return
  1763. ;;
  1764. esac
  1765. case "$cur" in
  1766. -*)
  1767. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1768. ;;
  1769. *)
  1770. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1771. if [ $cword -eq $counter ]; then
  1772. __docker_complete_images
  1773. fi
  1774. ;;
  1775. esac
  1776. }
  1777. _docker_save() {
  1778. case "$prev" in
  1779. --output|-o)
  1780. _filedir
  1781. return
  1782. ;;
  1783. esac
  1784. case "$cur" in
  1785. -*)
  1786. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  1787. ;;
  1788. *)
  1789. __docker_complete_images
  1790. ;;
  1791. esac
  1792. }
  1793. _docker_search() {
  1794. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1795. case "$key" in
  1796. is-automated)
  1797. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1798. return
  1799. ;;
  1800. is-official)
  1801. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1802. return
  1803. ;;
  1804. esac
  1805. case "$prev" in
  1806. --filter|-f)
  1807. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  1808. __docker_nospace
  1809. return
  1810. ;;
  1811. --limit)
  1812. return
  1813. ;;
  1814. esac
  1815. case "$cur" in
  1816. -*)
  1817. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  1818. ;;
  1819. esac
  1820. }
  1821. _docker_start() {
  1822. __docker_complete_detach-keys && return
  1823. case "$cur" in
  1824. -*)
  1825. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  1826. ;;
  1827. *)
  1828. __docker_complete_containers_stopped
  1829. ;;
  1830. esac
  1831. }
  1832. _docker_stats() {
  1833. case "$cur" in
  1834. -*)
  1835. COMPREPLY=( $( compgen -W "--all -a --help --no-stream" -- "$cur" ) )
  1836. ;;
  1837. *)
  1838. __docker_complete_containers_running
  1839. ;;
  1840. esac
  1841. }
  1842. _docker_stop() {
  1843. case "$prev" in
  1844. --time|-t)
  1845. return
  1846. ;;
  1847. esac
  1848. case "$cur" in
  1849. -*)
  1850. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1851. ;;
  1852. *)
  1853. __docker_complete_containers_running
  1854. ;;
  1855. esac
  1856. }
  1857. _docker_tag() {
  1858. case "$cur" in
  1859. -*)
  1860. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1861. ;;
  1862. *)
  1863. local counter=$(__docker_pos_first_nonflag)
  1864. if [ $cword -eq $counter ]; then
  1865. __docker_complete_image_repos_and_tags
  1866. return
  1867. fi
  1868. (( counter++ ))
  1869. if [ $cword -eq $counter ]; then
  1870. __docker_complete_image_repos_and_tags
  1871. return
  1872. fi
  1873. ;;
  1874. esac
  1875. }
  1876. _docker_unpause() {
  1877. case "$cur" in
  1878. -*)
  1879. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1880. ;;
  1881. *)
  1882. local counter=$(__docker_pos_first_nonflag)
  1883. if [ $cword -eq $counter ]; then
  1884. __docker_complete_containers_unpauseable
  1885. fi
  1886. ;;
  1887. esac
  1888. }
  1889. _docker_update() {
  1890. local options_with_args="
  1891. --blkio-weight
  1892. --cpu-period
  1893. --cpu-quota
  1894. --cpuset-cpus
  1895. --cpuset-mems
  1896. --cpu-shares
  1897. --kernel-memory
  1898. --memory -m
  1899. --memory-reservation
  1900. --memory-swap
  1901. --restart
  1902. "
  1903. local boolean_options="
  1904. --help
  1905. "
  1906. local all_options="$options_with_args $boolean_options"
  1907. __docker_complete_restart && return
  1908. case "$prev" in
  1909. $(__docker_to_extglob "$options_with_args") )
  1910. return
  1911. ;;
  1912. esac
  1913. case "$cur" in
  1914. -*)
  1915. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1916. ;;
  1917. *)
  1918. __docker_complete_containers_all
  1919. ;;
  1920. esac
  1921. }
  1922. _docker_top() {
  1923. case "$cur" in
  1924. -*)
  1925. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1926. ;;
  1927. *)
  1928. local counter=$(__docker_pos_first_nonflag)
  1929. if [ $cword -eq $counter ]; then
  1930. __docker_complete_containers_running
  1931. fi
  1932. ;;
  1933. esac
  1934. }
  1935. _docker_version() {
  1936. case "$cur" in
  1937. -*)
  1938. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1939. ;;
  1940. esac
  1941. }
  1942. _docker_volume_create() {
  1943. case "$prev" in
  1944. --driver|-d)
  1945. __docker_complete_plugins Volume
  1946. return
  1947. ;;
  1948. --label|--name|--opt|-o)
  1949. return
  1950. ;;
  1951. esac
  1952. case "$cur" in
  1953. -*)
  1954. COMPREPLY=( $( compgen -W "--driver -d --help --label --name --opt -o" -- "$cur" ) )
  1955. ;;
  1956. esac
  1957. }
  1958. _docker_volume_inspect() {
  1959. case "$prev" in
  1960. --format|-f)
  1961. return
  1962. ;;
  1963. esac
  1964. case "$cur" in
  1965. -*)
  1966. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1967. ;;
  1968. *)
  1969. __docker_complete_volumes
  1970. ;;
  1971. esac
  1972. }
  1973. _docker_volume_ls() {
  1974. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1975. case "$key" in
  1976. dangling)
  1977. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  1978. return
  1979. ;;
  1980. driver)
  1981. cur=${cur##*=}
  1982. __docker_complete_plugins Volume
  1983. return
  1984. ;;
  1985. name)
  1986. cur=${cur##*=}
  1987. __docker_complete_volumes
  1988. return
  1989. ;;
  1990. esac
  1991. case "$prev" in
  1992. --filter|-f)
  1993. COMPREPLY=( $( compgen -S = -W "dangling driver name" -- "$cur" ) )
  1994. __docker_nospace
  1995. return
  1996. ;;
  1997. esac
  1998. case "$cur" in
  1999. -*)
  2000. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  2001. ;;
  2002. esac
  2003. }
  2004. _docker_volume_rm() {
  2005. case "$cur" in
  2006. -*)
  2007. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2008. ;;
  2009. *)
  2010. __docker_complete_volumes
  2011. ;;
  2012. esac
  2013. }
  2014. _docker_volume() {
  2015. local subcommands="
  2016. create
  2017. inspect
  2018. ls
  2019. rm
  2020. "
  2021. __docker_subcommands "$subcommands" && return
  2022. case "$cur" in
  2023. -*)
  2024. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2025. ;;
  2026. *)
  2027. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2028. ;;
  2029. esac
  2030. }
  2031. _docker_wait() {
  2032. case "$cur" in
  2033. -*)
  2034. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2035. ;;
  2036. *)
  2037. __docker_complete_containers_all
  2038. ;;
  2039. esac
  2040. }
  2041. _docker() {
  2042. local previous_extglob_setting=$(shopt -p extglob)
  2043. shopt -s extglob
  2044. local commands=(
  2045. attach
  2046. build
  2047. commit
  2048. cp
  2049. create
  2050. daemon
  2051. diff
  2052. events
  2053. exec
  2054. export
  2055. history
  2056. images
  2057. import
  2058. info
  2059. inspect
  2060. kill
  2061. load
  2062. login
  2063. logout
  2064. logs
  2065. network
  2066. pause
  2067. port
  2068. ps
  2069. pull
  2070. push
  2071. rename
  2072. restart
  2073. rm
  2074. rmi
  2075. run
  2076. save
  2077. search
  2078. start
  2079. stats
  2080. stop
  2081. tag
  2082. top
  2083. unpause
  2084. update
  2085. version
  2086. volume
  2087. wait
  2088. )
  2089. # These options are valid as global options for all client commands
  2090. # and valid as command options for `docker daemon`
  2091. local global_boolean_options="
  2092. --debug -D
  2093. --tls
  2094. --tlsverify
  2095. "
  2096. local global_options_with_args="
  2097. --config
  2098. --host -H
  2099. --log-level -l
  2100. --tlscacert
  2101. --tlscert
  2102. --tlskey
  2103. "
  2104. local host config
  2105. COMPREPLY=()
  2106. local cur prev words cword
  2107. _get_comp_words_by_ref -n : cur prev words cword
  2108. local command='docker' command_pos=0 subcommand_pos
  2109. local counter=1
  2110. while [ $counter -lt $cword ]; do
  2111. case "${words[$counter]}" in
  2112. # save host so that completion can use custom daemon
  2113. --host|-H)
  2114. (( counter++ ))
  2115. host="${words[$counter]}"
  2116. ;;
  2117. # save config so that completion can use custom configuration directories
  2118. --config)
  2119. (( counter++ ))
  2120. config="${words[$counter]}"
  2121. ;;
  2122. $(__docker_to_extglob "$global_options_with_args") )
  2123. (( counter++ ))
  2124. ;;
  2125. -*)
  2126. ;;
  2127. =)
  2128. (( counter++ ))
  2129. ;;
  2130. *)
  2131. command="${words[$counter]}"
  2132. command_pos=$counter
  2133. break
  2134. ;;
  2135. esac
  2136. (( counter++ ))
  2137. done
  2138. local binary="${words[0]}"
  2139. if [[ $binary == ?(*/)dockerd ]] ; then
  2140. # for the dockerd binary, we reuse completion of `docker daemon`.
  2141. # dockerd does not have subcommands and global options.
  2142. command=daemon
  2143. command_pos=0
  2144. fi
  2145. local completions_func=_docker_${command}
  2146. declare -F $completions_func >/dev/null && $completions_func
  2147. eval "$previous_extglob_setting"
  2148. return 0
  2149. }
  2150. eval "$__docker_previous_extglob_setting"
  2151. unset __docker_previous_extglob_setting
  2152. complete -F _docker docker dockerd