docker 43 KB

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