github.com/damirazo/docker@v1.9.0/contrib/completion/bash/docker (about) 1 #!/bin/bash 2 # 3 # bash completion file for core docker commands 4 # 5 # This script provides completion of: 6 # - commands and their options 7 # - container ids and names 8 # - image repos and tags 9 # - filepaths 10 # 11 # To enable the completions either: 12 # - place this file in /etc/bash_completion.d 13 # or 14 # - copy this file to e.g. ~/.docker-completion.sh and add the line 15 # below to your .bashrc after bash completion features are loaded 16 # . ~/.docker-completion.sh 17 # 18 # Configuration: 19 # 20 # You can tailor completion for the "events", "history", "inspect", "run", 21 # "rmi" and "save" commands by settings the following environment 22 # variables: 23 # 24 # DOCKER_COMPLETION_SHOW_IMAGE_IDS 25 # "none" - Show names only (default) 26 # "non-intermediate" - Show names and ids, but omit intermediate image IDs 27 # "all" - Show names and ids, including intermediate image IDs 28 # 29 # DOCKER_COMPLETION_SHOW_TAGS 30 # "yes" - include tags in completion options (default) 31 # "no" - don't include tags in completion options 32 33 # 34 # Note: 35 # Currently, the completions will not work if the docker daemon is not 36 # bound to the default communication port/socket 37 # If the docker daemon is using a unix socket for communication your user 38 # must have access to the socket for the completions to function correctly 39 # 40 # Note for developers: 41 # Please arrange options sorted alphabetically by long name with the short 42 # options immediately following their corresponding long form. 43 # This order should be applied to lists, alternatives and code blocks. 44 45 __docker_q() { 46 docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@" 47 } 48 49 __docker_containers_all() { 50 local IFS=$'\n' 51 local containers=( $(__docker_q ps -aq --no-trunc) ) 52 if [ "$1" ]; then 53 containers=( $(__docker_q inspect --format "{{if $1}}{{.Id}}{{end}}" "${containers[@]}") ) 54 fi 55 local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") ) 56 names=( "${names[@]#/}" ) # trim off the leading "/" from the container names 57 unset IFS 58 COMPREPLY=( $(compgen -W "${names[*]} ${containers[*]}" -- "$cur") ) 59 } 60 61 __docker_containers_running() { 62 __docker_containers_all '.State.Running' 63 } 64 65 __docker_containers_stopped() { 66 __docker_containers_all 'not .State.Running' 67 } 68 69 __docker_containers_pauseable() { 70 __docker_containers_all 'and .State.Running (not .State.Paused)' 71 } 72 73 __docker_containers_unpauseable() { 74 __docker_containers_all '.State.Paused' 75 } 76 77 __docker_container_names() { 78 local containers=( $(__docker_q ps -aq --no-trunc) ) 79 local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") ) 80 names=( "${names[@]#/}" ) # trim off the leading "/" from the container names 81 COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") ) 82 } 83 84 __docker_container_ids() { 85 local containers=( $(__docker_q ps -aq) ) 86 COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") ) 87 } 88 89 __docker_images() { 90 local images_args="" 91 92 case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in 93 all) 94 images_args="--no-trunc -a" 95 ;; 96 non-intermediate) 97 images_args="--no-trunc" 98 ;; 99 esac 100 101 local repo_print_command 102 if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then 103 repo_print_command='print $1; print $1":"$2' 104 else 105 repo_print_command='print $1' 106 fi 107 108 local awk_script 109 case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in 110 all|non-intermediate) 111 awk_script='NR>1 { print $3; if ($1 != "<none>") { '"$repo_print_command"' } }' 112 ;; 113 none|*) 114 awk_script='NR>1 && $1 != "<none>" { '"$repo_print_command"' }' 115 ;; 116 esac 117 118 local images=$(__docker_q images $images_args | awk "$awk_script") 119 COMPREPLY=( $(compgen -W "$images" -- "$cur") ) 120 __ltrim_colon_completions "$cur" 121 } 122 123 __docker_image_repos() { 124 local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')" 125 COMPREPLY=( $(compgen -W "$repos" -- "$cur") ) 126 } 127 128 __docker_image_repos_and_tags() { 129 local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')" 130 COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") ) 131 __ltrim_colon_completions "$cur" 132 } 133 134 __docker_containers_and_images() { 135 __docker_containers_all 136 local containers=( "${COMPREPLY[@]}" ) 137 __docker_images 138 COMPREPLY+=( "${containers[@]}" ) 139 } 140 141 __docker_networks() { 142 COMPREPLY=( $(compgen -W "$(__docker_q network ls | awk 'NR>1 {print $2}')" -- "$cur") ) 143 } 144 145 __docker_volumes() { 146 COMPREPLY=( $(compgen -W "$(__docker_q volume ls -q)" -- "$cur") ) 147 } 148 149 # Finds the position of the first word that is neither option nor an option's argument. 150 # If there are options that require arguments, you should pass a glob describing those 151 # options, e.g. "--option1|-o|--option2" 152 # Use this function to restrict completions to exact positions after the argument list. 153 __docker_pos_first_nonflag() { 154 local argument_flags=$1 155 156 local counter=$((${subcommand_pos:-${command_pos}} + 1)) 157 while [ $counter -le $cword ]; do 158 if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then 159 (( counter++ )) 160 # eat "=" in case of --option=arg syntax 161 [ "${words[$counter]}" = "=" ] && (( counter++ )) 162 else 163 case "${words[$counter]}" in 164 -*) 165 ;; 166 *) 167 break 168 ;; 169 esac 170 fi 171 172 # Bash splits words at "=", retaining "=" as a word, examples: 173 # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words 174 while [ "${words[$counter + 1]}" = "=" ] ; do 175 counter=$(( counter + 2)) 176 done 177 178 (( counter++ )) 179 done 180 181 echo $counter 182 } 183 184 # Returns the value of the first option matching option_glob. 185 # Valid values for option_glob are option names like '--log-level' and 186 # globs like '--log-level|-l' 187 # Only positions between the command and the current word are considered. 188 __docker_value_of_option() { 189 local option_extglob=$(__docker_to_extglob "$1") 190 191 local counter=$((command_pos + 1)) 192 while [ $counter -lt $cword ]; do 193 case ${words[$counter]} in 194 $option_extglob ) 195 echo ${words[$counter + 1]} 196 break 197 ;; 198 esac 199 (( counter++ )) 200 done 201 } 202 203 # Transforms a multiline list of strings into a single line string 204 # with the words separated by "|". 205 # This is used to prepare arguments to __docker_pos_first_nonflag(). 206 __docker_to_alternatives() { 207 local parts=( $1 ) 208 local IFS='|' 209 echo "${parts[*]}" 210 } 211 212 # Transforms a multiline list of options into an extglob pattern 213 # suitable for use in case statements. 214 __docker_to_extglob() { 215 local extglob=$( __docker_to_alternatives "$1" ) 216 echo "@($extglob)" 217 } 218 219 # Subcommand processing. 220 # Locates the first occurrence of any of the subcommands contained in the 221 # first argument. In case of a match, calls the corresponding completion 222 # function and returns 0. 223 # If no match is found, 1 is returned. The calling function can then 224 # continue processing its completion. 225 # 226 # TODO if the preceding command has options that accept arguments and an 227 # argument is equal ot one of the subcommands, this is falsely detected as 228 # a match. 229 __docker_subcommands() { 230 local subcommands="$1" 231 232 local counter=$(($command_pos + 1)) 233 while [ $counter -lt $cword ]; do 234 case "${words[$counter]}" in 235 $(__docker_to_extglob "$subcommands") ) 236 subcommand_pos=$counter 237 local subcommand=${words[$counter]} 238 local completions_func=_docker_${command}_${subcommand} 239 declare -F $completions_func >/dev/null && $completions_func 240 return 0 241 ;; 242 esac 243 (( counter++ )) 244 done 245 return 1 246 } 247 248 # suppress trailing whitespace 249 __docker_nospace() { 250 # compopt is not available in ancient bash versions 251 type compopt &>/dev/null && compopt -o nospace 252 } 253 254 __docker_resolve_hostname() { 255 command -v host >/dev/null 2>&1 || return 256 COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') ) 257 } 258 259 __docker_capabilities() { 260 # The list of capabilities is defined in types.go, ALL was added manually. 261 COMPREPLY=( $( compgen -W " 262 ALL 263 AUDIT_CONTROL 264 AUDIT_WRITE 265 AUDIT_READ 266 BLOCK_SUSPEND 267 CHOWN 268 DAC_OVERRIDE 269 DAC_READ_SEARCH 270 FOWNER 271 FSETID 272 IPC_LOCK 273 IPC_OWNER 274 KILL 275 LEASE 276 LINUX_IMMUTABLE 277 MAC_ADMIN 278 MAC_OVERRIDE 279 MKNOD 280 NET_ADMIN 281 NET_BIND_SERVICE 282 NET_BROADCAST 283 NET_RAW 284 SETFCAP 285 SETGID 286 SETPCAP 287 SETUID 288 SYS_ADMIN 289 SYS_BOOT 290 SYS_CHROOT 291 SYSLOG 292 SYS_MODULE 293 SYS_NICE 294 SYS_PACCT 295 SYS_PTRACE 296 SYS_RAWIO 297 SYS_RESOURCE 298 SYS_TIME 299 SYS_TTY_CONFIG 300 WAKE_ALARM 301 " -- "$cur" ) ) 302 } 303 304 __docker_log_drivers() { 305 COMPREPLY=( $( compgen -W " 306 awslogs 307 fluentd 308 gelf 309 journald 310 json-file 311 none 312 syslog 313 " -- "$cur" ) ) 314 } 315 316 __docker_log_driver_options() { 317 # see docs/reference/logging/index.md 318 local awslogs_options="awslogs-region awslogs-group awslogs-stream" 319 local fluentd_options="env fluentd-address labels tag" 320 local gelf_options="env gelf-address labels tag" 321 local journald_options="env labels" 322 local json_file_options="env labels max-file max-size" 323 local syslog_options="syslog-address syslog-facility tag" 324 325 local all_options="$fluentd_options $gelf_options $journald_options $json_file_options $syslog_options" 326 327 case $(__docker_value_of_option --log-driver) in 328 '') 329 COMPREPLY=( $( compgen -W "$all_options" -S = -- "$cur" ) ) 330 ;; 331 awslogs) 332 COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) ) 333 ;; 334 fluentd) 335 COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) ) 336 ;; 337 gelf) 338 COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) ) 339 ;; 340 journald) 341 COMPREPLY=( $( compgen -W "$journald_options" -S = -- "$cur" ) ) 342 ;; 343 json-file) 344 COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) ) 345 ;; 346 syslog) 347 COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) ) 348 ;; 349 *) 350 return 351 ;; 352 esac 353 354 __docker_nospace 355 } 356 357 __docker_complete_log_driver_options() { 358 # "=" gets parsed to a word and assigned to either $cur or $prev depending on whether 359 # it is the last character or not. So we search for "xxx=" in the the last two words. 360 case "${words[$cword-2]}$prev=" in 361 *gelf-address=*) 362 COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur#=}" ) ) 363 __docker_nospace 364 return 365 ;; 366 *syslog-address=*) 367 COMPREPLY=( $( compgen -W "tcp udp unix" -S "://" -- "${cur#=}" ) ) 368 __docker_nospace 369 return 370 ;; 371 *syslog-facility=*) 372 COMPREPLY=( $( compgen -W " 373 auth 374 authpriv 375 cron 376 daemon 377 ftp 378 kern 379 local0 380 local1 381 local2 382 local3 383 local4 384 local5 385 local6 386 local7 387 lpr 388 mail 389 news 390 syslog 391 user 392 uucp 393 " -- "${cur#=}" ) ) 394 return 395 ;; 396 esac 397 return 1 398 } 399 400 __docker_log_levels() { 401 COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) ) 402 } 403 404 # a selection of the available signals that is most likely of interest in the 405 # context of docker containers. 406 __docker_signals() { 407 local signals=( 408 SIGCONT 409 SIGHUP 410 SIGINT 411 SIGKILL 412 SIGQUIT 413 SIGSTOP 414 SIGTERM 415 SIGUSR1 416 SIGUSR2 417 ) 418 COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) ) 419 } 420 421 # global options that may appear after the docker command 422 _docker_docker() { 423 local boolean_options=" 424 $global_boolean_options 425 --help 426 --version -v 427 " 428 429 case "$prev" in 430 --config) 431 _filedir -d 432 return 433 ;; 434 --log-level|-l) 435 __docker_log_levels 436 return 437 ;; 438 $(__docker_to_extglob "$global_options_with_args") ) 439 return 440 ;; 441 esac 442 443 case "$cur" in 444 -*) 445 COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) ) 446 ;; 447 *) 448 local counter=$( __docker_pos_first_nonflag $(__docker_to_extglob "$global_options_with_args") ) 449 if [ $cword -eq $counter ]; then 450 COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) ) 451 fi 452 ;; 453 esac 454 } 455 456 _docker_attach() { 457 case "$cur" in 458 -*) 459 COMPREPLY=( $( compgen -W "--help --no-stdin --sig-proxy" -- "$cur" ) ) 460 ;; 461 *) 462 local counter="$(__docker_pos_first_nonflag)" 463 if [ $cword -eq $counter ]; then 464 __docker_containers_running 465 fi 466 ;; 467 esac 468 } 469 470 _docker_build() { 471 local options_with_args=" 472 --build-arg 473 --cgroup-parent 474 --cpuset-cpus 475 --cpuset-mems 476 --cpu-shares 477 --cpu-period 478 --cpu-quota 479 --file -f 480 --memory -m 481 --memory-swap 482 --tag -t 483 --ulimit 484 " 485 486 local boolean_options=" 487 --disable-content-trust=false 488 --force-rm 489 --help 490 --no-cache 491 --pull 492 --quiet -q 493 --rm 494 " 495 496 local all_options="$options_with_args $boolean_options" 497 498 case "$prev" in 499 --build-arg) 500 COMPREPLY=( $( compgen -e -- "$cur" ) ) 501 __docker_nospace 502 return 503 ;; 504 --file|-f) 505 _filedir 506 return 507 ;; 508 --tag|-t) 509 __docker_image_repos_and_tags 510 return 511 ;; 512 $(__docker_to_extglob "$options_with_args") ) 513 return 514 ;; 515 esac 516 517 case "$cur" in 518 -*) 519 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 520 ;; 521 *) 522 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 523 if [ $cword -eq $counter ]; then 524 _filedir -d 525 fi 526 ;; 527 esac 528 } 529 530 _docker_commit() { 531 case "$prev" in 532 --author|-a|--change|-c|--message|-m) 533 return 534 ;; 535 esac 536 537 case "$cur" in 538 -*) 539 COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause -p" -- "$cur" ) ) 540 ;; 541 *) 542 local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m') 543 544 if [ $cword -eq $counter ]; then 545 __docker_containers_all 546 return 547 fi 548 (( counter++ )) 549 550 if [ $cword -eq $counter ]; then 551 __docker_image_repos_and_tags 552 return 553 fi 554 ;; 555 esac 556 } 557 558 _docker_cp() { 559 case "$cur" in 560 -*) 561 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 562 ;; 563 *) 564 local counter=$(__docker_pos_first_nonflag) 565 if [ $cword -eq $counter ]; then 566 case "$cur" in 567 *:) 568 return 569 ;; 570 *) 571 # combined container and filename completion 572 _filedir 573 local files=( ${COMPREPLY[@]} ) 574 575 __docker_containers_all 576 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 577 local containers=( ${COMPREPLY[@]} ) 578 579 COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) ) 580 if [[ "$COMPREPLY" == *: ]]; then 581 __docker_nospace 582 fi 583 return 584 ;; 585 esac 586 fi 587 (( counter++ )) 588 589 if [ $cword -eq $counter ]; then 590 if [ -e "$prev" ]; then 591 __docker_containers_all 592 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 593 __docker_nospace 594 else 595 _filedir 596 fi 597 return 598 fi 599 ;; 600 esac 601 } 602 603 _docker_create() { 604 _docker_run 605 } 606 607 _docker_daemon() { 608 local boolean_options=" 609 $global_boolean_options 610 --disable-legacy-registry 611 --help 612 --icc=false 613 --ip-forward=false 614 --ip-masq=false 615 --iptables=false 616 --ipv6 617 --selinux-enabled 618 --userland-proxy=false 619 " 620 local options_with_args=" 621 $global_options_with_args 622 --api-cors-header 623 --bip 624 --bridge -b 625 --cluster-advertise 626 --cluster-store 627 --cluster-store-opt 628 --default-gateway 629 --default-gateway-v6 630 --default-ulimit 631 --dns 632 --dns-search 633 --dns-opt 634 --exec-driver -e 635 --exec-opt 636 --exec-root 637 --fixed-cidr 638 --fixed-cidr-v6 639 --graph -g 640 --group -G 641 --insecure-registry 642 --ip 643 --label 644 --log-driver 645 --log-opt 646 --mtu 647 --pidfile -p 648 --registry-mirror 649 --storage-driver -s 650 --storage-opt 651 " 652 653 case "$prev" in 654 --cluster-store) 655 COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) ) 656 __docker_nospace 657 return 658 ;; 659 --cluster-store-opt) 660 COMPREPLY=( $( compgen -W "kv.cacertfile kv.certfile kv.keyfile" -S = -- "$cur" ) ) 661 __docker_nospace 662 return 663 ;; 664 --exec-root|--graph|-g) 665 _filedir -d 666 return 667 ;; 668 --log-driver) 669 __docker_log_drivers 670 return 671 ;; 672 --pidfile|-p|--tlscacert|--tlscert|--tlskey) 673 _filedir 674 return 675 ;; 676 --storage-driver|-s) 677 COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) ) 678 return 679 ;; 680 --storage-opt) 681 local devicemapper_options=" 682 dm.basesize 683 dm.blkdiscard 684 dm.blocksize 685 dm.fs 686 dm.loopdatasize 687 dm.loopmetadatasize 688 dm.mkfsarg 689 dm.mountopt 690 dm.override_udev_sync_check 691 dm.thinpooldev 692 dm.use_deferred_deletion 693 dm.use_deferred_removal 694 " 695 local zfs_options="zfs.fsname" 696 697 case $(__docker_value_of_option '--storage-driver|-s') in 698 '') 699 COMPREPLY=( $( compgen -W "$devicemapper_options $zfs_options" -S = -- "$cur" ) ) 700 ;; 701 devicemapper) 702 COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) ) 703 ;; 704 zfs) 705 COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) ) 706 ;; 707 *) 708 return 709 ;; 710 esac 711 __docker_nospace 712 return 713 ;; 714 --log-level|-l) 715 __docker_log_levels 716 return 717 ;; 718 --log-opt) 719 __docker_log_driver_options 720 return 721 ;; 722 $(__docker_to_extglob "$options_with_args") ) 723 return 724 ;; 725 esac 726 727 __docker_complete_log_driver_options && return 728 729 case "${words[$cword-2]}$prev=" in 730 # completions for --storage-opt 731 *dm.@(blkdiscard|override_udev_sync_check|use_deferred_@(removal|deletion))=*) 732 COMPREPLY=( $( compgen -W "false true" -- "${cur#=}" ) ) 733 return 734 ;; 735 *dm.fs=*) 736 COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur#=}" ) ) 737 return 738 ;; 739 *dm.thinpooldev=*) 740 _filedir 741 return 742 ;; 743 # completions for --cluster-store-opt 744 *kv.*file=*) 745 _filedir 746 return 747 ;; 748 esac 749 750 case "$cur" in 751 -*) 752 COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) 753 ;; 754 esac 755 } 756 757 _docker_diff() { 758 case "$cur" in 759 -*) 760 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 761 ;; 762 *) 763 local counter=$(__docker_pos_first_nonflag) 764 if [ $cword -eq $counter ]; then 765 __docker_containers_all 766 fi 767 ;; 768 esac 769 } 770 771 _docker_events() { 772 case "$prev" in 773 --filter|-f) 774 COMPREPLY=( $( compgen -S = -W "container event image" -- "$cur" ) ) 775 __docker_nospace 776 return 777 ;; 778 --since|--until) 779 return 780 ;; 781 esac 782 783 case "${words[$cword-2]}$prev=" in 784 *container=*) 785 cur="${cur#=}" 786 __docker_containers_all 787 return 788 ;; 789 *event=*) 790 COMPREPLY=( $( compgen -W " 791 attach 792 commit 793 copy 794 create 795 delete 796 destroy 797 die 798 exec_create 799 exec_start 800 export 801 import 802 kill 803 oom 804 pause 805 pull 806 push 807 rename 808 resize 809 restart 810 start 811 stop 812 tag 813 top 814 unpause 815 untag 816 " -- "${cur#=}" ) ) 817 return 818 ;; 819 *image=*) 820 cur="${cur#=}" 821 __docker_images 822 return 823 ;; 824 esac 825 826 case "$cur" in 827 -*) 828 COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) ) 829 ;; 830 esac 831 } 832 833 _docker_exec() { 834 case "$prev" in 835 --user|-u) 836 return 837 ;; 838 esac 839 840 case "$cur" in 841 -*) 842 COMPREPLY=( $( compgen -W "--detach -d --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) ) 843 ;; 844 *) 845 __docker_containers_running 846 ;; 847 esac 848 } 849 850 _docker_export() { 851 case "$cur" in 852 -*) 853 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 854 ;; 855 *) 856 local counter=$(__docker_pos_first_nonflag) 857 if [ $cword -eq $counter ]; then 858 __docker_containers_all 859 fi 860 ;; 861 esac 862 } 863 864 _docker_help() { 865 local counter=$(__docker_pos_first_nonflag) 866 if [ $cword -eq $counter ]; then 867 COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) ) 868 fi 869 } 870 871 _docker_history() { 872 case "$cur" in 873 -*) 874 COMPREPLY=( $( compgen -W "--help --no-trunc --quiet -q" -- "$cur" ) ) 875 ;; 876 *) 877 local counter=$(__docker_pos_first_nonflag) 878 if [ $cword -eq $counter ]; then 879 __docker_images 880 fi 881 ;; 882 esac 883 } 884 885 _docker_images() { 886 case "$prev" in 887 --filter|-f) 888 COMPREPLY=( $( compgen -W "dangling=true label=" -- "$cur" ) ) 889 if [ "$COMPREPLY" = "label=" ]; then 890 __docker_nospace 891 fi 892 return 893 ;; 894 esac 895 896 case "${words[$cword-2]}$prev=" in 897 *dangling=*) 898 COMPREPLY=( $( compgen -W "true false" -- "${cur#=}" ) ) 899 return 900 ;; 901 *label=*) 902 return 903 ;; 904 esac 905 906 case "$cur" in 907 -*) 908 COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --help --no-trunc --quiet -q" -- "$cur" ) ) 909 ;; 910 =) 911 return 912 ;; 913 *) 914 __docker_image_repos 915 ;; 916 esac 917 } 918 919 _docker_import() { 920 case "$prev" in 921 --change|-c|--message|-m) 922 return 923 ;; 924 esac 925 926 case "$cur" in 927 -*) 928 COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) ) 929 ;; 930 *) 931 local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m') 932 if [ $cword -eq $counter ]; then 933 return 934 fi 935 (( counter++ )) 936 937 if [ $cword -eq $counter ]; then 938 __docker_image_repos_and_tags 939 return 940 fi 941 ;; 942 esac 943 } 944 945 _docker_info() { 946 case "$cur" in 947 -*) 948 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 949 ;; 950 esac 951 } 952 953 _docker_inspect() { 954 case "$prev" in 955 --format|-f) 956 return 957 ;; 958 --type) 959 COMPREPLY=( $( compgen -W "image container" -- "$cur" ) ) 960 return 961 ;; 962 963 esac 964 965 case "$cur" in 966 -*) 967 COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) ) 968 ;; 969 *) 970 case $(__docker_value_of_option --type) in 971 '') 972 __docker_containers_and_images 973 ;; 974 container) 975 __docker_containers_all 976 ;; 977 image) 978 __docker_images 979 ;; 980 esac 981 esac 982 } 983 984 _docker_kill() { 985 case "$prev" in 986 --signal|-s) 987 __docker_signals 988 return 989 ;; 990 esac 991 992 case "$cur" in 993 -*) 994 COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) ) 995 ;; 996 *) 997 __docker_containers_running 998 ;; 999 esac 1000 } 1001 1002 _docker_load() { 1003 case "$prev" in 1004 --input|-i) 1005 _filedir 1006 return 1007 ;; 1008 esac 1009 1010 case "$cur" in 1011 -*) 1012 COMPREPLY=( $( compgen -W "--help --input -i" -- "$cur" ) ) 1013 ;; 1014 esac 1015 } 1016 1017 _docker_login() { 1018 case "$prev" in 1019 --email|-e|--password|-p|--username|-u) 1020 return 1021 ;; 1022 esac 1023 1024 case "$cur" in 1025 -*) 1026 COMPREPLY=( $( compgen -W "--email -e --help --password -p --username -u" -- "$cur" ) ) 1027 ;; 1028 esac 1029 } 1030 1031 _docker_logout() { 1032 case "$cur" in 1033 -*) 1034 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1035 ;; 1036 esac 1037 } 1038 1039 _docker_logs() { 1040 case "$prev" in 1041 --since|--tail) 1042 return 1043 ;; 1044 esac 1045 1046 case "$cur" in 1047 -*) 1048 COMPREPLY=( $( compgen -W "--follow -f --help --since --tail --timestamps -t" -- "$cur" ) ) 1049 ;; 1050 *) 1051 local counter=$(__docker_pos_first_nonflag '--tail') 1052 if [ $cword -eq $counter ]; then 1053 __docker_containers_all 1054 fi 1055 ;; 1056 esac 1057 } 1058 1059 _docker_network_connect() { 1060 case "$cur" in 1061 -*) 1062 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1063 ;; 1064 *) 1065 local counter=$(__docker_pos_first_nonflag '--tail') 1066 if [ $cword -eq $counter ]; then 1067 __docker_networks 1068 elif [ $cword -eq $(($counter + 1)) ]; then 1069 __docker_containers_running 1070 fi 1071 ;; 1072 esac 1073 } 1074 1075 _docker_network_create() { 1076 case "$prev" in 1077 --aux-address|--gateway|--ip-range|--opt|-o|--subnet) 1078 return 1079 ;; 1080 --ipam-driver) 1081 COMPREPLY=( $( compgen -W "default" -- "$cur" ) ) 1082 return 1083 ;; 1084 --driver|-d) 1085 # no need to suggest drivers that allow one instance only 1086 # (host, null) 1087 COMPREPLY=( $( compgen -W "bridge overlay" -- "$cur" ) ) 1088 return 1089 ;; 1090 esac 1091 1092 case "$cur" in 1093 -*) 1094 COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --ip-range --ipam-driver --opt -o --subnet" -- "$cur" ) ) 1095 ;; 1096 esac 1097 } 1098 1099 _docker_network_disconnect() { 1100 # TODO disconnect should only complete running containers connected 1101 # to the specified network. 1102 _docker_network_connect 1103 } 1104 1105 _docker_network_inspect() { 1106 case "$cur" in 1107 -*) 1108 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1109 ;; 1110 *) 1111 __docker_networks 1112 esac 1113 } 1114 1115 _docker_network_ls() { 1116 case "$prev" in 1117 -n) 1118 return 1119 ;; 1120 esac 1121 1122 case "$cur" in 1123 -*) 1124 COMPREPLY=( $( compgen -W "--help --no-trunc --quiet -q" -- "$cur" ) ) 1125 ;; 1126 esac 1127 } 1128 1129 _docker_network_rm() { 1130 _docker_network_inspect 1131 } 1132 1133 _docker_network() { 1134 local subcommands=" 1135 connect 1136 create 1137 disconnect 1138 inspect 1139 ls 1140 rm 1141 " 1142 __docker_subcommands "$subcommands" && return 1143 1144 case "$cur" in 1145 -*) 1146 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1147 ;; 1148 *) 1149 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 1150 ;; 1151 esac 1152 } 1153 1154 _docker_pause() { 1155 case "$cur" in 1156 -*) 1157 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1158 ;; 1159 *) 1160 local counter=$(__docker_pos_first_nonflag) 1161 if [ $cword -eq $counter ]; then 1162 __docker_containers_pauseable 1163 fi 1164 ;; 1165 esac 1166 } 1167 1168 _docker_port() { 1169 case "$cur" in 1170 -*) 1171 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1172 ;; 1173 *) 1174 local counter=$(__docker_pos_first_nonflag) 1175 if [ $cword -eq $counter ]; then 1176 __docker_containers_all 1177 fi 1178 ;; 1179 esac 1180 } 1181 1182 _docker_ps() { 1183 case "$prev" in 1184 --before|--since) 1185 __docker_containers_all 1186 ;; 1187 --filter|-f) 1188 COMPREPLY=( $( compgen -S = -W "ancestor exited id label name status" -- "$cur" ) ) 1189 __docker_nospace 1190 return 1191 ;; 1192 --format|-n) 1193 return 1194 ;; 1195 esac 1196 1197 case "${words[$cword-2]}$prev=" in 1198 *ancestor=*) 1199 cur="${cur#=}" 1200 __docker_images 1201 return 1202 ;; 1203 *id=*) 1204 cur="${cur#=}" 1205 __docker_container_ids 1206 return 1207 ;; 1208 *name=*) 1209 cur="${cur#=}" 1210 __docker_container_names 1211 return 1212 ;; 1213 *status=*) 1214 COMPREPLY=( $( compgen -W "exited paused restarting running" -- "${cur#=}" ) ) 1215 return 1216 ;; 1217 esac 1218 1219 case "$cur" in 1220 -*) 1221 COMPREPLY=( $( compgen -W "--all -a --before --filter -f --format --help --latest -l -n --no-trunc --quiet -q --size -s --since" -- "$cur" ) ) 1222 ;; 1223 esac 1224 } 1225 1226 _docker_pull() { 1227 case "$cur" in 1228 -*) 1229 COMPREPLY=( $( compgen -W "--all-tags -a --help" -- "$cur" ) ) 1230 ;; 1231 *) 1232 local counter=$(__docker_pos_first_nonflag) 1233 if [ $cword -eq $counter ]; then 1234 for arg in "${COMP_WORDS[@]}"; do 1235 case "$arg" in 1236 --all-tags|-a) 1237 __docker_image_repos 1238 return 1239 ;; 1240 esac 1241 done 1242 __docker_image_repos_and_tags 1243 fi 1244 ;; 1245 esac 1246 } 1247 1248 _docker_push() { 1249 case "$cur" in 1250 -*) 1251 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1252 ;; 1253 *) 1254 local counter=$(__docker_pos_first_nonflag) 1255 if [ $cword -eq $counter ]; then 1256 __docker_image_repos_and_tags 1257 fi 1258 ;; 1259 esac 1260 } 1261 1262 _docker_rename() { 1263 case "$cur" in 1264 -*) 1265 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1266 ;; 1267 *) 1268 local counter=$(__docker_pos_first_nonflag) 1269 if [ $cword -eq $counter ]; then 1270 __docker_containers_all 1271 fi 1272 ;; 1273 esac 1274 } 1275 1276 _docker_restart() { 1277 case "$prev" in 1278 --time|-t) 1279 return 1280 ;; 1281 esac 1282 1283 case "$cur" in 1284 -*) 1285 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 1286 ;; 1287 *) 1288 __docker_containers_all 1289 ;; 1290 esac 1291 } 1292 1293 _docker_rm() { 1294 case "$cur" in 1295 -*) 1296 COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) ) 1297 ;; 1298 *) 1299 for arg in "${COMP_WORDS[@]}"; do 1300 case "$arg" in 1301 --force|-f) 1302 __docker_containers_all 1303 return 1304 ;; 1305 esac 1306 done 1307 __docker_containers_stopped 1308 ;; 1309 esac 1310 } 1311 1312 _docker_rmi() { 1313 case "$cur" in 1314 -*) 1315 COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) ) 1316 ;; 1317 *) 1318 __docker_images 1319 ;; 1320 esac 1321 } 1322 1323 _docker_run() { 1324 local options_with_args=" 1325 --add-host 1326 --attach -a 1327 --blkio-weight 1328 --cap-add 1329 --cap-drop 1330 --cgroup-parent 1331 --cidfile 1332 --cpu-period 1333 --cpu-quota 1334 --cpuset-cpus 1335 --cpuset-mems 1336 --cpu-shares 1337 --device 1338 --dns 1339 --dns-opt 1340 --dns-search 1341 --entrypoint 1342 --env -e 1343 --env-file 1344 --expose 1345 --group-add 1346 --hostname -h 1347 --ipc 1348 --kernel-memory 1349 --label-file 1350 --label -l 1351 --link 1352 --log-driver 1353 --log-opt 1354 --lxc-conf 1355 --mac-address 1356 --memory -m 1357 --memory-swap 1358 --memory-swappiness 1359 --memory-reservation 1360 --name 1361 --net 1362 --pid 1363 --publish -p 1364 --restart 1365 --security-opt 1366 --stop-signal 1367 --ulimit 1368 --user -u 1369 --uts 1370 --volumes-from 1371 --volume -v 1372 --workdir -w 1373 " 1374 1375 local boolean_options=" 1376 --disable-content-trust=false 1377 --help 1378 --interactive -i 1379 --oom-kill-disable 1380 --privileged 1381 --publish-all -P 1382 --read-only 1383 --tty -t 1384 " 1385 1386 local all_options="$options_with_args $boolean_options" 1387 1388 [ "$command" = "run" ] && all_options="$all_options 1389 --detach -d 1390 --rm 1391 --sig-proxy=false 1392 " 1393 1394 case "$prev" in 1395 --add-host) 1396 case "$cur" in 1397 *:) 1398 __docker_resolve_hostname 1399 return 1400 ;; 1401 esac 1402 ;; 1403 --attach|-a) 1404 COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) ) 1405 return 1406 ;; 1407 --cap-add|--cap-drop) 1408 __docker_capabilities 1409 return 1410 ;; 1411 --cidfile|--env-file|--label-file) 1412 _filedir 1413 return 1414 ;; 1415 --device|--volume|-v) 1416 case "$cur" in 1417 *:*) 1418 # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) 1419 ;; 1420 '') 1421 COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) 1422 __docker_nospace 1423 ;; 1424 /*) 1425 _filedir 1426 __docker_nospace 1427 ;; 1428 esac 1429 return 1430 ;; 1431 --env|-e) 1432 COMPREPLY=( $( compgen -e -- "$cur" ) ) 1433 __docker_nospace 1434 return 1435 ;; 1436 --ipc) 1437 case "$cur" in 1438 *:*) 1439 cur="${cur#*:}" 1440 __docker_containers_running 1441 ;; 1442 *) 1443 COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) ) 1444 if [ "$COMPREPLY" = "container:" ]; then 1445 __docker_nospace 1446 fi 1447 ;; 1448 esac 1449 return 1450 ;; 1451 --link) 1452 case "$cur" in 1453 *:*) 1454 ;; 1455 *) 1456 __docker_containers_running 1457 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 1458 __docker_nospace 1459 ;; 1460 esac 1461 return 1462 ;; 1463 --log-driver) 1464 __docker_log_drivers 1465 return 1466 ;; 1467 --log-opt) 1468 __docker_log_driver_options 1469 return 1470 ;; 1471 --net) 1472 case "$cur" in 1473 container:*) 1474 local cur=${cur#*:} 1475 __docker_containers_all 1476 ;; 1477 *) 1478 COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") ) 1479 if [ "${COMPREPLY[*]}" = "container:" ] ; then 1480 __docker_nospace 1481 fi 1482 ;; 1483 esac 1484 return 1485 ;; 1486 --restart) 1487 case "$cur" in 1488 on-failure:*) 1489 ;; 1490 *) 1491 COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") ) 1492 ;; 1493 esac 1494 return 1495 ;; 1496 --security-opt) 1497 case "$cur" in 1498 label:*:*) 1499 ;; 1500 label:*) 1501 local cur=${cur##*:} 1502 COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") ) 1503 if [ "${COMPREPLY[*]}" != "disable" ] ; then 1504 __docker_nospace 1505 fi 1506 ;; 1507 *) 1508 COMPREPLY=( $( compgen -W "label apparmor" -S ":" -- "$cur") ) 1509 __docker_nospace 1510 ;; 1511 esac 1512 return 1513 ;; 1514 --volumes-from) 1515 __docker_containers_all 1516 return 1517 ;; 1518 $(__docker_to_extglob "$options_with_args") ) 1519 return 1520 ;; 1521 esac 1522 1523 __docker_complete_log_driver_options && return 1524 1525 case "$cur" in 1526 -*) 1527 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 1528 ;; 1529 *) 1530 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 1531 if [ $cword -eq $counter ]; then 1532 __docker_images 1533 fi 1534 ;; 1535 esac 1536 } 1537 1538 _docker_save() { 1539 case "$prev" in 1540 --output|-o) 1541 _filedir 1542 return 1543 ;; 1544 esac 1545 1546 case "$cur" in 1547 -*) 1548 COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) ) 1549 ;; 1550 *) 1551 __docker_images 1552 ;; 1553 esac 1554 } 1555 1556 _docker_search() { 1557 case "$prev" in 1558 --stars|-s) 1559 return 1560 ;; 1561 esac 1562 1563 case "$cur" in 1564 -*) 1565 COMPREPLY=( $( compgen -W "--automated --help --no-trunc --stars -s" -- "$cur" ) ) 1566 ;; 1567 esac 1568 } 1569 1570 _docker_start() { 1571 case "$cur" in 1572 -*) 1573 COMPREPLY=( $( compgen -W "--attach -a --help --interactive -i" -- "$cur" ) ) 1574 ;; 1575 *) 1576 __docker_containers_stopped 1577 ;; 1578 esac 1579 } 1580 1581 _docker_stats() { 1582 case "$cur" in 1583 -*) 1584 COMPREPLY=( $( compgen -W "--no-stream --help" -- "$cur" ) ) 1585 ;; 1586 *) 1587 __docker_containers_running 1588 ;; 1589 esac 1590 } 1591 1592 _docker_stop() { 1593 case "$prev" in 1594 --time|-t) 1595 return 1596 ;; 1597 esac 1598 1599 case "$cur" in 1600 -*) 1601 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 1602 ;; 1603 *) 1604 __docker_containers_running 1605 ;; 1606 esac 1607 } 1608 1609 _docker_tag() { 1610 case "$cur" in 1611 -*) 1612 COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) 1613 ;; 1614 *) 1615 local counter=$(__docker_pos_first_nonflag) 1616 1617 if [ $cword -eq $counter ]; then 1618 __docker_image_repos_and_tags 1619 return 1620 fi 1621 (( counter++ )) 1622 1623 if [ $cword -eq $counter ]; then 1624 __docker_image_repos_and_tags 1625 return 1626 fi 1627 ;; 1628 esac 1629 } 1630 1631 _docker_unpause() { 1632 case "$cur" in 1633 -*) 1634 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1635 ;; 1636 *) 1637 local counter=$(__docker_pos_first_nonflag) 1638 if [ $cword -eq $counter ]; then 1639 __docker_containers_unpauseable 1640 fi 1641 ;; 1642 esac 1643 } 1644 1645 _docker_top() { 1646 case "$cur" in 1647 -*) 1648 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1649 ;; 1650 *) 1651 local counter=$(__docker_pos_first_nonflag) 1652 if [ $cword -eq $counter ]; then 1653 __docker_containers_running 1654 fi 1655 ;; 1656 esac 1657 } 1658 1659 _docker_version() { 1660 case "$cur" in 1661 -*) 1662 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1663 ;; 1664 esac 1665 } 1666 1667 _docker_volume_create() { 1668 case "$prev" in 1669 --driver|-d) 1670 COMPREPLY=( $( compgen -W "local" -- "$cur" ) ) 1671 return 1672 ;; 1673 --name|--opt|-o) 1674 return 1675 ;; 1676 esac 1677 1678 case "$cur" in 1679 -*) 1680 COMPREPLY=( $( compgen -W "--driver -d --help --name --opt -o" -- "$cur" ) ) 1681 ;; 1682 esac 1683 } 1684 1685 _docker_volume_inspect() { 1686 case "$prev" in 1687 --format|-f) 1688 return 1689 ;; 1690 esac 1691 1692 case "$cur" in 1693 -*) 1694 COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) 1695 ;; 1696 *) 1697 __docker_volumes 1698 ;; 1699 esac 1700 } 1701 1702 _docker_volume_ls() { 1703 case "$prev" in 1704 --filter|-f) 1705 COMPREPLY=( $( compgen -W "dangling=true" -- "$cur" ) ) 1706 return 1707 ;; 1708 esac 1709 1710 case "$cur" in 1711 -*) 1712 COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) ) 1713 ;; 1714 esac 1715 } 1716 1717 _docker_volume_rm() { 1718 case "$cur" in 1719 -*) 1720 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1721 ;; 1722 *) 1723 __docker_volumes 1724 ;; 1725 esac 1726 } 1727 1728 _docker_volume() { 1729 local subcommands=" 1730 create 1731 inspect 1732 ls 1733 rm 1734 " 1735 __docker_subcommands "$subcommands" && return 1736 1737 case "$cur" in 1738 -*) 1739 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1740 ;; 1741 *) 1742 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 1743 ;; 1744 esac 1745 } 1746 1747 _docker_wait() { 1748 case "$cur" in 1749 -*) 1750 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1751 ;; 1752 *) 1753 __docker_containers_all 1754 ;; 1755 esac 1756 } 1757 1758 _docker() { 1759 local previous_extglob_setting=$(shopt -p extglob) 1760 shopt -s extglob 1761 1762 local commands=( 1763 attach 1764 build 1765 commit 1766 cp 1767 create 1768 daemon 1769 diff 1770 events 1771 exec 1772 export 1773 history 1774 images 1775 import 1776 info 1777 inspect 1778 kill 1779 load 1780 login 1781 logout 1782 logs 1783 network 1784 pause 1785 port 1786 ps 1787 pull 1788 push 1789 rename 1790 restart 1791 rm 1792 rmi 1793 run 1794 save 1795 search 1796 start 1797 stats 1798 stop 1799 tag 1800 top 1801 unpause 1802 version 1803 volume 1804 wait 1805 ) 1806 1807 # These options are valid as global options for all client commands 1808 # and valid as command options for `docker daemon` 1809 local global_boolean_options=" 1810 --debug -D 1811 --tls 1812 --tlsverify 1813 " 1814 local global_options_with_args=" 1815 --config 1816 --host -H 1817 --log-level -l 1818 --tlscacert 1819 --tlscert 1820 --tlskey 1821 " 1822 1823 local host config 1824 1825 COMPREPLY=() 1826 local cur prev words cword 1827 _get_comp_words_by_ref -n : cur prev words cword 1828 1829 local command='docker' command_pos=0 subcommand_pos 1830 local counter=1 1831 while [ $counter -lt $cword ]; do 1832 case "${words[$counter]}" in 1833 # save host so that completion can use custom daemon 1834 --host|-H) 1835 (( counter++ )) 1836 host="${words[$counter]}" 1837 ;; 1838 # save config so that completion can use custom configuration directories 1839 --config) 1840 (( counter++ )) 1841 config="${words[$counter]}" 1842 ;; 1843 $(__docker_to_extglob "$global_options_with_args") ) 1844 (( counter++ )) 1845 ;; 1846 -*) 1847 ;; 1848 =) 1849 (( counter++ )) 1850 ;; 1851 *) 1852 command="${words[$counter]}" 1853 command_pos=$counter 1854 break 1855 ;; 1856 esac 1857 (( counter++ )) 1858 done 1859 1860 local completions_func=_docker_${command} 1861 declare -F $completions_func >/dev/null && $completions_func 1862 1863 eval "$previous_extglob_setting" 1864 return 0 1865 } 1866 1867 complete -F _docker docker