github.com/codemac/docker@v1.2.1-0.20150518222241-6a18412d5b9c/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 --since --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 for arg in "${COMP_WORDS[@]}"; do 683 case "$arg" in 684 --all-tags|-a) 685 __docker_image_repos 686 return 687 ;; 688 esac 689 done 690 __docker_image_repos_and_tags 691 fi 692 ;; 693 esac 694 } 695 696 _docker_push() { 697 case "$cur" in 698 -*) 699 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 700 ;; 701 *) 702 local counter=$(__docker_pos_first_nonflag) 703 if [ $cword -eq $counter ]; then 704 __docker_image_repos_and_tags 705 fi 706 ;; 707 esac 708 } 709 710 _docker_rename() { 711 case "$cur" in 712 -*) 713 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 714 ;; 715 *) 716 local counter=$(__docker_pos_first_nonflag) 717 if [ $cword -eq $counter ]; then 718 __docker_containers_all 719 fi 720 ;; 721 esac 722 } 723 724 _docker_restart() { 725 case "$prev" in 726 --time|-t) 727 return 728 ;; 729 esac 730 731 case "$cur" in 732 -*) 733 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 734 ;; 735 *) 736 __docker_containers_all 737 ;; 738 esac 739 } 740 741 _docker_rm() { 742 case "$cur" in 743 -*) 744 COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) ) 745 ;; 746 *) 747 for arg in "${COMP_WORDS[@]}"; do 748 case "$arg" in 749 --force|-f) 750 __docker_containers_all 751 return 752 ;; 753 esac 754 done 755 __docker_containers_stopped 756 ;; 757 esac 758 } 759 760 _docker_rmi() { 761 case "$cur" in 762 -*) 763 COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) ) 764 ;; 765 *) 766 __docker_image_repos_and_tags_and_ids 767 ;; 768 esac 769 } 770 771 _docker_run() { 772 local options_with_args=" 773 --add-host 774 --attach -a 775 --cap-add 776 --cap-drop 777 --cgroup-parent 778 --cidfile 779 --cpuset 780 --cpu-shares -c 781 --cpu-period 782 --cpu-quota 783 --device 784 --dns 785 --dns-search 786 --entrypoint 787 --env -e 788 --env-file 789 --expose 790 --hostname -h 791 --ipc 792 --label -l 793 --label-file 794 --link 795 --log-driver 796 --lxc-conf 797 --mac-address 798 --memory -m 799 --memory-swap 800 --name 801 --net 802 --pid 803 --publish -p 804 --restart 805 --security-opt 806 --user -u 807 --ulimit 808 --volumes-from 809 --volume -v 810 --workdir -w 811 " 812 813 local all_options="$options_with_args 814 --help 815 --interactive -i 816 --privileged 817 --publish-all -P 818 --read-only 819 --tty -t 820 " 821 822 [ "$command" = "run" ] && all_options="$all_options 823 --detach -d 824 --rm 825 --sig-proxy 826 " 827 828 local options_with_args_glob=$(__docker_to_extglob "$options_with_args") 829 830 case "$prev" in 831 --add-host) 832 case "$cur" in 833 *:) 834 __docker_resolve_hostname 835 return 836 ;; 837 esac 838 ;; 839 --attach|-a) 840 COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) ) 841 return 842 ;; 843 --cap-add|--cap-drop) 844 __docker_capabilities 845 return 846 ;; 847 --cidfile|--env-file|--label-file) 848 _filedir 849 return 850 ;; 851 --device|--volume|-v) 852 case "$cur" in 853 *:*) 854 # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) 855 ;; 856 '') 857 COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) 858 compopt -o nospace 859 ;; 860 /*) 861 _filedir 862 compopt -o nospace 863 ;; 864 esac 865 return 866 ;; 867 --env|-e) 868 COMPREPLY=( $( compgen -e -- "$cur" ) ) 869 compopt -o nospace 870 return 871 ;; 872 --ipc) 873 case "$cur" in 874 *:*) 875 cur="${cur#*:}" 876 __docker_containers_running 877 ;; 878 *) 879 COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) ) 880 if [ "$COMPREPLY" = "container:" ]; then 881 compopt -o nospace 882 fi 883 ;; 884 esac 885 return 886 ;; 887 --link) 888 case "$cur" in 889 *:*) 890 ;; 891 *) 892 __docker_containers_running 893 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 894 compopt -o nospace 895 ;; 896 esac 897 return 898 ;; 899 --log-driver) 900 COMPREPLY=( $( compgen -W "json-file syslog none" -- "$cur") ) 901 return 902 ;; 903 --net) 904 case "$cur" in 905 container:*) 906 local cur=${cur#*:} 907 __docker_containers_all 908 ;; 909 *) 910 COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") ) 911 if [ "${COMPREPLY[*]}" = "container:" ] ; then 912 compopt -o nospace 913 fi 914 ;; 915 esac 916 return 917 ;; 918 --restart) 919 case "$cur" in 920 on-failure:*) 921 ;; 922 *) 923 COMPREPLY=( $( compgen -W "no on-failure on-failure: always" -- "$cur") ) 924 ;; 925 esac 926 return 927 ;; 928 --security-opt) 929 case "$cur" in 930 label:*:*) 931 ;; 932 label:*) 933 local cur=${cur##*:} 934 COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") ) 935 if [ "${COMPREPLY[*]}" != "disable" ] ; then 936 compopt -o nospace 937 fi 938 ;; 939 *) 940 COMPREPLY=( $( compgen -W "label apparmor" -S ":" -- "$cur") ) 941 compopt -o nospace 942 ;; 943 esac 944 return 945 ;; 946 --volumes-from) 947 __docker_containers_all 948 return 949 ;; 950 $options_with_args_glob ) 951 return 952 ;; 953 esac 954 955 case "$cur" in 956 -*) 957 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 958 ;; 959 *) 960 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 961 962 if [ $cword -eq $counter ]; then 963 __docker_image_repos_and_tags_and_ids 964 fi 965 ;; 966 esac 967 } 968 969 _docker_save() { 970 case "$prev" in 971 --output|-o) 972 _filedir 973 return 974 ;; 975 esac 976 977 case "$cur" in 978 -*) 979 COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) ) 980 ;; 981 *) 982 __docker_image_repos_and_tags_and_ids 983 ;; 984 esac 985 } 986 987 _docker_search() { 988 case "$prev" in 989 --stars|-s) 990 return 991 ;; 992 esac 993 994 case "$cur" in 995 -*) 996 COMPREPLY=( $( compgen -W "--automated --help --no-trunc --stars -s" -- "$cur" ) ) 997 ;; 998 esac 999 } 1000 1001 _docker_start() { 1002 case "$cur" in 1003 -*) 1004 COMPREPLY=( $( compgen -W "--attach -a --help --interactive -i" -- "$cur" ) ) 1005 ;; 1006 *) 1007 __docker_containers_stopped 1008 ;; 1009 esac 1010 } 1011 1012 _docker_stats() { 1013 case "$cur" in 1014 -*) 1015 COMPREPLY=( $( compgen -W "--no-stream --help" -- "$cur" ) ) 1016 ;; 1017 *) 1018 __docker_containers_running 1019 ;; 1020 esac 1021 } 1022 1023 _docker_stop() { 1024 case "$prev" in 1025 --time|-t) 1026 return 1027 ;; 1028 esac 1029 1030 case "$cur" in 1031 -*) 1032 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 1033 ;; 1034 *) 1035 __docker_containers_running 1036 ;; 1037 esac 1038 } 1039 1040 _docker_tag() { 1041 case "$cur" in 1042 -*) 1043 COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) 1044 ;; 1045 *) 1046 local counter=$(__docker_pos_first_nonflag) 1047 1048 if [ $cword -eq $counter ]; then 1049 __docker_image_repos_and_tags 1050 return 1051 fi 1052 (( counter++ )) 1053 1054 if [ $cword -eq $counter ]; then 1055 __docker_image_repos_and_tags 1056 return 1057 fi 1058 ;; 1059 esac 1060 } 1061 1062 _docker_unpause() { 1063 case "$cur" in 1064 -*) 1065 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1066 ;; 1067 *) 1068 local counter=$(__docker_pos_first_nonflag) 1069 if [ $cword -eq $counter ]; then 1070 __docker_containers_unpauseable 1071 fi 1072 ;; 1073 esac 1074 } 1075 1076 _docker_top() { 1077 case "$cur" in 1078 -*) 1079 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1080 ;; 1081 *) 1082 local counter=$(__docker_pos_first_nonflag) 1083 if [ $cword -eq $counter ]; then 1084 __docker_containers_running 1085 fi 1086 ;; 1087 esac 1088 } 1089 1090 _docker_version() { 1091 case "$cur" in 1092 -*) 1093 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1094 ;; 1095 esac 1096 } 1097 1098 _docker_wait() { 1099 case "$cur" in 1100 -*) 1101 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1102 ;; 1103 *) 1104 __docker_containers_all 1105 ;; 1106 esac 1107 } 1108 1109 _docker() { 1110 local previous_extglob_setting=$(shopt -p extglob) 1111 shopt -s extglob 1112 1113 local commands=( 1114 attach 1115 build 1116 commit 1117 cp 1118 create 1119 diff 1120 events 1121 exec 1122 export 1123 history 1124 images 1125 import 1126 info 1127 inspect 1128 kill 1129 load 1130 login 1131 logout 1132 logs 1133 pause 1134 port 1135 ps 1136 pull 1137 push 1138 rename 1139 restart 1140 rm 1141 rmi 1142 run 1143 save 1144 search 1145 start 1146 stats 1147 stop 1148 tag 1149 top 1150 unpause 1151 version 1152 wait 1153 ) 1154 1155 local main_options_with_args=" 1156 --api-cors-header 1157 --bip 1158 --bridge -b 1159 --default-ulimit 1160 --dns 1161 --dns-search 1162 --exec-driver -e 1163 --exec-opt 1164 --exec-root 1165 --fixed-cidr 1166 --fixed-cidr-v6 1167 --graph -g 1168 --group -G 1169 --host -H 1170 --insecure-registry 1171 --ip 1172 --label 1173 --log-driver 1174 --log-level -l 1175 --mtu 1176 --pidfile -p 1177 --registry-mirror 1178 --storage-driver -s 1179 --storage-opt 1180 --tlscacert 1181 --tlscert 1182 --tlskey 1183 " 1184 1185 local main_options_with_args_glob=$(__docker_to_extglob "$main_options_with_args") 1186 1187 COMPREPLY=() 1188 local cur prev words cword 1189 _get_comp_words_by_ref -n : cur prev words cword 1190 1191 local command='docker' cpos=0 1192 local counter=1 1193 while [ $counter -lt $cword ]; do 1194 case "${words[$counter]}" in 1195 $main_options_with_args_glob ) 1196 (( counter++ )) 1197 ;; 1198 -*) 1199 ;; 1200 *) 1201 command="${words[$counter]}" 1202 cpos=$counter 1203 (( cpos++ )) 1204 break 1205 ;; 1206 esac 1207 (( counter++ )) 1208 done 1209 1210 local completions_func=_docker_${command} 1211 declare -F $completions_func >/dev/null && $completions_func 1212 1213 eval "$previous_extglob_setting" 1214 return 0 1215 } 1216 1217 complete -F _docker docker