github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/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 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 --version -v 216 " 217 218 case "$prev" in 219 --graph|-g) 220 _filedir -d 221 return 222 ;; 223 --log-driver) 224 COMPREPLY=( $( compgen -W "json-file syslog none" -- "$cur" ) ) 225 return 226 ;; 227 --log-level|-l) 228 COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) ) 229 return 230 ;; 231 --pidfile|-p|--tlscacert|--tlscert|--tlskey) 232 _filedir 233 return 234 ;; 235 --storage-driver|-s) 236 COMPREPLY=( $( compgen -W "aufs devicemapper btrfs overlay" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) ) 237 return 238 ;; 239 $main_options_with_args_glob ) 240 return 241 ;; 242 esac 243 244 case "$cur" in 245 -*) 246 COMPREPLY=( $( compgen -W "$boolean_options $main_options_with_args" -- "$cur" ) ) 247 ;; 248 *) 249 COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) ) 250 ;; 251 esac 252 } 253 254 _docker_attach() { 255 case "$cur" in 256 -*) 257 COMPREPLY=( $( compgen -W "--help --no-stdin --sig-proxy" -- "$cur" ) ) 258 ;; 259 *) 260 local counter="$(__docker_pos_first_nonflag)" 261 if [ $cword -eq $counter ]; then 262 __docker_containers_running 263 fi 264 ;; 265 esac 266 } 267 268 _docker_build() { 269 case "$prev" in 270 --tag|-t) 271 __docker_image_repos_and_tags 272 return 273 ;; 274 --file|-f) 275 _filedir 276 return 277 ;; 278 esac 279 280 case "$cur" in 281 -*) 282 COMPREPLY=( $( compgen -W "--cpu-shares -c --cpuset-cpus --cpu-quota --file -f --force-rm --help --memory -m --memory-swap --no-cache --pull --quiet -q --rm --tag -t" -- "$cur" ) ) 283 ;; 284 *) 285 local counter="$(__docker_pos_first_nonflag '--tag|-t')" 286 if [ $cword -eq $counter ]; then 287 _filedir -d 288 fi 289 ;; 290 esac 291 } 292 293 _docker_commit() { 294 case "$prev" in 295 --author|-a|--change|-c|--message|-m) 296 return 297 ;; 298 esac 299 300 case "$cur" in 301 -*) 302 COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause -p" -- "$cur" ) ) 303 ;; 304 *) 305 local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m') 306 307 if [ $cword -eq $counter ]; then 308 __docker_containers_all 309 return 310 fi 311 (( counter++ )) 312 313 if [ $cword -eq $counter ]; then 314 __docker_image_repos_and_tags 315 return 316 fi 317 ;; 318 esac 319 } 320 321 _docker_cp() { 322 case "$cur" in 323 -*) 324 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 325 ;; 326 *) 327 local counter=$(__docker_pos_first_nonflag) 328 if [ $cword -eq $counter ]; then 329 case "$cur" in 330 *:) 331 return 332 ;; 333 *) 334 __docker_containers_all 335 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 336 compopt -o nospace 337 return 338 ;; 339 esac 340 fi 341 (( counter++ )) 342 343 if [ $cword -eq $counter ]; then 344 _filedir -d 345 return 346 fi 347 ;; 348 esac 349 } 350 351 _docker_create() { 352 _docker_run 353 } 354 355 _docker_diff() { 356 case "$cur" in 357 -*) 358 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 359 ;; 360 *) 361 local counter=$(__docker_pos_first_nonflag) 362 if [ $cword -eq $counter ]; then 363 __docker_containers_all 364 fi 365 ;; 366 esac 367 } 368 369 _docker_events() { 370 case "$prev" in 371 --filter|-f) 372 COMPREPLY=( $( compgen -S = -W "container event image" -- "$cur" ) ) 373 compopt -o nospace 374 return 375 ;; 376 --since|--until) 377 return 378 ;; 379 esac 380 381 # "=" gets parsed to a word and assigned to either $cur or $prev depending on whether 382 # it is the last character or not. So we search for "xxx=" in the the last two words. 383 case "${words[$cword-2]}$prev=" in 384 *container=*) 385 cur="${cur#=}" 386 __docker_containers_all 387 return 388 ;; 389 *event=*) 390 COMPREPLY=( $( compgen -W "create destroy die export kill pause restart start stop unpause" -- "${cur#=}" ) ) 391 return 392 ;; 393 *image=*) 394 cur="${cur#=}" 395 __docker_image_repos_and_tags_and_ids 396 return 397 ;; 398 esac 399 400 case "$cur" in 401 -*) 402 COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) ) 403 ;; 404 esac 405 } 406 407 _docker_exec() { 408 case "$cur" in 409 -*) 410 COMPREPLY=( $( compgen -W "--detach -d --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) ) 411 ;; 412 *) 413 __docker_containers_running 414 ;; 415 esac 416 } 417 418 _docker_export() { 419 case "$cur" in 420 -*) 421 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 422 ;; 423 *) 424 local counter=$(__docker_pos_first_nonflag) 425 if [ $cword -eq $counter ]; then 426 __docker_containers_all 427 fi 428 ;; 429 esac 430 } 431 432 _docker_help() { 433 local counter=$(__docker_pos_first_nonflag) 434 if [ $cword -eq $counter ]; then 435 COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) ) 436 fi 437 } 438 439 _docker_history() { 440 case "$cur" in 441 -*) 442 COMPREPLY=( $( compgen -W "--help --no-trunc --quiet -q" -- "$cur" ) ) 443 ;; 444 *) 445 local counter=$(__docker_pos_first_nonflag) 446 if [ $cword -eq $counter ]; then 447 __docker_image_repos_and_tags_and_ids 448 fi 449 ;; 450 esac 451 } 452 453 _docker_images() { 454 case "$prev" in 455 --filter|-f) 456 COMPREPLY=( $( compgen -W "dangling=true label=" -- "$cur" ) ) 457 if [ "$COMPREPLY" = "label=" ]; then 458 compopt -o nospace 459 fi 460 return 461 ;; 462 esac 463 464 case "${words[$cword-2]}$prev=" in 465 *dangling=*) 466 COMPREPLY=( $( compgen -W "true false" -- "${cur#=}" ) ) 467 return 468 ;; 469 *label=*) 470 return 471 ;; 472 esac 473 474 case "$cur" in 475 -*) 476 COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --help --no-trunc --quiet -q" -- "$cur" ) ) 477 ;; 478 =) 479 return 480 ;; 481 *) 482 __docker_image_repos 483 ;; 484 esac 485 } 486 487 _docker_import() { 488 case "$cur" in 489 -*) 490 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 491 ;; 492 *) 493 local counter=$(__docker_pos_first_nonflag) 494 if [ $cword -eq $counter ]; then 495 return 496 fi 497 (( counter++ )) 498 499 if [ $cword -eq $counter ]; then 500 __docker_image_repos_and_tags 501 return 502 fi 503 ;; 504 esac 505 } 506 507 _docker_info() { 508 case "$cur" in 509 -*) 510 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 511 ;; 512 esac 513 } 514 515 _docker_inspect() { 516 case "$prev" in 517 --format|-f) 518 return 519 ;; 520 esac 521 522 case "$cur" in 523 -*) 524 COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) 525 ;; 526 *) 527 __docker_containers_and_images 528 ;; 529 esac 530 } 531 532 _docker_kill() { 533 case "$prev" in 534 --signal|-s) 535 __docker_signals 536 return 537 ;; 538 esac 539 540 case "$cur" in 541 -*) 542 COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) ) 543 ;; 544 *) 545 __docker_containers_running 546 ;; 547 esac 548 } 549 550 _docker_load() { 551 case "$prev" in 552 --input|-i) 553 _filedir 554 return 555 ;; 556 esac 557 558 case "$cur" in 559 -*) 560 COMPREPLY=( $( compgen -W "--help --input -i" -- "$cur" ) ) 561 ;; 562 esac 563 } 564 565 _docker_login() { 566 case "$prev" in 567 --email|-e|--password|-p|--username|-u) 568 return 569 ;; 570 esac 571 572 case "$cur" in 573 -*) 574 COMPREPLY=( $( compgen -W "--email -e --help --password -p --username -u" -- "$cur" ) ) 575 ;; 576 esac 577 } 578 579 _docker_logout() { 580 case "$cur" in 581 -*) 582 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 583 ;; 584 esac 585 } 586 587 _docker_logs() { 588 case "$prev" in 589 --tail) 590 return 591 ;; 592 esac 593 594 case "$cur" in 595 -*) 596 COMPREPLY=( $( compgen -W "--follow -f --help --tail --timestamps -t" -- "$cur" ) ) 597 ;; 598 *) 599 local counter=$(__docker_pos_first_nonflag '--tail') 600 if [ $cword -eq $counter ]; then 601 __docker_containers_all 602 fi 603 ;; 604 esac 605 } 606 607 _docker_pause() { 608 case "$cur" in 609 -*) 610 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 611 ;; 612 *) 613 local counter=$(__docker_pos_first_nonflag) 614 if [ $cword -eq $counter ]; then 615 __docker_containers_pauseable 616 fi 617 ;; 618 esac 619 } 620 621 _docker_port() { 622 case "$cur" in 623 -*) 624 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 625 ;; 626 *) 627 local counter=$(__docker_pos_first_nonflag) 628 if [ $cword -eq $counter ]; then 629 __docker_containers_all 630 fi 631 ;; 632 esac 633 } 634 635 _docker_ps() { 636 case "$prev" in 637 --before|--since) 638 __docker_containers_all 639 ;; 640 --filter|-f) 641 COMPREPLY=( $( compgen -S = -W "exited id label name status" -- "$cur" ) ) 642 compopt -o nospace 643 return 644 ;; 645 -n) 646 return 647 ;; 648 esac 649 650 case "${words[$cword-2]}$prev=" in 651 *id=*) 652 cur="${cur#=}" 653 __docker_container_ids 654 return 655 ;; 656 *name=*) 657 cur="${cur#=}" 658 __docker_container_names 659 return 660 ;; 661 *status=*) 662 COMPREPLY=( $( compgen -W "exited paused restarting running" -- "${cur#=}" ) ) 663 return 664 ;; 665 esac 666 667 case "$cur" in 668 -*) 669 COMPREPLY=( $( compgen -W "--all -a --before --filter -f --help --latest -l -n --no-trunc --quiet -q --size -s --since" -- "$cur" ) ) 670 ;; 671 esac 672 } 673 674 _docker_pull() { 675 case "$cur" in 676 -*) 677 COMPREPLY=( $( compgen -W "--all-tags -a --help" -- "$cur" ) ) 678 ;; 679 *) 680 local counter=$(__docker_pos_first_nonflag) 681 if [ $cword -eq $counter ]; then 682 __docker_image_repos_and_tags 683 fi 684 ;; 685 esac 686 } 687 688 _docker_push() { 689 case "$cur" in 690 -*) 691 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 692 ;; 693 *) 694 local counter=$(__docker_pos_first_nonflag) 695 if [ $cword -eq $counter ]; then 696 __docker_image_repos_and_tags 697 fi 698 ;; 699 esac 700 } 701 702 _docker_rename() { 703 case "$cur" in 704 -*) 705 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 706 ;; 707 *) 708 local counter=$(__docker_pos_first_nonflag) 709 if [ $cword -eq $counter ]; then 710 __docker_containers_all 711 fi 712 ;; 713 esac 714 } 715 716 _docker_restart() { 717 case "$prev" in 718 --time|-t) 719 return 720 ;; 721 esac 722 723 case "$cur" in 724 -*) 725 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 726 ;; 727 *) 728 __docker_containers_all 729 ;; 730 esac 731 } 732 733 _docker_rm() { 734 case "$cur" in 735 -*) 736 COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) ) 737 ;; 738 *) 739 for arg in "${COMP_WORDS[@]}"; do 740 case "$arg" in 741 --force|-f) 742 __docker_containers_all 743 return 744 ;; 745 esac 746 done 747 __docker_containers_stopped 748 ;; 749 esac 750 } 751 752 _docker_rmi() { 753 case "$cur" in 754 -*) 755 COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) ) 756 ;; 757 *) 758 __docker_image_repos_and_tags_and_ids 759 ;; 760 esac 761 } 762 763 _docker_run() { 764 local options_with_args=" 765 --add-host 766 --attach -a 767 --cap-add 768 --cap-drop 769 --cgroup-parent 770 --cidfile 771 --cpuset 772 --cpu-shares -c 773 --cpu-quota 774 --device 775 --dns 776 --dns-search 777 --entrypoint 778 --env -e 779 --env-file 780 --expose 781 --hostname -h 782 --ipc 783 --label -l 784 --label-file 785 --link 786 --log-driver 787 --lxc-conf 788 --mac-address 789 --memory -m 790 --memory-swap 791 --name 792 --net 793 --pid 794 --publish -p 795 --restart 796 --security-opt 797 --user -u 798 --ulimit 799 --volumes-from 800 --volume -v 801 --workdir -w 802 " 803 804 local all_options="$options_with_args 805 --help 806 --interactive -i 807 --privileged 808 --publish-all -P 809 --read-only 810 --tty -t 811 " 812 813 [ "$command" = "run" ] && all_options="$all_options 814 --detach -d 815 --rm 816 --sig-proxy 817 " 818 819 local options_with_args_glob=$(__docker_to_extglob "$options_with_args") 820 821 case "$prev" in 822 --add-host) 823 case "$cur" in 824 *:) 825 __docker_resolve_hostname 826 return 827 ;; 828 esac 829 ;; 830 --attach|-a) 831 COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) ) 832 return 833 ;; 834 --cap-add|--cap-drop) 835 __docker_capabilities 836 return 837 ;; 838 --cidfile|--env-file|--label-file) 839 _filedir 840 return 841 ;; 842 --device|--volume|-v) 843 case "$cur" in 844 *:*) 845 # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) 846 ;; 847 '') 848 COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) 849 compopt -o nospace 850 ;; 851 /*) 852 _filedir 853 compopt -o nospace 854 ;; 855 esac 856 return 857 ;; 858 --env|-e) 859 COMPREPLY=( $( compgen -e -- "$cur" ) ) 860 compopt -o nospace 861 return 862 ;; 863 --ipc) 864 case "$cur" in 865 *:*) 866 cur="${cur#*:}" 867 __docker_containers_running 868 ;; 869 *) 870 COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) ) 871 if [ "$COMPREPLY" = "container:" ]; then 872 compopt -o nospace 873 fi 874 ;; 875 esac 876 return 877 ;; 878 --link) 879 case "$cur" in 880 *:*) 881 ;; 882 *) 883 __docker_containers_running 884 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 885 compopt -o nospace 886 ;; 887 esac 888 return 889 ;; 890 --log-driver) 891 COMPREPLY=( $( compgen -W "json-file syslog none" -- "$cur") ) 892 return 893 ;; 894 --net) 895 case "$cur" in 896 container:*) 897 local cur=${cur#*:} 898 __docker_containers_all 899 ;; 900 *) 901 COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") ) 902 if [ "${COMPREPLY[*]}" = "container:" ] ; then 903 compopt -o nospace 904 fi 905 ;; 906 esac 907 return 908 ;; 909 --restart) 910 case "$cur" in 911 on-failure:*) 912 ;; 913 *) 914 COMPREPLY=( $( compgen -W "no on-failure on-failure: always" -- "$cur") ) 915 ;; 916 esac 917 return 918 ;; 919 --security-opt) 920 case "$cur" in 921 label:*:*) 922 ;; 923 label:*) 924 local cur=${cur##*:} 925 COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") ) 926 if [ "${COMPREPLY[*]}" != "disable" ] ; then 927 compopt -o nospace 928 fi 929 ;; 930 *) 931 COMPREPLY=( $( compgen -W "label apparmor" -S ":" -- "$cur") ) 932 compopt -o nospace 933 ;; 934 esac 935 return 936 ;; 937 --volumes-from) 938 __docker_containers_all 939 return 940 ;; 941 $options_with_args_glob ) 942 return 943 ;; 944 esac 945 946 case "$cur" in 947 -*) 948 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 949 ;; 950 *) 951 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 952 953 if [ $cword -eq $counter ]; then 954 __docker_image_repos_and_tags_and_ids 955 fi 956 ;; 957 esac 958 } 959 960 _docker_save() { 961 case "$prev" in 962 --output|-o) 963 _filedir 964 return 965 ;; 966 esac 967 968 case "$cur" in 969 -*) 970 COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) ) 971 ;; 972 *) 973 __docker_image_repos_and_tags_and_ids 974 ;; 975 esac 976 } 977 978 _docker_search() { 979 case "$prev" in 980 --stars|-s) 981 return 982 ;; 983 esac 984 985 case "$cur" in 986 -*) 987 COMPREPLY=( $( compgen -W "--automated --help --no-trunc --stars -s" -- "$cur" ) ) 988 ;; 989 esac 990 } 991 992 _docker_start() { 993 case "$cur" in 994 -*) 995 COMPREPLY=( $( compgen -W "--attach -a --help --interactive -i" -- "$cur" ) ) 996 ;; 997 *) 998 __docker_containers_stopped 999 ;; 1000 esac 1001 } 1002 1003 _docker_stats() { 1004 case "$cur" in 1005 -*) 1006 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1007 ;; 1008 *) 1009 __docker_containers_running 1010 ;; 1011 esac 1012 } 1013 1014 _docker_stop() { 1015 case "$prev" in 1016 --time|-t) 1017 return 1018 ;; 1019 esac 1020 1021 case "$cur" in 1022 -*) 1023 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 1024 ;; 1025 *) 1026 __docker_containers_running 1027 ;; 1028 esac 1029 } 1030 1031 _docker_tag() { 1032 case "$cur" in 1033 -*) 1034 COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) 1035 ;; 1036 *) 1037 local counter=$(__docker_pos_first_nonflag) 1038 1039 if [ $cword -eq $counter ]; then 1040 __docker_image_repos_and_tags 1041 return 1042 fi 1043 (( counter++ )) 1044 1045 if [ $cword -eq $counter ]; then 1046 __docker_image_repos_and_tags 1047 return 1048 fi 1049 ;; 1050 esac 1051 } 1052 1053 _docker_unpause() { 1054 case "$cur" in 1055 -*) 1056 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1057 ;; 1058 *) 1059 local counter=$(__docker_pos_first_nonflag) 1060 if [ $cword -eq $counter ]; then 1061 __docker_containers_unpauseable 1062 fi 1063 ;; 1064 esac 1065 } 1066 1067 _docker_top() { 1068 case "$cur" in 1069 -*) 1070 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1071 ;; 1072 *) 1073 local counter=$(__docker_pos_first_nonflag) 1074 if [ $cword -eq $counter ]; then 1075 __docker_containers_running 1076 fi 1077 ;; 1078 esac 1079 } 1080 1081 _docker_version() { 1082 case "$cur" in 1083 -*) 1084 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1085 ;; 1086 esac 1087 } 1088 1089 _docker_wait() { 1090 case "$cur" in 1091 -*) 1092 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1093 ;; 1094 *) 1095 __docker_containers_all 1096 ;; 1097 esac 1098 } 1099 1100 _docker() { 1101 local previous_extglob_setting=$(shopt -p extglob) 1102 shopt -s extglob 1103 1104 local commands=( 1105 attach 1106 build 1107 commit 1108 cp 1109 create 1110 diff 1111 events 1112 exec 1113 export 1114 history 1115 images 1116 import 1117 info 1118 inspect 1119 kill 1120 load 1121 login 1122 logout 1123 logs 1124 pause 1125 port 1126 ps 1127 pull 1128 push 1129 rename 1130 restart 1131 rm 1132 rmi 1133 run 1134 save 1135 search 1136 start 1137 stats 1138 stop 1139 tag 1140 top 1141 unpause 1142 version 1143 wait 1144 ) 1145 1146 local main_options_with_args=" 1147 --api-cors-header 1148 --bip 1149 --bridge -b 1150 --default-ulimit 1151 --dns 1152 --dns-search 1153 --exec-driver -e 1154 --fixed-cidr 1155 --fixed-cidr-v6 1156 --graph -g 1157 --group -G 1158 --host -H 1159 --insecure-registry 1160 --ip 1161 --label 1162 --log-driver 1163 --log-level -l 1164 --mtu 1165 --pidfile -p 1166 --registry-mirror 1167 --storage-driver -s 1168 --storage-opt 1169 --tlscacert 1170 --tlscert 1171 --tlskey 1172 " 1173 1174 local main_options_with_args_glob=$(__docker_to_extglob "$main_options_with_args") 1175 1176 COMPREPLY=() 1177 local cur prev words cword 1178 _get_comp_words_by_ref -n : cur prev words cword 1179 1180 local command='docker' cpos=0 1181 local counter=1 1182 while [ $counter -lt $cword ]; do 1183 case "${words[$counter]}" in 1184 $main_options_with_args_glob ) 1185 (( counter++ )) 1186 ;; 1187 -*) 1188 ;; 1189 *) 1190 command="${words[$counter]}" 1191 cpos=$counter 1192 (( cpos++ )) 1193 break 1194 ;; 1195 esac 1196 (( counter++ )) 1197 done 1198 1199 local completions_func=_docker_${command} 1200 declare -F $completions_func >/dev/null && $completions_func 1201 1202 eval "$previous_extglob_setting" 1203 return 0 1204 } 1205 1206 complete -F _docker docker