docker 20 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  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. # Note:
  19. # Currently, the completions will not work if the docker daemon is not
  20. # bound to the default communication port/socket
  21. # If the docker daemon is using a unix socket for communication your user
  22. # must have access to the socket for the completions to function correctly
  23. #
  24. # Note for developers:
  25. # Please arrange options sorted alphabetically by long name with the short
  26. # options immediately following their corresponding long form.
  27. # This order should be applied to lists, alternatives and code blocks.
  28. __docker_q() {
  29. docker 2>/dev/null "$@"
  30. }
  31. __docker_containers_all() {
  32. local IFS=$'\n'
  33. local containers=( $(__docker_q ps -aq --no-trunc) )
  34. if [ "$1" ]; then
  35. containers=( $(__docker_q inspect --format "{{if $1}}{{.Id}}{{end}}" "${containers[@]}") )
  36. fi
  37. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  38. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  39. unset IFS
  40. COMPREPLY=( $(compgen -W "${names[*]} ${containers[*]}" -- "$cur") )
  41. }
  42. __docker_containers_running() {
  43. __docker_containers_all '.State.Running'
  44. }
  45. __docker_containers_stopped() {
  46. __docker_containers_all 'not .State.Running'
  47. }
  48. __docker_containers_pauseable() {
  49. __docker_containers_all 'and .State.Running (not .State.Paused)'
  50. }
  51. __docker_containers_unpauseable() {
  52. __docker_containers_all '.State.Paused'
  53. }
  54. __docker_image_repos() {
  55. local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')"
  56. COMPREPLY=( $(compgen -W "$repos" -- "$cur") )
  57. }
  58. __docker_image_repos_and_tags() {
  59. local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')"
  60. COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") )
  61. __ltrim_colon_completions "$cur"
  62. }
  63. __docker_image_repos_and_tags_and_ids() {
  64. local images="$(__docker_q images -a --no-trunc | awk 'NR>1 { print $3; if ($1 != "<none>") { print $1; print $1":"$2 } }')"
  65. COMPREPLY=( $(compgen -W "$images" -- "$cur") )
  66. __ltrim_colon_completions "$cur"
  67. }
  68. __docker_containers_and_images() {
  69. __docker_containers_all
  70. local containers=( "${COMPREPLY[@]}" )
  71. __docker_image_repos_and_tags_and_ids
  72. COMPREPLY+=( "${containers[@]}" )
  73. }
  74. __docker_pos_first_nonflag() {
  75. local argument_flags=$1
  76. local counter=$cpos
  77. while [ $counter -le $cword ]; do
  78. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  79. (( counter++ ))
  80. else
  81. case "${words[$counter]}" in
  82. -*)
  83. ;;
  84. *)
  85. break
  86. ;;
  87. esac
  88. fi
  89. (( counter++ ))
  90. done
  91. echo $counter
  92. }
  93. # Transforms a multiline list of strings into a single line string
  94. # with the words separated by "|".
  95. # This is used to prepare arguments to __docker_pos_first_nonflag().
  96. __docker_to_alternatives() {
  97. local parts=( $1 )
  98. local IFS='|'
  99. echo "${parts[*]}"
  100. }
  101. # Transforms a multiline list of options into an extglob pattern
  102. # suitable for use in case statements.
  103. __docker_to_extglob() {
  104. local extglob=$( __docker_to_alternatives "$1" )
  105. echo "@($extglob)"
  106. }
  107. __docker_resolve_hostname() {
  108. command -v host >/dev/null 2>&1 || return
  109. COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
  110. }
  111. __docker_capabilities() {
  112. # The list of capabilities is defined in types.go, ALL was added manually.
  113. COMPREPLY=( $( compgen -W "
  114. ALL
  115. AUDIT_CONTROL
  116. AUDIT_WRITE
  117. AUDIT_READ
  118. BLOCK_SUSPEND
  119. CHOWN
  120. DAC_OVERRIDE
  121. DAC_READ_SEARCH
  122. FOWNER
  123. FSETID
  124. IPC_LOCK
  125. IPC_OWNER
  126. KILL
  127. LEASE
  128. LINUX_IMMUTABLE
  129. MAC_ADMIN
  130. MAC_OVERRIDE
  131. MKNOD
  132. NET_ADMIN
  133. NET_BIND_SERVICE
  134. NET_BROADCAST
  135. NET_RAW
  136. SETFCAP
  137. SETGID
  138. SETPCAP
  139. SETUID
  140. SYS_ADMIN
  141. SYS_BOOT
  142. SYS_CHROOT
  143. SYSLOG
  144. SYS_MODULE
  145. SYS_NICE
  146. SYS_PACCT
  147. SYS_PTRACE
  148. SYS_RAWIO
  149. SYS_RESOURCE
  150. SYS_TIME
  151. SYS_TTY_CONFIG
  152. WAKE_ALARM
  153. " -- "$cur" ) )
  154. }
  155. # a selection of the available signals that is most likely of interest in the
  156. # context of docker containers.
  157. __docker_signals() {
  158. local signals=(
  159. SIGCONT
  160. SIGHUP
  161. SIGINT
  162. SIGKILL
  163. SIGQUIT
  164. SIGSTOP
  165. SIGTERM
  166. SIGUSR1
  167. SIGUSR2
  168. )
  169. COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) )
  170. }
  171. _docker_docker() {
  172. local boolean_options="
  173. --daemon -d
  174. --debug -D
  175. --help -h
  176. --icc
  177. --ip-forward
  178. --ip-masq
  179. --iptables
  180. --ipv6
  181. --selinux-enabled
  182. --tls
  183. --tlsverify
  184. --version -v
  185. "
  186. case "$prev" in
  187. --graph|-g)
  188. _filedir -d
  189. return
  190. ;;
  191. --log-level|-l)
  192. COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) )
  193. return
  194. ;;
  195. --pidfile|-p|--tlscacert|--tlscert|--tlskey)
  196. _filedir
  197. return
  198. ;;
  199. --storage-driver|-s)
  200. COMPREPLY=( $( compgen -W "aufs devicemapper btrfs overlay" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  201. return
  202. ;;
  203. $main_options_with_args_glob )
  204. return
  205. ;;
  206. esac
  207. case "$cur" in
  208. -*)
  209. COMPREPLY=( $( compgen -W "$boolean_options $main_options_with_args" -- "$cur" ) )
  210. ;;
  211. *)
  212. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  213. ;;
  214. esac
  215. }
  216. _docker_attach() {
  217. case "$cur" in
  218. -*)
  219. COMPREPLY=( $( compgen -W "--help --no-stdin --sig-proxy" -- "$cur" ) )
  220. ;;
  221. *)
  222. local counter="$(__docker_pos_first_nonflag)"
  223. if [ $cword -eq $counter ]; then
  224. __docker_containers_running
  225. fi
  226. ;;
  227. esac
  228. }
  229. _docker_build() {
  230. case "$prev" in
  231. --tag|-t)
  232. __docker_image_repos_and_tags
  233. return
  234. ;;
  235. --file|-f)
  236. _filedir
  237. return
  238. ;;
  239. esac
  240. case "$cur" in
  241. -*)
  242. COMPREPLY=( $( compgen -W "--file -f --force-rm --help --no-cache --pull --quiet -q --rm --tag -t" -- "$cur" ) )
  243. ;;
  244. *)
  245. local counter="$(__docker_pos_first_nonflag '--tag|-t')"
  246. if [ $cword -eq $counter ]; then
  247. _filedir -d
  248. fi
  249. ;;
  250. esac
  251. }
  252. _docker_commit() {
  253. case "$prev" in
  254. --author|-a|--change|-c|--message|-m)
  255. return
  256. ;;
  257. esac
  258. case "$cur" in
  259. -*)
  260. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause -p" -- "$cur" ) )
  261. ;;
  262. *)
  263. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  264. if [ $cword -eq $counter ]; then
  265. __docker_containers_all
  266. return
  267. fi
  268. (( counter++ ))
  269. if [ $cword -eq $counter ]; then
  270. __docker_image_repos_and_tags
  271. return
  272. fi
  273. ;;
  274. esac
  275. }
  276. _docker_cp() {
  277. case "$cur" in
  278. -*)
  279. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  280. ;;
  281. *)
  282. local counter=$(__docker_pos_first_nonflag)
  283. if [ $cword -eq $counter ]; then
  284. case "$cur" in
  285. *:)
  286. return
  287. ;;
  288. *)
  289. __docker_containers_all
  290. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  291. compopt -o nospace
  292. return
  293. ;;
  294. esac
  295. fi
  296. (( counter++ ))
  297. if [ $cword -eq $counter ]; then
  298. _filedir -d
  299. return
  300. fi
  301. ;;
  302. esac
  303. }
  304. _docker_create() {
  305. _docker_run
  306. }
  307. _docker_diff() {
  308. case "$cur" in
  309. -*)
  310. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  311. ;;
  312. *)
  313. local counter=$(__docker_pos_first_nonflag)
  314. if [ $cword -eq $counter ]; then
  315. __docker_containers_all
  316. fi
  317. ;;
  318. esac
  319. }
  320. _docker_events() {
  321. case "$prev" in
  322. --filter|-f)
  323. COMPREPLY=( $( compgen -S = -W "container event image" -- "$cur" ) )
  324. compopt -o nospace
  325. return
  326. ;;
  327. --since|--until)
  328. return
  329. ;;
  330. esac
  331. # "=" gets parsed to a word and assigned to either $cur or $prev depending on whether
  332. # it is the last character or not. So we search for "xxx=" in the the last two words.
  333. case "${words[$cword-2]}$prev=" in
  334. *container=*)
  335. cur="${cur#=}"
  336. __docker_containers_all
  337. return
  338. ;;
  339. *event=*)
  340. COMPREPLY=( $( compgen -W "create destroy die export kill pause restart start stop unpause" -- "${cur#=}" ) )
  341. return
  342. ;;
  343. *image=*)
  344. cur="${cur#=}"
  345. __docker_image_repos_and_tags_and_ids
  346. return
  347. ;;
  348. esac
  349. case "$cur" in
  350. -*)
  351. COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) )
  352. ;;
  353. esac
  354. }
  355. _docker_exec() {
  356. case "$cur" in
  357. -*)
  358. COMPREPLY=( $( compgen -W "--detach -d --help --interactive -i -t --tty" -- "$cur" ) )
  359. ;;
  360. *)
  361. __docker_containers_running
  362. ;;
  363. esac
  364. }
  365. _docker_export() {
  366. case "$cur" in
  367. -*)
  368. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  369. ;;
  370. *)
  371. local counter=$(__docker_pos_first_nonflag)
  372. if [ $cword -eq $counter ]; then
  373. __docker_containers_all
  374. fi
  375. ;;
  376. esac
  377. }
  378. _docker_help() {
  379. local counter=$(__docker_pos_first_nonflag)
  380. if [ $cword -eq $counter ]; then
  381. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  382. fi
  383. }
  384. _docker_history() {
  385. case "$cur" in
  386. -*)
  387. COMPREPLY=( $( compgen -W "--help --no-trunc --quiet -q" -- "$cur" ) )
  388. ;;
  389. *)
  390. local counter=$(__docker_pos_first_nonflag)
  391. if [ $cword -eq $counter ]; then
  392. __docker_image_repos_and_tags_and_ids
  393. fi
  394. ;;
  395. esac
  396. }
  397. _docker_images() {
  398. case "$prev" in
  399. --filter|-f)
  400. COMPREPLY=( $( compgen -W "dangling=true" -- "$cur" ) )
  401. return
  402. ;;
  403. esac
  404. case "${words[$cword-2]}$prev=" in
  405. *dangling=*)
  406. COMPREPLY=( $( compgen -W "true false" -- "${cur#=}" ) )
  407. return
  408. ;;
  409. esac
  410. case "$cur" in
  411. -*)
  412. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
  413. ;;
  414. *)
  415. local counter=$(__docker_pos_first_nonflag)
  416. if [ $cword -eq $counter ]; then
  417. __docker_image_repos
  418. fi
  419. ;;
  420. esac
  421. }
  422. _docker_import() {
  423. case "$cur" in
  424. -*)
  425. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  426. ;;
  427. *)
  428. local counter=$(__docker_pos_first_nonflag)
  429. if [ $cword -eq $counter ]; then
  430. return
  431. fi
  432. (( counter++ ))
  433. if [ $cword -eq $counter ]; then
  434. __docker_image_repos_and_tags
  435. return
  436. fi
  437. ;;
  438. esac
  439. }
  440. _docker_info() {
  441. case "$cur" in
  442. -*)
  443. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  444. ;;
  445. esac
  446. }
  447. _docker_inspect() {
  448. case "$prev" in
  449. --format|-f)
  450. return
  451. ;;
  452. esac
  453. case "$cur" in
  454. -*)
  455. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  456. ;;
  457. *)
  458. __docker_containers_and_images
  459. ;;
  460. esac
  461. }
  462. _docker_kill() {
  463. case "$prev" in
  464. --signal|-s)
  465. __docker_signals
  466. return
  467. ;;
  468. esac
  469. case "$cur" in
  470. -*)
  471. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  472. ;;
  473. *)
  474. __docker_containers_running
  475. ;;
  476. esac
  477. }
  478. _docker_load() {
  479. case "$prev" in
  480. --input|-i)
  481. _filedir
  482. return
  483. ;;
  484. esac
  485. case "$cur" in
  486. -*)
  487. COMPREPLY=( $( compgen -W "--help --input -i" -- "$cur" ) )
  488. ;;
  489. esac
  490. }
  491. _docker_login() {
  492. case "$prev" in
  493. --email|-e|--password|-p|--username|-u)
  494. return
  495. ;;
  496. esac
  497. case "$cur" in
  498. -*)
  499. COMPREPLY=( $( compgen -W "--email -e --help --password -p --username -u" -- "$cur" ) )
  500. ;;
  501. esac
  502. }
  503. _docker_logout() {
  504. case "$cur" in
  505. -*)
  506. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  507. ;;
  508. esac
  509. }
  510. _docker_logs() {
  511. case "$prev" in
  512. --tail)
  513. return
  514. ;;
  515. esac
  516. case "$cur" in
  517. -*)
  518. COMPREPLY=( $( compgen -W "--follow -f --help --tail --timestamps -t" -- "$cur" ) )
  519. ;;
  520. *)
  521. local counter=$(__docker_pos_first_nonflag '--tail')
  522. if [ $cword -eq $counter ]; then
  523. __docker_containers_all
  524. fi
  525. ;;
  526. esac
  527. }
  528. _docker_pause() {
  529. case "$cur" in
  530. -*)
  531. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  532. ;;
  533. *)
  534. local counter=$(__docker_pos_first_nonflag)
  535. if [ $cword -eq $counter ]; then
  536. __docker_containers_pauseable
  537. fi
  538. ;;
  539. esac
  540. }
  541. _docker_port() {
  542. case "$cur" in
  543. -*)
  544. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  545. ;;
  546. *)
  547. local counter=$(__docker_pos_first_nonflag)
  548. if [ $cword -eq $counter ]; then
  549. __docker_containers_all
  550. fi
  551. ;;
  552. esac
  553. }
  554. _docker_ps() {
  555. case "$prev" in
  556. --before|--since)
  557. __docker_containers_all
  558. ;;
  559. --filter|-f)
  560. COMPREPLY=( $( compgen -S = -W "exited status" -- "$cur" ) )
  561. compopt -o nospace
  562. return
  563. ;;
  564. -n)
  565. return
  566. ;;
  567. esac
  568. case "${words[$cword-2]}$prev=" in
  569. *status=*)
  570. COMPREPLY=( $( compgen -W "exited paused restarting running" -- "${cur#=}" ) )
  571. return
  572. ;;
  573. esac
  574. case "$cur" in
  575. -*)
  576. COMPREPLY=( $( compgen -W "--all -a --before --filter -f --help --latest -l -n --no-trunc --quiet -q --size -s --since" -- "$cur" ) )
  577. ;;
  578. esac
  579. }
  580. _docker_pull() {
  581. case "$cur" in
  582. -*)
  583. COMPREPLY=( $( compgen -W "--all-tags -a --help" -- "$cur" ) )
  584. ;;
  585. *)
  586. local counter=$(__docker_pos_first_nonflag)
  587. if [ $cword -eq $counter ]; then
  588. __docker_image_repos_and_tags
  589. fi
  590. ;;
  591. esac
  592. }
  593. _docker_push() {
  594. case "$cur" in
  595. -*)
  596. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  597. ;;
  598. *)
  599. local counter=$(__docker_pos_first_nonflag)
  600. if [ $cword -eq $counter ]; then
  601. __docker_image_repos_and_tags
  602. fi
  603. ;;
  604. esac
  605. }
  606. _docker_rename() {
  607. case "$cur" in
  608. -*)
  609. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  610. ;;
  611. *)
  612. local counter=$(__docker_pos_first_nonflag)
  613. if [ $cword -eq $counter ]; then
  614. __docker_containers_all
  615. fi
  616. ;;
  617. esac
  618. }
  619. _docker_restart() {
  620. case "$prev" in
  621. --time|-t)
  622. return
  623. ;;
  624. esac
  625. case "$cur" in
  626. -*)
  627. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  628. ;;
  629. *)
  630. __docker_containers_all
  631. ;;
  632. esac
  633. }
  634. _docker_rm() {
  635. case "$cur" in
  636. -*)
  637. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  638. ;;
  639. *)
  640. for arg in "${COMP_WORDS[@]}"; do
  641. case "$arg" in
  642. --force|-f)
  643. __docker_containers_all
  644. return
  645. ;;
  646. esac
  647. done
  648. __docker_containers_stopped
  649. ;;
  650. esac
  651. }
  652. _docker_rmi() {
  653. case "$cur" in
  654. -*)
  655. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  656. ;;
  657. *)
  658. __docker_image_repos_and_tags_and_ids
  659. ;;
  660. esac
  661. }
  662. _docker_run() {
  663. local options_with_args="
  664. --add-host
  665. --attach -a
  666. --cap-add
  667. --cap-drop
  668. --cgroup-parent
  669. --cidfile
  670. --cpuset
  671. --cpu-shares -c
  672. --device
  673. --dns
  674. --dns-search
  675. --entrypoint
  676. --env -e
  677. --env-file
  678. --expose
  679. --hostname -h
  680. --ipc
  681. --label -l
  682. --label-file
  683. --link
  684. --log-driver
  685. --lxc-conf
  686. --mac-address
  687. --memory -m
  688. --memory-swap
  689. --name
  690. --net
  691. --pid
  692. --publish -p
  693. --restart
  694. --security-opt
  695. --user -u
  696. --ulimit
  697. --volumes-from
  698. --volume -v
  699. --workdir -w
  700. "
  701. local all_options="$options_with_args
  702. --help
  703. --interactive -i
  704. --privileged
  705. --publish-all -P
  706. --read-only
  707. --tty -t
  708. "
  709. [ "$command" = "run" ] && all_options="$all_options
  710. --detach -d
  711. --rm
  712. --sig-proxy
  713. "
  714. local options_with_args_glob=$(__docker_to_extglob "$options_with_args")
  715. case "$prev" in
  716. --add-host)
  717. case "$cur" in
  718. *:)
  719. __docker_resolve_hostname
  720. return
  721. ;;
  722. esac
  723. ;;
  724. --attach|-a)
  725. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  726. return
  727. ;;
  728. --cap-add|--cap-drop)
  729. __docker_capabilities
  730. return
  731. ;;
  732. --cidfile|--env-file|--label-file)
  733. _filedir
  734. return
  735. ;;
  736. --device|--volume|-v)
  737. case "$cur" in
  738. *:*)
  739. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  740. ;;
  741. '')
  742. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  743. compopt -o nospace
  744. ;;
  745. /*)
  746. _filedir
  747. compopt -o nospace
  748. ;;
  749. esac
  750. return
  751. ;;
  752. --env|-e)
  753. COMPREPLY=( $( compgen -e -- "$cur" ) )
  754. compopt -o nospace
  755. return
  756. ;;
  757. --ipc)
  758. case "$cur" in
  759. *:*)
  760. cur="${cur#*:}"
  761. __docker_containers_running
  762. ;;
  763. *)
  764. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  765. if [ "$COMPREPLY" = "container:" ]; then
  766. compopt -o nospace
  767. fi
  768. ;;
  769. esac
  770. return
  771. ;;
  772. --link)
  773. case "$cur" in
  774. *:*)
  775. ;;
  776. *)
  777. __docker_containers_running
  778. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  779. compopt -o nospace
  780. ;;
  781. esac
  782. return
  783. ;;
  784. --log-driver)
  785. COMPREPLY=( $( compgen -W "json-file syslog none" -- "$cur") )
  786. return
  787. ;;
  788. --net)
  789. case "$cur" in
  790. container:*)
  791. local cur=${cur#*:}
  792. __docker_containers_all
  793. ;;
  794. *)
  795. COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") )
  796. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  797. compopt -o nospace
  798. fi
  799. ;;
  800. esac
  801. return
  802. ;;
  803. --restart)
  804. case "$cur" in
  805. on-failure:*)
  806. ;;
  807. *)
  808. COMPREPLY=( $( compgen -W "no on-failure on-failure: always" -- "$cur") )
  809. ;;
  810. esac
  811. return
  812. ;;
  813. --security-opt)
  814. case "$cur" in
  815. label:*:*)
  816. ;;
  817. label:*)
  818. local cur=${cur##*:}
  819. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") )
  820. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  821. compopt -o nospace
  822. fi
  823. ;;
  824. *)
  825. COMPREPLY=( $( compgen -W "label apparmor" -S ":" -- "$cur") )
  826. compopt -o nospace
  827. ;;
  828. esac
  829. return
  830. ;;
  831. --volumes-from)
  832. __docker_containers_all
  833. return
  834. ;;
  835. $options_with_args_glob )
  836. return
  837. ;;
  838. esac
  839. case "$cur" in
  840. -*)
  841. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  842. ;;
  843. *)
  844. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  845. if [ $cword -eq $counter ]; then
  846. __docker_image_repos_and_tags_and_ids
  847. fi
  848. ;;
  849. esac
  850. }
  851. _docker_save() {
  852. case "$prev" in
  853. --output|-o)
  854. _filedir
  855. return
  856. ;;
  857. esac
  858. case "$cur" in
  859. -*)
  860. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  861. ;;
  862. *)
  863. __docker_image_repos_and_tags_and_ids
  864. ;;
  865. esac
  866. }
  867. _docker_search() {
  868. case "$prev" in
  869. --stars|-s)
  870. return
  871. ;;
  872. esac
  873. case "$cur" in
  874. -*)
  875. COMPREPLY=( $( compgen -W "--automated --help --no-trunc --stars -s" -- "$cur" ) )
  876. ;;
  877. esac
  878. }
  879. _docker_start() {
  880. case "$cur" in
  881. -*)
  882. COMPREPLY=( $( compgen -W "--attach -a --help --interactive -i" -- "$cur" ) )
  883. ;;
  884. *)
  885. __docker_containers_stopped
  886. ;;
  887. esac
  888. }
  889. _docker_stats() {
  890. case "$cur" in
  891. -*)
  892. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  893. ;;
  894. *)
  895. __docker_containers_running
  896. ;;
  897. esac
  898. }
  899. _docker_stop() {
  900. case "$prev" in
  901. --time|-t)
  902. return
  903. ;;
  904. esac
  905. case "$cur" in
  906. -*)
  907. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  908. ;;
  909. *)
  910. __docker_containers_running
  911. ;;
  912. esac
  913. }
  914. _docker_tag() {
  915. case "$cur" in
  916. -*)
  917. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  918. ;;
  919. *)
  920. local counter=$(__docker_pos_first_nonflag)
  921. if [ $cword -eq $counter ]; then
  922. __docker_image_repos_and_tags
  923. return
  924. fi
  925. (( counter++ ))
  926. if [ $cword -eq $counter ]; then
  927. __docker_image_repos_and_tags
  928. return
  929. fi
  930. ;;
  931. esac
  932. }
  933. _docker_unpause() {
  934. case "$cur" in
  935. -*)
  936. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  937. ;;
  938. *)
  939. local counter=$(__docker_pos_first_nonflag)
  940. if [ $cword -eq $counter ]; then
  941. __docker_containers_unpauseable
  942. fi
  943. ;;
  944. esac
  945. }
  946. _docker_top() {
  947. case "$cur" in
  948. -*)
  949. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  950. ;;
  951. *)
  952. local counter=$(__docker_pos_first_nonflag)
  953. if [ $cword -eq $counter ]; then
  954. __docker_containers_running
  955. fi
  956. ;;
  957. esac
  958. }
  959. _docker_version() {
  960. case "$cur" in
  961. -*)
  962. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  963. ;;
  964. esac
  965. }
  966. _docker_wait() {
  967. case "$cur" in
  968. -*)
  969. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  970. ;;
  971. *)
  972. __docker_containers_all
  973. ;;
  974. esac
  975. }
  976. _docker() {
  977. local previous_extglob_setting=$(shopt -p extglob)
  978. shopt -s extglob
  979. local commands=(
  980. attach
  981. build
  982. commit
  983. cp
  984. create
  985. diff
  986. events
  987. exec
  988. export
  989. history
  990. images
  991. import
  992. info
  993. inspect
  994. kill
  995. load
  996. login
  997. logout
  998. logs
  999. pause
  1000. port
  1001. ps
  1002. pull
  1003. push
  1004. rename
  1005. restart
  1006. rm
  1007. rmi
  1008. run
  1009. save
  1010. search
  1011. start
  1012. stats
  1013. stop
  1014. tag
  1015. top
  1016. unpause
  1017. version
  1018. wait
  1019. )
  1020. local main_options_with_args="
  1021. --api-cors-header
  1022. --bip
  1023. --bridge -b
  1024. --default-ulimit
  1025. --dns
  1026. --dns-search
  1027. --exec-driver -e
  1028. --fixed-cidr
  1029. --fixed-cidr-v6
  1030. --graph -g
  1031. --group -G
  1032. --host -H
  1033. --insecure-registry
  1034. --ip
  1035. --label
  1036. --log-level -l
  1037. --mtu
  1038. --pidfile -p
  1039. --registry-mirror
  1040. --storage-driver -s
  1041. --storage-opt
  1042. --tlscacert
  1043. --tlscert
  1044. --tlskey
  1045. "
  1046. local main_options_with_args_glob=$(__docker_to_extglob "$main_options_with_args")
  1047. COMPREPLY=()
  1048. local cur prev words cword
  1049. _get_comp_words_by_ref -n : cur prev words cword
  1050. local command='docker' cpos=0
  1051. local counter=1
  1052. while [ $counter -lt $cword ]; do
  1053. case "${words[$counter]}" in
  1054. $main_options_with_args_glob )
  1055. (( counter++ ))
  1056. ;;
  1057. -*)
  1058. ;;
  1059. *)
  1060. command="${words[$counter]}"
  1061. cpos=$counter
  1062. (( cpos++ ))
  1063. break
  1064. ;;
  1065. esac
  1066. (( counter++ ))
  1067. done
  1068. local completions_func=_docker_${command}
  1069. declare -F $completions_func >/dev/null && $completions_func
  1070. eval "$previous_extglob_setting"
  1071. return 0
  1072. }
  1073. complete -F _docker docker