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