docker 43 KB

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