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