docker 43 KB

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