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