docker 36 KB

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