github.com/mssola/docker@v1.8.1/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"} ${config:+--config "$config"} 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 # Finds the position of the first word that is neither option nor an option's argument. 98 # If there are options that require arguments, you should pass a glob describing those 99 # options, e.g. "--option1|-o|--option2" 100 # Use this function to restrict completions to exact positions after the argument list. 101 __docker_pos_first_nonflag() { 102 local argument_flags=$1 103 104 local counter=$((command_pos + 1)) 105 while [ $counter -le $cword ]; do 106 if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then 107 (( counter++ )) 108 # eat "=" in case of --option=arg syntax 109 [ "${words[$counter]}" = "=" ] && (( counter++ )) 110 else 111 case "${words[$counter]}" in 112 -*) 113 ;; 114 *) 115 break 116 ;; 117 esac 118 fi 119 120 # Bash splits words at "=", retaining "=" as a word, examples: 121 # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words 122 while [ "${words[$counter + 1]}" = "=" ] ; do 123 counter=$(( counter + 2)) 124 done 125 126 (( counter++ )) 127 done 128 129 echo $counter 130 } 131 132 # Returns the value of the first option matching option_glob. 133 # Valid values for option_glob are option names like '--log-level' and 134 # globs like '--log-level|-l' 135 # Only positions between the command and the current word are considered. 136 __docker_value_of_option() { 137 local option_glob=$1 138 139 local counter=$((command_pos + 1)) 140 while [ $counter -lt $cword ]; do 141 case ${words[$counter]} in 142 $option_glob ) 143 echo ${words[$counter + 1]} 144 break 145 ;; 146 esac 147 (( counter++ )) 148 done 149 } 150 151 # Transforms a multiline list of strings into a single line string 152 # with the words separated by "|". 153 # This is used to prepare arguments to __docker_pos_first_nonflag(). 154 __docker_to_alternatives() { 155 local parts=( $1 ) 156 local IFS='|' 157 echo "${parts[*]}" 158 } 159 160 # Transforms a multiline list of options into an extglob pattern 161 # suitable for use in case statements. 162 __docker_to_extglob() { 163 local extglob=$( __docker_to_alternatives "$1" ) 164 echo "@($extglob)" 165 } 166 167 __docker_resolve_hostname() { 168 command -v host >/dev/null 2>&1 || return 169 COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') ) 170 } 171 172 __docker_capabilities() { 173 # The list of capabilities is defined in types.go, ALL was added manually. 174 COMPREPLY=( $( compgen -W " 175 ALL 176 AUDIT_CONTROL 177 AUDIT_WRITE 178 AUDIT_READ 179 BLOCK_SUSPEND 180 CHOWN 181 DAC_OVERRIDE 182 DAC_READ_SEARCH 183 FOWNER 184 FSETID 185 IPC_LOCK 186 IPC_OWNER 187 KILL 188 LEASE 189 LINUX_IMMUTABLE 190 MAC_ADMIN 191 MAC_OVERRIDE 192 MKNOD 193 NET_ADMIN 194 NET_BIND_SERVICE 195 NET_BROADCAST 196 NET_RAW 197 SETFCAP 198 SETGID 199 SETPCAP 200 SETUID 201 SYS_ADMIN 202 SYS_BOOT 203 SYS_CHROOT 204 SYSLOG 205 SYS_MODULE 206 SYS_NICE 207 SYS_PACCT 208 SYS_PTRACE 209 SYS_RAWIO 210 SYS_RESOURCE 211 SYS_TIME 212 SYS_TTY_CONFIG 213 WAKE_ALARM 214 " -- "$cur" ) ) 215 } 216 217 __docker_log_drivers() { 218 COMPREPLY=( $( compgen -W " 219 fluentd 220 gelf 221 journald 222 json-file 223 none 224 syslog 225 " -- "$cur" ) ) 226 } 227 228 __docker_log_driver_options() { 229 # see docs/reference/logging/index.md 230 local fluentd_options="fluentd-address fluentd-tag" 231 local gelf_options="gelf-address gelf-tag" 232 local syslog_options="syslog-address syslog-facility syslog-tag" 233 234 case $(__docker_value_of_option --log-driver) in 235 '') 236 COMPREPLY=( $( compgen -W "$fluentd_options $gelf_options $syslog_options" -S = -- "$cur" ) ) 237 ;; 238 fluentd) 239 COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) ) 240 ;; 241 gelf) 242 COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) ) 243 ;; 244 syslog) 245 COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) ) 246 ;; 247 *) 248 return 249 ;; 250 esac 251 252 compopt -o nospace 253 } 254 255 __docker_complete_log_driver_options() { 256 # "=" gets parsed to a word and assigned to either $cur or $prev depending on whether 257 # it is the last character or not. So we search for "xxx=" in the the last two words. 258 case "${words[$cword-2]}$prev=" in 259 *gelf-address=*) 260 COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur#=}" ) ) 261 compopt -o nospace 262 return 263 ;; 264 *syslog-address=*) 265 COMPREPLY=( $( compgen -W "tcp udp unix" -S "://" -- "${cur#=}" ) ) 266 compopt -o nospace 267 return 268 ;; 269 *syslog-facility=*) 270 COMPREPLY=( $( compgen -W " 271 auth 272 authpriv 273 cron 274 daemon 275 ftp 276 kern 277 local0 278 local1 279 local2 280 local3 281 local4 282 local5 283 local6 284 local7 285 lpr 286 mail 287 news 288 syslog 289 user 290 uucp 291 " -- "${cur#=}" ) ) 292 return 293 ;; 294 esac 295 return 1 296 } 297 298 __docker_log_levels() { 299 COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) ) 300 } 301 302 # a selection of the available signals that is most likely of interest in the 303 # context of docker containers. 304 __docker_signals() { 305 local signals=( 306 SIGCONT 307 SIGHUP 308 SIGINT 309 SIGKILL 310 SIGQUIT 311 SIGSTOP 312 SIGTERM 313 SIGUSR1 314 SIGUSR2 315 ) 316 COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) ) 317 } 318 319 # global options that may appear after the docker command 320 _docker_docker() { 321 local boolean_options=" 322 $global_boolean_options 323 --help -h 324 --version -v 325 " 326 327 case "$prev" in 328 --config) 329 _filedir -d 330 return 331 ;; 332 --log-level|-l) 333 __docker_log_levels 334 return 335 ;; 336 $(__docker_to_extglob "$global_options_with_args") ) 337 return 338 ;; 339 esac 340 341 __docker_complete_log_driver_options && return 342 343 case "$cur" in 344 -*) 345 COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) ) 346 ;; 347 *) 348 local counter=$( __docker_pos_first_nonflag $(__docker_to_extglob "$global_options_with_args") ) 349 if [ $cword -eq $counter ]; then 350 COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) ) 351 fi 352 ;; 353 esac 354 } 355 356 _docker_attach() { 357 case "$cur" in 358 -*) 359 COMPREPLY=( $( compgen -W "--help --no-stdin --sig-proxy" -- "$cur" ) ) 360 ;; 361 *) 362 local counter="$(__docker_pos_first_nonflag)" 363 if [ $cword -eq $counter ]; then 364 __docker_containers_running 365 fi 366 ;; 367 esac 368 } 369 370 _docker_build() { 371 case "$prev" in 372 --cgroup-parent|--cpuset-cpus|--cpuset-mems|--cpu-shares|-c|--cpu-period|--cpu-quota|--memory|-m|--memory-swap) 373 return 374 ;; 375 --file|-f) 376 _filedir 377 return 378 ;; 379 --tag|-t) 380 __docker_image_repos_and_tags 381 return 382 ;; 383 esac 384 385 case "$cur" in 386 -*) 387 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 --ulimit" -- "$cur" ) ) 388 ;; 389 *) 390 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')" 391 if [ $cword -eq $counter ]; then 392 _filedir -d 393 fi 394 ;; 395 esac 396 } 397 398 _docker_commit() { 399 case "$prev" in 400 --author|-a|--change|-c|--message|-m) 401 return 402 ;; 403 esac 404 405 case "$cur" in 406 -*) 407 COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause -p" -- "$cur" ) ) 408 ;; 409 *) 410 local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m') 411 412 if [ $cword -eq $counter ]; then 413 __docker_containers_all 414 return 415 fi 416 (( counter++ )) 417 418 if [ $cword -eq $counter ]; then 419 __docker_image_repos_and_tags 420 return 421 fi 422 ;; 423 esac 424 } 425 426 _docker_cp() { 427 case "$cur" in 428 -*) 429 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 430 ;; 431 *) 432 local counter=$(__docker_pos_first_nonflag) 433 if [ $cword -eq $counter ]; then 434 case "$cur" in 435 *:) 436 return 437 ;; 438 *) 439 __docker_containers_all 440 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 441 compopt -o nospace 442 return 443 ;; 444 esac 445 fi 446 (( counter++ )) 447 448 if [ $cword -eq $counter ]; then 449 _filedir -d 450 return 451 fi 452 ;; 453 esac 454 } 455 456 _docker_create() { 457 _docker_run 458 } 459 460 _docker_daemon() { 461 local boolean_options=" 462 $global_boolean_options 463 --help -h 464 --icc=false 465 --ip-forward=false 466 --ip-masq=false 467 --iptables=false 468 --ipv6 469 --selinux-enabled 470 --userland-proxy=false 471 " 472 local options_with_args=" 473 $global_options_with_args 474 --api-cors-header 475 --bip 476 --bridge -b 477 --default-gateway 478 --default-gateway-v6 479 --default-ulimit 480 --dns 481 --dns-search 482 --exec-driver -e 483 --exec-opt 484 --exec-root 485 --fixed-cidr 486 --fixed-cidr-v6 487 --graph -g 488 --group -G 489 --insecure-registry 490 --ip 491 --label 492 --log-driver 493 --log-opt 494 --mtu 495 --pidfile -p 496 --registry-mirror 497 --storage-driver -s 498 --storage-opt 499 " 500 501 case "$prev" in 502 --exec-root|--graph|-g) 503 _filedir -d 504 return 505 ;; 506 --log-driver) 507 __docker_log_drivers 508 return 509 ;; 510 --pidfile|-p|--tlscacert|--tlscert|--tlskey) 511 _filedir 512 return 513 ;; 514 --storage-driver|-s) 515 COMPREPLY=( $( compgen -W "aufs devicemapper btrfs overlay" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) ) 516 return 517 ;; 518 --log-level|-l) 519 __docker_log_levels 520 return 521 ;; 522 --log-opt) 523 __docker_log_driver_options 524 return 525 ;; 526 $(__docker_to_extglob "$options_with_args") ) 527 return 528 ;; 529 esac 530 531 case "$cur" in 532 -*) 533 COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) 534 ;; 535 esac 536 } 537 538 _docker_diff() { 539 case "$cur" in 540 -*) 541 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 542 ;; 543 *) 544 local counter=$(__docker_pos_first_nonflag) 545 if [ $cword -eq $counter ]; then 546 __docker_containers_all 547 fi 548 ;; 549 esac 550 } 551 552 _docker_events() { 553 case "$prev" in 554 --filter|-f) 555 COMPREPLY=( $( compgen -S = -W "container event image" -- "$cur" ) ) 556 compopt -o nospace 557 return 558 ;; 559 --since|--until) 560 return 561 ;; 562 esac 563 564 case "${words[$cword-2]}$prev=" in 565 *container=*) 566 cur="${cur#=}" 567 __docker_containers_all 568 return 569 ;; 570 *event=*) 571 COMPREPLY=( $( compgen -W " 572 attach 573 commit 574 copy 575 create 576 delete 577 destroy 578 die 579 exec_create 580 exec_start 581 export 582 import 583 kill 584 oom 585 pause 586 pull 587 push 588 rename 589 resize 590 restart 591 start 592 stop 593 tag 594 top 595 unpause 596 untag 597 " -- "${cur#=}" ) ) 598 return 599 ;; 600 *image=*) 601 cur="${cur#=}" 602 __docker_image_repos_and_tags_and_ids 603 return 604 ;; 605 esac 606 607 case "$cur" in 608 -*) 609 COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) ) 610 ;; 611 esac 612 } 613 614 _docker_exec() { 615 case "$prev" in 616 --user|-u) 617 return 618 ;; 619 esac 620 621 case "$cur" in 622 -*) 623 COMPREPLY=( $( compgen -W "--detach -d --help --interactive -i -t --tty -u --user" -- "$cur" ) ) 624 ;; 625 *) 626 __docker_containers_running 627 ;; 628 esac 629 } 630 631 _docker_export() { 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_help() { 646 local counter=$(__docker_pos_first_nonflag) 647 if [ $cword -eq $counter ]; then 648 COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) ) 649 fi 650 } 651 652 _docker_history() { 653 case "$cur" in 654 -*) 655 COMPREPLY=( $( compgen -W "--help --no-trunc --quiet -q" -- "$cur" ) ) 656 ;; 657 *) 658 local counter=$(__docker_pos_first_nonflag) 659 if [ $cword -eq $counter ]; then 660 __docker_image_repos_and_tags_and_ids 661 fi 662 ;; 663 esac 664 } 665 666 _docker_images() { 667 case "$prev" in 668 --filter|-f) 669 COMPREPLY=( $( compgen -W "dangling=true label=" -- "$cur" ) ) 670 if [ "$COMPREPLY" = "label=" ]; then 671 compopt -o nospace 672 fi 673 return 674 ;; 675 esac 676 677 case "${words[$cword-2]}$prev=" in 678 *dangling=*) 679 COMPREPLY=( $( compgen -W "true false" -- "${cur#=}" ) ) 680 return 681 ;; 682 *label=*) 683 return 684 ;; 685 esac 686 687 case "$cur" in 688 -*) 689 COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --help --no-trunc --quiet -q" -- "$cur" ) ) 690 ;; 691 =) 692 return 693 ;; 694 *) 695 __docker_image_repos 696 ;; 697 esac 698 } 699 700 _docker_import() { 701 case "$cur" in 702 -*) 703 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 704 ;; 705 *) 706 local counter=$(__docker_pos_first_nonflag) 707 if [ $cword -eq $counter ]; then 708 return 709 fi 710 (( counter++ )) 711 712 if [ $cword -eq $counter ]; then 713 __docker_image_repos_and_tags 714 return 715 fi 716 ;; 717 esac 718 } 719 720 _docker_info() { 721 case "$cur" in 722 -*) 723 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 724 ;; 725 esac 726 } 727 728 _docker_inspect() { 729 case "$prev" in 730 --format|-f) 731 return 732 ;; 733 --type) 734 COMPREPLY=( $( compgen -W "image container" -- "$cur" ) ) 735 return 736 ;; 737 738 esac 739 740 case "$cur" in 741 -*) 742 COMPREPLY=( $( compgen -W "--format -f --type --help" -- "$cur" ) ) 743 ;; 744 *) 745 case $(__docker_value_of_option --type) in 746 '') 747 __docker_containers_and_images 748 ;; 749 container) 750 __docker_containers_all 751 ;; 752 image) 753 __docker_image_repos_and_tags_and_ids 754 ;; 755 esac 756 esac 757 } 758 759 _docker_kill() { 760 case "$prev" in 761 --signal|-s) 762 __docker_signals 763 return 764 ;; 765 esac 766 767 case "$cur" in 768 -*) 769 COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) ) 770 ;; 771 *) 772 __docker_containers_running 773 ;; 774 esac 775 } 776 777 _docker_load() { 778 case "$prev" in 779 --input|-i) 780 _filedir 781 return 782 ;; 783 esac 784 785 case "$cur" in 786 -*) 787 COMPREPLY=( $( compgen -W "--help --input -i" -- "$cur" ) ) 788 ;; 789 esac 790 } 791 792 _docker_login() { 793 case "$prev" in 794 --email|-e|--password|-p|--username|-u) 795 return 796 ;; 797 esac 798 799 case "$cur" in 800 -*) 801 COMPREPLY=( $( compgen -W "--email -e --help --password -p --username -u" -- "$cur" ) ) 802 ;; 803 esac 804 } 805 806 _docker_logout() { 807 case "$cur" in 808 -*) 809 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 810 ;; 811 esac 812 } 813 814 _docker_logs() { 815 case "$prev" in 816 --since|--tail) 817 return 818 ;; 819 esac 820 821 case "$cur" in 822 -*) 823 COMPREPLY=( $( compgen -W "--follow -f --help --since --tail --timestamps -t" -- "$cur" ) ) 824 ;; 825 *) 826 local counter=$(__docker_pos_first_nonflag '--tail') 827 if [ $cword -eq $counter ]; then 828 __docker_containers_all 829 fi 830 ;; 831 esac 832 } 833 834 _docker_pause() { 835 case "$cur" in 836 -*) 837 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 838 ;; 839 *) 840 local counter=$(__docker_pos_first_nonflag) 841 if [ $cword -eq $counter ]; then 842 __docker_containers_pauseable 843 fi 844 ;; 845 esac 846 } 847 848 _docker_port() { 849 case "$cur" in 850 -*) 851 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 852 ;; 853 *) 854 local counter=$(__docker_pos_first_nonflag) 855 if [ $cword -eq $counter ]; then 856 __docker_containers_all 857 fi 858 ;; 859 esac 860 } 861 862 _docker_ps() { 863 case "$prev" in 864 --before|--since) 865 __docker_containers_all 866 ;; 867 --filter|-f) 868 COMPREPLY=( $( compgen -S = -W "exited id label name status" -- "$cur" ) ) 869 compopt -o nospace 870 return 871 ;; 872 -n) 873 return 874 ;; 875 esac 876 877 case "${words[$cword-2]}$prev=" in 878 *id=*) 879 cur="${cur#=}" 880 __docker_container_ids 881 return 882 ;; 883 *name=*) 884 cur="${cur#=}" 885 __docker_container_names 886 return 887 ;; 888 *status=*) 889 COMPREPLY=( $( compgen -W "exited paused restarting running" -- "${cur#=}" ) ) 890 return 891 ;; 892 esac 893 894 case "$cur" in 895 -*) 896 COMPREPLY=( $( compgen -W "--all -a --before --filter -f --help --latest -l -n --no-trunc --quiet -q --size -s --since" -- "$cur" ) ) 897 ;; 898 esac 899 } 900 901 _docker_pull() { 902 case "$cur" in 903 -*) 904 COMPREPLY=( $( compgen -W "--all-tags -a --help" -- "$cur" ) ) 905 ;; 906 *) 907 local counter=$(__docker_pos_first_nonflag) 908 if [ $cword -eq $counter ]; then 909 for arg in "${COMP_WORDS[@]}"; do 910 case "$arg" in 911 --all-tags|-a) 912 __docker_image_repos 913 return 914 ;; 915 esac 916 done 917 __docker_image_repos_and_tags 918 fi 919 ;; 920 esac 921 } 922 923 _docker_push() { 924 case "$cur" in 925 -*) 926 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 927 ;; 928 *) 929 local counter=$(__docker_pos_first_nonflag) 930 if [ $cword -eq $counter ]; then 931 __docker_image_repos_and_tags 932 fi 933 ;; 934 esac 935 } 936 937 _docker_rename() { 938 case "$cur" in 939 -*) 940 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 941 ;; 942 *) 943 local counter=$(__docker_pos_first_nonflag) 944 if [ $cword -eq $counter ]; then 945 __docker_containers_all 946 fi 947 ;; 948 esac 949 } 950 951 _docker_restart() { 952 case "$prev" in 953 --time|-t) 954 return 955 ;; 956 esac 957 958 case "$cur" in 959 -*) 960 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 961 ;; 962 *) 963 __docker_containers_all 964 ;; 965 esac 966 } 967 968 _docker_rm() { 969 case "$cur" in 970 -*) 971 COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) ) 972 ;; 973 *) 974 for arg in "${COMP_WORDS[@]}"; do 975 case "$arg" in 976 --force|-f) 977 __docker_containers_all 978 return 979 ;; 980 esac 981 done 982 __docker_containers_stopped 983 ;; 984 esac 985 } 986 987 _docker_rmi() { 988 case "$cur" in 989 -*) 990 COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) ) 991 ;; 992 *) 993 __docker_image_repos_and_tags_and_ids 994 ;; 995 esac 996 } 997 998 _docker_run() { 999 local options_with_args=" 1000 --add-host 1001 --blkio-weight 1002 --attach -a 1003 --cap-add 1004 --cap-drop 1005 --cgroup-parent 1006 --cidfile 1007 --cpuset 1008 --cpu-period 1009 --cpu-quota 1010 --cpu-shares -c 1011 --device 1012 --dns 1013 --dns-search 1014 --entrypoint 1015 --env -e 1016 --env-file 1017 --expose 1018 --group-add 1019 --hostname -h 1020 --ipc 1021 --label -l 1022 --label-file 1023 --link 1024 --log-driver 1025 --log-opt 1026 --lxc-conf 1027 --mac-address 1028 --memory -m 1029 --memory-swap 1030 --name 1031 --net 1032 --pid 1033 --publish -p 1034 --restart 1035 --security-opt 1036 --user -u 1037 --ulimit 1038 --uts 1039 --volumes-from 1040 --volume -v 1041 --workdir -w 1042 " 1043 1044 local all_options="$options_with_args 1045 --help 1046 --interactive -i 1047 --privileged 1048 --publish-all -P 1049 --read-only 1050 --tty -t 1051 " 1052 1053 [ "$command" = "run" ] && all_options="$all_options 1054 --detach -d 1055 --rm 1056 --sig-proxy 1057 " 1058 1059 local options_with_args_glob=$(__docker_to_extglob "$options_with_args") 1060 1061 case "$prev" in 1062 --add-host) 1063 case "$cur" in 1064 *:) 1065 __docker_resolve_hostname 1066 return 1067 ;; 1068 esac 1069 ;; 1070 --attach|-a) 1071 COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) ) 1072 return 1073 ;; 1074 --cap-add|--cap-drop) 1075 __docker_capabilities 1076 return 1077 ;; 1078 --cidfile|--env-file|--label-file) 1079 _filedir 1080 return 1081 ;; 1082 --device|--volume|-v) 1083 case "$cur" in 1084 *:*) 1085 # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) 1086 ;; 1087 '') 1088 COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) 1089 compopt -o nospace 1090 ;; 1091 /*) 1092 _filedir 1093 compopt -o nospace 1094 ;; 1095 esac 1096 return 1097 ;; 1098 --env|-e) 1099 COMPREPLY=( $( compgen -e -- "$cur" ) ) 1100 compopt -o nospace 1101 return 1102 ;; 1103 --ipc) 1104 case "$cur" in 1105 *:*) 1106 cur="${cur#*:}" 1107 __docker_containers_running 1108 ;; 1109 *) 1110 COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) ) 1111 if [ "$COMPREPLY" = "container:" ]; then 1112 compopt -o nospace 1113 fi 1114 ;; 1115 esac 1116 return 1117 ;; 1118 --link) 1119 case "$cur" in 1120 *:*) 1121 ;; 1122 *) 1123 __docker_containers_running 1124 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 1125 compopt -o nospace 1126 ;; 1127 esac 1128 return 1129 ;; 1130 --log-driver) 1131 __docker_log_drivers 1132 return 1133 ;; 1134 --log-opt) 1135 __docker_log_driver_options 1136 return 1137 ;; 1138 --net) 1139 case "$cur" in 1140 container:*) 1141 local cur=${cur#*:} 1142 __docker_containers_all 1143 ;; 1144 *) 1145 COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") ) 1146 if [ "${COMPREPLY[*]}" = "container:" ] ; then 1147 compopt -o nospace 1148 fi 1149 ;; 1150 esac 1151 return 1152 ;; 1153 --restart) 1154 case "$cur" in 1155 on-failure:*) 1156 ;; 1157 *) 1158 COMPREPLY=( $( compgen -W "no on-failure on-failure: always" -- "$cur") ) 1159 ;; 1160 esac 1161 return 1162 ;; 1163 --security-opt) 1164 case "$cur" in 1165 label:*:*) 1166 ;; 1167 label:*) 1168 local cur=${cur##*:} 1169 COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") ) 1170 if [ "${COMPREPLY[*]}" != "disable" ] ; then 1171 compopt -o nospace 1172 fi 1173 ;; 1174 *) 1175 COMPREPLY=( $( compgen -W "label apparmor" -S ":" -- "$cur") ) 1176 compopt -o nospace 1177 ;; 1178 esac 1179 return 1180 ;; 1181 --volumes-from) 1182 __docker_containers_all 1183 return 1184 ;; 1185 $options_with_args_glob ) 1186 return 1187 ;; 1188 esac 1189 1190 __docker_complete_log_driver_options && return 1191 1192 case "$cur" in 1193 -*) 1194 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 1195 ;; 1196 *) 1197 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 1198 1199 if [ $cword -eq $counter ]; then 1200 __docker_image_repos_and_tags_and_ids 1201 fi 1202 ;; 1203 esac 1204 } 1205 1206 _docker_save() { 1207 case "$prev" in 1208 --output|-o) 1209 _filedir 1210 return 1211 ;; 1212 esac 1213 1214 case "$cur" in 1215 -*) 1216 COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) ) 1217 ;; 1218 *) 1219 __docker_image_repos_and_tags_and_ids 1220 ;; 1221 esac 1222 } 1223 1224 _docker_search() { 1225 case "$prev" in 1226 --stars|-s) 1227 return 1228 ;; 1229 esac 1230 1231 case "$cur" in 1232 -*) 1233 COMPREPLY=( $( compgen -W "--automated --help --no-trunc --stars -s" -- "$cur" ) ) 1234 ;; 1235 esac 1236 } 1237 1238 _docker_start() { 1239 case "$cur" in 1240 -*) 1241 COMPREPLY=( $( compgen -W "--attach -a --help --interactive -i" -- "$cur" ) ) 1242 ;; 1243 *) 1244 __docker_containers_stopped 1245 ;; 1246 esac 1247 } 1248 1249 _docker_stats() { 1250 case "$cur" in 1251 -*) 1252 COMPREPLY=( $( compgen -W "--no-stream --help" -- "$cur" ) ) 1253 ;; 1254 *) 1255 __docker_containers_running 1256 ;; 1257 esac 1258 } 1259 1260 _docker_stop() { 1261 case "$prev" in 1262 --time|-t) 1263 return 1264 ;; 1265 esac 1266 1267 case "$cur" in 1268 -*) 1269 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 1270 ;; 1271 *) 1272 __docker_containers_running 1273 ;; 1274 esac 1275 } 1276 1277 _docker_tag() { 1278 case "$cur" in 1279 -*) 1280 COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) 1281 ;; 1282 *) 1283 local counter=$(__docker_pos_first_nonflag) 1284 1285 if [ $cword -eq $counter ]; then 1286 __docker_image_repos_and_tags 1287 return 1288 fi 1289 (( counter++ )) 1290 1291 if [ $cword -eq $counter ]; then 1292 __docker_image_repos_and_tags 1293 return 1294 fi 1295 ;; 1296 esac 1297 } 1298 1299 _docker_unpause() { 1300 case "$cur" in 1301 -*) 1302 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1303 ;; 1304 *) 1305 local counter=$(__docker_pos_first_nonflag) 1306 if [ $cword -eq $counter ]; then 1307 __docker_containers_unpauseable 1308 fi 1309 ;; 1310 esac 1311 } 1312 1313 _docker_top() { 1314 case "$cur" in 1315 -*) 1316 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1317 ;; 1318 *) 1319 local counter=$(__docker_pos_first_nonflag) 1320 if [ $cword -eq $counter ]; then 1321 __docker_containers_running 1322 fi 1323 ;; 1324 esac 1325 } 1326 1327 _docker_version() { 1328 case "$cur" in 1329 -*) 1330 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1331 ;; 1332 esac 1333 } 1334 1335 _docker_wait() { 1336 case "$cur" in 1337 -*) 1338 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1339 ;; 1340 *) 1341 __docker_containers_all 1342 ;; 1343 esac 1344 } 1345 1346 _docker() { 1347 local previous_extglob_setting=$(shopt -p extglob) 1348 shopt -s extglob 1349 1350 local commands=( 1351 attach 1352 build 1353 commit 1354 cp 1355 create 1356 daemon 1357 diff 1358 events 1359 exec 1360 export 1361 history 1362 images 1363 import 1364 info 1365 inspect 1366 kill 1367 load 1368 login 1369 logout 1370 logs 1371 pause 1372 port 1373 ps 1374 pull 1375 push 1376 rename 1377 restart 1378 rm 1379 rmi 1380 run 1381 save 1382 search 1383 start 1384 stats 1385 stop 1386 tag 1387 top 1388 unpause 1389 version 1390 wait 1391 ) 1392 1393 # These options are valid as global options for all client commands 1394 # and valid as command options for `docker daemon` 1395 local global_boolean_options=" 1396 --debug -D 1397 --tls 1398 --tlsverify 1399 " 1400 local global_options_with_args=" 1401 --config 1402 --host -H 1403 --log-level -l 1404 --tlscacert 1405 --tlscert 1406 --tlskey 1407 " 1408 1409 local host config 1410 1411 COMPREPLY=() 1412 local cur prev words cword 1413 _get_comp_words_by_ref -n : cur prev words cword 1414 1415 local command='docker' command_pos=0 1416 local counter=1 1417 while [ $counter -lt $cword ]; do 1418 case "${words[$counter]}" in 1419 # save host so that completion can use custom daemon 1420 --host|-H) 1421 (( counter++ )) 1422 host="${words[$counter]}" 1423 ;; 1424 # save config so that completion can use custom configuration directories 1425 --config) 1426 (( counter++ )) 1427 config="${words[$counter]}" 1428 ;; 1429 $(__docker_to_extglob "$global_options_with_args") ) 1430 (( counter++ )) 1431 ;; 1432 -*) 1433 ;; 1434 =) 1435 (( counter++ )) 1436 ;; 1437 *) 1438 command="${words[$counter]}" 1439 command_pos=$counter 1440 break 1441 ;; 1442 esac 1443 (( counter++ )) 1444 done 1445 1446 local completions_func=_docker_${command} 1447 declare -F $completions_func >/dev/null && $completions_func 1448 1449 eval "$previous_extglob_setting" 1450 return 0 1451 } 1452 1453 complete -F _docker docker