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