docker 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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. __docker_q() {
  24. docker 2>/dev/null "$@"
  25. }
  26. __docker_containers_all() {
  27. local IFS=$'\n'
  28. local containers=( $(__docker_q ps -aq --no-trunc) )
  29. if [ "$1" ]; then
  30. containers=( $(__docker_q inspect --format "{{if $1}}{{.Id}}{{end}}" "${containers[@]}") )
  31. fi
  32. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  33. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  34. unset IFS
  35. COMPREPLY=( $(compgen -W "${names[*]} ${containers[*]}" -- "$cur") )
  36. }
  37. __docker_containers_running() {
  38. __docker_containers_all '.State.Running'
  39. }
  40. __docker_containers_stopped() {
  41. __docker_containers_all 'not .State.Running'
  42. }
  43. __docker_containers_pauseable() {
  44. __docker_containers_all 'and .State.Running (not .State.Paused)'
  45. }
  46. __docker_containers_unpauseable() {
  47. __docker_containers_all '.State.Paused'
  48. }
  49. __docker_image_repos() {
  50. local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')"
  51. COMPREPLY=( $(compgen -W "$repos" -- "$cur") )
  52. }
  53. __docker_image_repos_and_tags() {
  54. local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')"
  55. COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") )
  56. __ltrim_colon_completions "$cur"
  57. }
  58. __docker_image_repos_and_tags_and_ids() {
  59. local images="$(__docker_q images -a --no-trunc | awk 'NR>1 { print $3; if ($1 != "<none>") { print $1; print $1":"$2 } }')"
  60. COMPREPLY=( $(compgen -W "$images" -- "$cur") )
  61. __ltrim_colon_completions "$cur"
  62. }
  63. __docker_containers_and_images() {
  64. __docker_containers_all
  65. local containers=( "${COMPREPLY[@]}" )
  66. __docker_image_repos_and_tags_and_ids
  67. COMPREPLY+=( "${containers[@]}" )
  68. }
  69. __docker_pos_first_nonflag() {
  70. local argument_flags=$1
  71. local counter=$cpos
  72. while [ $counter -le $cword ]; do
  73. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  74. (( counter++ ))
  75. else
  76. case "${words[$counter]}" in
  77. -*)
  78. ;;
  79. *)
  80. break
  81. ;;
  82. esac
  83. fi
  84. (( counter++ ))
  85. done
  86. echo $counter
  87. }
  88. __docker_resolve_hostname() {
  89. command -v host >/dev/null 2>&1 || return
  90. COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
  91. }
  92. __docker_capabilities() {
  93. # The list of capabilities is defined in types.go, ALL was added manually.
  94. COMPREPLY=( $( compgen -W "
  95. ALL
  96. AUDIT_CONTROL
  97. AUDIT_WRITE
  98. BLOCK_SUSPEND
  99. CHOWN
  100. DAC_OVERRIDE
  101. DAC_READ_SEARCH
  102. FOWNER
  103. FSETID
  104. IPC_LOCK
  105. IPC_OWNER
  106. KILL
  107. LEASE
  108. LINUX_IMMUTABLE
  109. MAC_ADMIN
  110. MAC_OVERRIDE
  111. MKNOD
  112. NET_ADMIN
  113. NET_BIND_SERVICE
  114. NET_BROADCAST
  115. NET_RAW
  116. SETFCAP
  117. SETGID
  118. SETPCAP
  119. SETUID
  120. SYS_ADMIN
  121. SYS_BOOT
  122. SYS_CHROOT
  123. SYSLOG
  124. SYS_MODULE
  125. SYS_NICE
  126. SYS_PACCT
  127. SYS_PTRACE
  128. SYS_RAWIO
  129. SYS_RESOURCE
  130. SYS_TIME
  131. SYS_TTY_CONFIG
  132. WAKE_ALARM
  133. " -- "$cur" ) )
  134. }
  135. _docker_docker() {
  136. case "$prev" in
  137. -H)
  138. return
  139. ;;
  140. esac
  141. case "$cur" in
  142. -*)
  143. COMPREPLY=( $( compgen -W "-H" -- "$cur" ) )
  144. ;;
  145. *)
  146. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  147. ;;
  148. esac
  149. }
  150. _docker_attach() {
  151. case "$cur" in
  152. -*)
  153. COMPREPLY=( $( compgen -W "--no-stdin --sig-proxy" -- "$cur" ) )
  154. ;;
  155. *)
  156. local counter="$(__docker_pos_first_nonflag)"
  157. if [ $cword -eq $counter ]; then
  158. __docker_containers_running
  159. fi
  160. ;;
  161. esac
  162. }
  163. _docker_build() {
  164. case "$prev" in
  165. -t|--tag)
  166. __docker_image_repos_and_tags
  167. return
  168. ;;
  169. esac
  170. case "$cur" in
  171. -*)
  172. COMPREPLY=( $( compgen -W "-t --tag -q --quiet --no-cache --rm --force-rm" -- "$cur" ) )
  173. ;;
  174. *)
  175. local counter="$(__docker_pos_first_nonflag '-t|--tag')"
  176. if [ $cword -eq $counter ]; then
  177. _filedir -d
  178. fi
  179. ;;
  180. esac
  181. }
  182. _docker_commit() {
  183. case "$prev" in
  184. -m|--message|-a|--author|--run)
  185. return
  186. ;;
  187. esac
  188. case "$cur" in
  189. -*)
  190. COMPREPLY=( $( compgen -W "-m --message -a --author --run" -- "$cur" ) )
  191. ;;
  192. *)
  193. local counter=$(__docker_pos_first_nonflag '-m|--message|-a|--author|--run')
  194. if [ $cword -eq $counter ]; then
  195. __docker_containers_all
  196. return
  197. fi
  198. (( counter++ ))
  199. if [ $cword -eq $counter ]; then
  200. __docker_image_repos_and_tags
  201. return
  202. fi
  203. ;;
  204. esac
  205. }
  206. _docker_cp() {
  207. local counter=$(__docker_pos_first_nonflag)
  208. if [ $cword -eq $counter ]; then
  209. case "$cur" in
  210. *:)
  211. return
  212. ;;
  213. *)
  214. __docker_containers_all
  215. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  216. compopt -o nospace
  217. return
  218. ;;
  219. esac
  220. fi
  221. (( counter++ ))
  222. if [ $cword -eq $counter ]; then
  223. _filedir
  224. return
  225. fi
  226. }
  227. _docker_create() {
  228. case "$prev" in
  229. -a|--attach)
  230. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  231. return
  232. ;;
  233. --cidfile|--env-file)
  234. _filedir
  235. return
  236. ;;
  237. --volumes-from)
  238. __docker_containers_all
  239. return
  240. ;;
  241. -v|--volume|--device)
  242. case "$cur" in
  243. *:*)
  244. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  245. ;;
  246. '')
  247. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  248. compopt -o nospace
  249. ;;
  250. /*)
  251. _filedir
  252. compopt -o nospace
  253. ;;
  254. esac
  255. return
  256. ;;
  257. -e|--env)
  258. COMPREPLY=( $( compgen -e -- "$cur" ) )
  259. compopt -o nospace
  260. return
  261. ;;
  262. --link)
  263. case "$cur" in
  264. *:*)
  265. ;;
  266. *)
  267. __docker_containers_running
  268. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  269. compopt -o nospace
  270. ;;
  271. esac
  272. return
  273. ;;
  274. --add-host)
  275. case "$cur" in
  276. *:)
  277. __docker_resolve_hostname
  278. return
  279. ;;
  280. esac
  281. ;;
  282. --cap-add|--cap-drop)
  283. __docker_capabilities
  284. return
  285. ;;
  286. --net)
  287. case "$cur" in
  288. container:*)
  289. local cur=${cur#*:}
  290. __docker_containers_all
  291. ;;
  292. *)
  293. COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") )
  294. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  295. compopt -o nospace
  296. fi
  297. ;;
  298. esac
  299. return
  300. ;;
  301. --restart)
  302. case "$cur" in
  303. on-failure:*)
  304. ;;
  305. *)
  306. COMPREPLY=( $( compgen -W "no on-failure on-failure: always" -- "$cur") )
  307. ;;
  308. esac
  309. return
  310. ;;
  311. --security-opt)
  312. case "$cur" in
  313. label:*:*)
  314. ;;
  315. label:*)
  316. local cur=${cur##*:}
  317. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") )
  318. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  319. compopt -o nospace
  320. fi
  321. ;;
  322. *)
  323. COMPREPLY=( $( compgen -W "label apparmor" -S ":" -- "$cur") )
  324. compopt -o nospace
  325. ;;
  326. esac
  327. return
  328. ;;
  329. --entrypoint|-h|--hostname|-m|--memory|-u|--user|-w|--workdir|--cpuset|-c|--cpu-shares|-n|--name|-p|--publish|--expose|--dns|--lxc-conf|--dns-search)
  330. return
  331. ;;
  332. esac
  333. case "$cur" in
  334. -*)
  335. COMPREPLY=( $( compgen -W "--privileged -P --publish-all -i --interactive -t --tty --cidfile --entrypoint -h --hostname -m --memory -u --user -w --workdir --cpuset -c --cpu-shares --name -a --attach -v --volume --link -e --env --env-file -p --publish --expose --dns --volumes-from --lxc-conf --security-opt --add-host --cap-add --cap-drop --device --dns-search --net --restart" -- "$cur" ) )
  336. ;;
  337. *)
  338. local counter=$(__docker_pos_first_nonflag '--cidfile|--volumes-from|-v|--volume|-e|--env|--env-file|--entrypoint|-h|--hostname|-m|--memory|-u|--user|-w|--workdir|--cpuset|-c|--cpu-shares|-n|--name|-a|--attach|--link|-p|--publish|--expose|--dns|--lxc-conf|--security-opt|--add-host|--cap-add|--cap-drop|--device|--dns-search|--net|--restart')
  339. if [ $cword -eq $counter ]; then
  340. __docker_image_repos_and_tags_and_ids
  341. fi
  342. ;;
  343. esac
  344. }
  345. _docker_diff() {
  346. local counter=$(__docker_pos_first_nonflag)
  347. if [ $cword -eq $counter ]; then
  348. __docker_containers_all
  349. fi
  350. }
  351. _docker_events() {
  352. case "$prev" in
  353. --since)
  354. return
  355. ;;
  356. esac
  357. case "$cur" in
  358. -*)
  359. COMPREPLY=( $( compgen -W "--since" -- "$cur" ) )
  360. ;;
  361. esac
  362. }
  363. _docker_exec() {
  364. case "$cur" in
  365. -*)
  366. COMPREPLY=( $( compgen -W "-d --detach -i --interactive -t --tty" -- "$cur" ) )
  367. ;;
  368. *)
  369. __docker_containers_running
  370. ;;
  371. esac
  372. }
  373. _docker_export() {
  374. local counter=$(__docker_pos_first_nonflag)
  375. if [ $cword -eq $counter ]; then
  376. __docker_containers_all
  377. fi
  378. }
  379. _docker_help() {
  380. local counter=$(__docker_pos_first_nonflag)
  381. if [ $cword -eq $counter ]; then
  382. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  383. fi
  384. }
  385. _docker_history() {
  386. case "$cur" in
  387. -*)
  388. COMPREPLY=( $( compgen -W "-q --quiet --no-trunc" -- "$cur" ) )
  389. ;;
  390. *)
  391. local counter=$(__docker_pos_first_nonflag)
  392. if [ $cword -eq $counter ]; then
  393. __docker_image_repos_and_tags_and_ids
  394. fi
  395. ;;
  396. esac
  397. }
  398. _docker_images() {
  399. case "$cur" in
  400. -*)
  401. COMPREPLY=( $( compgen -W "-q --quiet -a --all --no-trunc -v --viz -t --tree" -- "$cur" ) )
  402. ;;
  403. *)
  404. local counter=$(__docker_pos_first_nonflag)
  405. if [ $cword -eq $counter ]; then
  406. __docker_image_repos
  407. fi
  408. ;;
  409. esac
  410. }
  411. _docker_import() {
  412. local counter=$(__docker_pos_first_nonflag)
  413. if [ $cword -eq $counter ]; then
  414. return
  415. fi
  416. (( counter++ ))
  417. if [ $cword -eq $counter ]; then
  418. __docker_image_repos_and_tags
  419. return
  420. fi
  421. }
  422. _docker_info() {
  423. return
  424. }
  425. _docker_inspect() {
  426. case "$prev" in
  427. -f|--format)
  428. return
  429. ;;
  430. esac
  431. case "$cur" in
  432. -*)
  433. COMPREPLY=( $( compgen -W "-f --format" -- "$cur" ) )
  434. ;;
  435. *)
  436. __docker_containers_and_images
  437. ;;
  438. esac
  439. }
  440. _docker_kill() {
  441. __docker_containers_running
  442. }
  443. _docker_load() {
  444. return
  445. }
  446. _docker_login() {
  447. case "$prev" in
  448. -u|--username|-p|--password|-e|--email)
  449. return
  450. ;;
  451. esac
  452. case "$cur" in
  453. -*)
  454. COMPREPLY=( $( compgen -W "-u --username -p --password -e --email" -- "$cur" ) )
  455. ;;
  456. esac
  457. }
  458. _docker_logs() {
  459. case "$cur" in
  460. -*)
  461. COMPREPLY=( $( compgen -W "-f --follow" -- "$cur" ) )
  462. ;;
  463. *)
  464. local counter=$(__docker_pos_first_nonflag)
  465. if [ $cword -eq $counter ]; then
  466. __docker_containers_all
  467. fi
  468. ;;
  469. esac
  470. }
  471. _docker_pause() {
  472. local counter=$(__docker_pos_first_nonflag)
  473. if [ $cword -eq $counter ]; then
  474. __docker_containers_pauseable
  475. fi
  476. }
  477. _docker_port() {
  478. local counter=$(__docker_pos_first_nonflag)
  479. if [ $cword -eq $counter ]; then
  480. __docker_containers_all
  481. fi
  482. }
  483. _docker_ps() {
  484. case "$prev" in
  485. --since|--before)
  486. __docker_containers_all
  487. ;;
  488. -n)
  489. return
  490. ;;
  491. esac
  492. case "$cur" in
  493. -*)
  494. COMPREPLY=( $( compgen -W "-q --quiet -s --size -a --all --no-trunc -l --latest --since --before -n" -- "$cur" ) )
  495. ;;
  496. esac
  497. }
  498. _docker_pull() {
  499. case "$prev" in
  500. -t|--tag)
  501. return
  502. ;;
  503. esac
  504. case "$cur" in
  505. -*)
  506. COMPREPLY=( $( compgen -W "-t --tag" -- "$cur" ) )
  507. ;;
  508. *)
  509. local counter=$(__docker_pos_first_nonflag '-t|--tag')
  510. if [ $cword -eq $counter ]; then
  511. __docker_image_repos_and_tags
  512. fi
  513. ;;
  514. esac
  515. }
  516. _docker_push() {
  517. local counter=$(__docker_pos_first_nonflag)
  518. if [ $cword -eq $counter ]; then
  519. __docker_image_repos_and_tags
  520. fi
  521. }
  522. _docker_restart() {
  523. case "$prev" in
  524. -t|--time)
  525. return
  526. ;;
  527. esac
  528. case "$cur" in
  529. -*)
  530. COMPREPLY=( $( compgen -W "-t --time" -- "$cur" ) )
  531. ;;
  532. *)
  533. __docker_containers_all
  534. ;;
  535. esac
  536. }
  537. _docker_rm() {
  538. case "$cur" in
  539. -*)
  540. COMPREPLY=( $( compgen -W "-f --force -l --link -v --volumes" -- "$cur" ) )
  541. return
  542. ;;
  543. *)
  544. for arg in "${COMP_WORDS[@]}"; do
  545. case "$arg" in
  546. -f|--force)
  547. __docker_containers_all
  548. return
  549. ;;
  550. esac
  551. done
  552. __docker_containers_stopped
  553. return
  554. ;;
  555. esac
  556. }
  557. _docker_rmi() {
  558. __docker_image_repos_and_tags_and_ids
  559. }
  560. _docker_run() {
  561. case "$prev" in
  562. -a|--attach)
  563. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  564. return
  565. ;;
  566. --cidfile|--env-file)
  567. _filedir
  568. return
  569. ;;
  570. --volumes-from)
  571. __docker_containers_all
  572. return
  573. ;;
  574. -v|--volume|--device)
  575. case "$cur" in
  576. *:*)
  577. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  578. ;;
  579. '')
  580. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  581. compopt -o nospace
  582. ;;
  583. /*)
  584. _filedir
  585. compopt -o nospace
  586. ;;
  587. esac
  588. return
  589. ;;
  590. -e|--env)
  591. COMPREPLY=( $( compgen -e -- "$cur" ) )
  592. compopt -o nospace
  593. return
  594. ;;
  595. --link)
  596. case "$cur" in
  597. *:*)
  598. ;;
  599. *)
  600. __docker_containers_running
  601. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  602. compopt -o nospace
  603. ;;
  604. esac
  605. return
  606. ;;
  607. --add-host)
  608. case "$cur" in
  609. *:)
  610. __docker_resolve_hostname
  611. return
  612. ;;
  613. esac
  614. ;;
  615. --cap-add|--cap-drop)
  616. __docker_capabilities
  617. return
  618. ;;
  619. --net)
  620. case "$cur" in
  621. container:*)
  622. local cur=${cur#*:}
  623. __docker_containers_all
  624. ;;
  625. *)
  626. COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") )
  627. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  628. compopt -o nospace
  629. fi
  630. ;;
  631. esac
  632. return
  633. ;;
  634. --restart)
  635. case "$cur" in
  636. on-failure:*)
  637. ;;
  638. *)
  639. COMPREPLY=( $( compgen -W "no on-failure on-failure: always" -- "$cur") )
  640. ;;
  641. esac
  642. return
  643. ;;
  644. --security-opt)
  645. case "$cur" in
  646. label:*:*)
  647. ;;
  648. label:*)
  649. local cur=${cur##*:}
  650. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") )
  651. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  652. compopt -o nospace
  653. fi
  654. ;;
  655. *)
  656. COMPREPLY=( $( compgen -W "label apparmor" -S ":" -- "$cur") )
  657. compopt -o nospace
  658. ;;
  659. esac
  660. return
  661. ;;
  662. --entrypoint|-h|--hostname|-m|--memory|-u|--user|-w|--workdir|--cpuset|-c|--cpu-shares|-n|--name|-p|--publish|--expose|--dns|--lxc-conf|--dns-search)
  663. return
  664. ;;
  665. esac
  666. case "$cur" in
  667. -*)
  668. COMPREPLY=( $( compgen -W "--rm -d --detach --privileged -P --publish-all -i --interactive -t --tty --cidfile --entrypoint -h --hostname -m --memory -u --user -w --workdir --cpuset -c --cpu-shares --sig-proxy --name -a --attach -v --volume --link -e --env --env-file -p --publish --expose --dns --volumes-from --lxc-conf --security-opt --add-host --cap-add --cap-drop --device --dns-search --net --restart" -- "$cur" ) )
  669. ;;
  670. *)
  671. local counter=$(__docker_pos_first_nonflag '--cidfile|--volumes-from|-v|--volume|-e|--env|--env-file|--entrypoint|-h|--hostname|-m|--memory|-u|--user|-w|--workdir|--cpuset|-c|--cpu-shares|-n|--name|-a|--attach|--link|-p|--publish|--expose|--dns|--lxc-conf|--security-opt|--add-host|--cap-add|--cap-drop|--device|--dns-search|--net|--restart')
  672. if [ $cword -eq $counter ]; then
  673. __docker_image_repos_and_tags_and_ids
  674. fi
  675. ;;
  676. esac
  677. }
  678. _docker_save() {
  679. local counter=$(__docker_pos_first_nonflag)
  680. if [ $cword -eq $counter ]; then
  681. __docker_image_repos_and_tags_and_ids
  682. fi
  683. }
  684. _docker_search() {
  685. case "$prev" in
  686. -s|--stars)
  687. return
  688. ;;
  689. esac
  690. case "$cur" in
  691. -*)
  692. COMPREPLY=( $( compgen -W "--no-trunc --automated -s --stars" -- "$cur" ) )
  693. ;;
  694. esac
  695. }
  696. _docker_start() {
  697. case "$cur" in
  698. -*)
  699. COMPREPLY=( $( compgen -W "-a --attach -i --interactive" -- "$cur" ) )
  700. ;;
  701. *)
  702. __docker_containers_stopped
  703. ;;
  704. esac
  705. }
  706. _docker_stop() {
  707. case "$prev" in
  708. -t|--time)
  709. return
  710. ;;
  711. esac
  712. case "$cur" in
  713. -*)
  714. COMPREPLY=( $( compgen -W "-t --time" -- "$cur" ) )
  715. ;;
  716. *)
  717. __docker_containers_running
  718. ;;
  719. esac
  720. }
  721. _docker_tag() {
  722. case "$cur" in
  723. -*)
  724. COMPREPLY=( $( compgen -W "-f --force" -- "$cur" ) )
  725. ;;
  726. *)
  727. local counter=$(__docker_pos_first_nonflag)
  728. if [ $cword -eq $counter ]; then
  729. __docker_image_repos_and_tags
  730. return
  731. fi
  732. (( counter++ ))
  733. if [ $cword -eq $counter ]; then
  734. __docker_image_repos_and_tags
  735. return
  736. fi
  737. ;;
  738. esac
  739. }
  740. _docker_unpause() {
  741. local counter=$(__docker_pos_first_nonflag)
  742. if [ $cword -eq $counter ]; then
  743. __docker_containers_unpauseable
  744. fi
  745. }
  746. _docker_top() {
  747. local counter=$(__docker_pos_first_nonflag)
  748. if [ $cword -eq $counter ]; then
  749. __docker_containers_running
  750. fi
  751. }
  752. _docker_version() {
  753. return
  754. }
  755. _docker_wait() {
  756. __docker_containers_all
  757. }
  758. _docker() {
  759. local commands=(
  760. attach
  761. build
  762. commit
  763. cp
  764. create
  765. diff
  766. events
  767. exec
  768. export
  769. history
  770. images
  771. import
  772. info
  773. insert
  774. inspect
  775. kill
  776. load
  777. login
  778. logs
  779. pause
  780. port
  781. ps
  782. pull
  783. push
  784. restart
  785. rm
  786. rmi
  787. run
  788. save
  789. search
  790. start
  791. stop
  792. tag
  793. top
  794. unpause
  795. version
  796. wait
  797. )
  798. COMPREPLY=()
  799. local cur prev words cword
  800. _get_comp_words_by_ref -n : cur prev words cword
  801. local command='docker' cpos=0
  802. local counter=1
  803. while [ $counter -lt $cword ]; do
  804. case "${words[$counter]}" in
  805. -H)
  806. (( counter++ ))
  807. ;;
  808. -*)
  809. ;;
  810. *)
  811. command="${words[$counter]}"
  812. cpos=$counter
  813. (( cpos++ ))
  814. break
  815. ;;
  816. esac
  817. (( counter++ ))
  818. done
  819. local completions_func=_docker_${command}
  820. declare -F $completions_func >/dev/null && $completions_func
  821. return 0
  822. }
  823. complete -F _docker docker