docker 36 KB

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