github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/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 # DOCKER_COMPLETION_SHOW_NODE_IDS 25 # DOCKER_COMPLETION_SHOW_SERVICE_IDS 26 # "no" - Show names only (default) 27 # "yes" - Show names and ids 28 # 29 # You can tailor completion for the "events", "history", "inspect", "run", 30 # "rmi" and "save" commands by settings the following environment 31 # variables: 32 # 33 # DOCKER_COMPLETION_SHOW_IMAGE_IDS 34 # "none" - Show names only (default) 35 # "non-intermediate" - Show names and ids, but omit intermediate image IDs 36 # "all" - Show names and ids, including intermediate image IDs 37 # 38 # DOCKER_COMPLETION_SHOW_TAGS 39 # "yes" - include tags in completion options (default) 40 # "no" - don't include tags in completion options 41 42 # 43 # Note: 44 # Currently, the completions will not work if the docker daemon is not 45 # bound to the default communication port/socket 46 # If the docker daemon is using a unix socket for communication your user 47 # must have access to the socket for the completions to function correctly 48 # 49 # Note for developers: 50 # Please arrange options sorted alphabetically by long name with the short 51 # options immediately following their corresponding long form. 52 # This order should be applied to lists, alternatives and code blocks. 53 54 __docker_previous_extglob_setting=$(shopt -p extglob) 55 shopt -s extglob 56 57 __docker_q() { 58 docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@" 59 } 60 61 __docker_complete_containers_all() { 62 local IFS=$'\n' 63 local containers=( $(__docker_q ps -aq --no-trunc) ) 64 if [ "$1" ]; then 65 containers=( $(__docker_q inspect --format "{{if $1}}{{.Id}}{{end}}" "${containers[@]}") ) 66 fi 67 local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") ) 68 names=( "${names[@]#/}" ) # trim off the leading "/" from the container names 69 unset IFS 70 COMPREPLY=( $(compgen -W "${names[*]} ${containers[*]}" -- "$cur") ) 71 } 72 73 __docker_complete_containers_running() { 74 __docker_complete_containers_all '.State.Running' 75 } 76 77 __docker_complete_containers_stopped() { 78 __docker_complete_containers_all 'not .State.Running' 79 } 80 81 __docker_complete_containers_pauseable() { 82 __docker_complete_containers_all 'and .State.Running (not .State.Paused)' 83 } 84 85 __docker_complete_containers_unpauseable() { 86 __docker_complete_containers_all '.State.Paused' 87 } 88 89 __docker_complete_container_names() { 90 local containers=( $(__docker_q ps -aq --no-trunc) ) 91 local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") ) 92 names=( "${names[@]#/}" ) # trim off the leading "/" from the container names 93 COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") ) 94 } 95 96 __docker_complete_container_ids() { 97 local containers=( $(__docker_q ps -aq) ) 98 COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") ) 99 } 100 101 __docker_complete_images() { 102 local images_args="" 103 104 case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in 105 all) 106 images_args="--no-trunc -a" 107 ;; 108 non-intermediate) 109 images_args="--no-trunc" 110 ;; 111 esac 112 113 local repo_print_command 114 if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then 115 repo_print_command='print $1; print $1":"$2' 116 else 117 repo_print_command='print $1' 118 fi 119 120 local awk_script 121 case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in 122 all|non-intermediate) 123 awk_script='NR>1 { print $3; if ($1 != "<none>") { '"$repo_print_command"' } }' 124 ;; 125 none|*) 126 awk_script='NR>1 && $1 != "<none>" { '"$repo_print_command"' }' 127 ;; 128 esac 129 130 local images=$(__docker_q images $images_args | awk "$awk_script") 131 COMPREPLY=( $(compgen -W "$images" -- "$cur") ) 132 __ltrim_colon_completions "$cur" 133 } 134 135 __docker_complete_image_repos() { 136 local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')" 137 COMPREPLY=( $(compgen -W "$repos" -- "$cur") ) 138 } 139 140 __docker_complete_image_repos_and_tags() { 141 local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')" 142 COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") ) 143 __ltrim_colon_completions "$cur" 144 } 145 146 __docker_complete_containers_and_images() { 147 __docker_complete_containers_all 148 local containers=( "${COMPREPLY[@]}" ) 149 __docker_complete_images 150 COMPREPLY+=( "${containers[@]}" ) 151 } 152 153 # Returns the names and optionally IDs of networks. 154 # The selection can be narrowed by an optional filter parameter, e.g. 'type=custom' 155 __docker_networks() { 156 local filter="$1" 157 # By default, only network names are completed. 158 # Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete network IDs. 159 local fields='$2' 160 [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] && fields='$1,$2' 161 __docker_q network ls --no-trunc ${filter:+-f "$filter"} | awk "NR>1 {print $fields}" 162 #__docker_q network ls --no-trunc | awk "NR>1 {print $fields}" 163 } 164 165 __docker_complete_networks() { 166 COMPREPLY=( $(compgen -W "$(__docker_networks $@)" -- "$cur") ) 167 } 168 169 __docker_complete_network_ids() { 170 COMPREPLY=( $(compgen -W "$(__docker_q network ls -q --no-trunc)" -- "$cur") ) 171 } 172 173 __docker_complete_network_names() { 174 COMPREPLY=( $(compgen -W "$(__docker_q network ls | awk 'NR>1 {print $2}')" -- "$cur") ) 175 } 176 177 __docker_complete_containers_in_network() { 178 local containers=$(__docker_q network inspect -f '{{range $i, $c := .Containers}}{{$i}} {{$c.Name}} {{end}}' "$1") 179 COMPREPLY=( $(compgen -W "$containers" -- "$cur") ) 180 } 181 182 __docker_complete_volumes() { 183 COMPREPLY=( $(compgen -W "$(__docker_q volume ls -q)" -- "$cur") ) 184 } 185 186 __docker_plugins() { 187 __docker_q info | sed -n "/^Plugins/,/^[^ ]/s/ $1: //p" 188 } 189 190 __docker_complete_plugins() { 191 COMPREPLY=( $(compgen -W "$(__docker_plugins $1)" -- "$cur") ) 192 } 193 194 __docker_runtimes() { 195 __docker_q info | sed -n 's/^Runtimes: \(.*\)/\1/p' 196 } 197 198 __docker_complete_runtimes() { 199 COMPREPLY=( $(compgen -W "$(__docker_runtimes)" -- "$cur") ) 200 } 201 202 # Returns a list of all nodes. Additional arguments to `docker node` 203 # may be specified in order to filter the node list, e.g. 204 # `__docker_nodes --filter role=manager` 205 # By default, only node names are completed. 206 # Set DOCKER_COMPLETION_SHOW_NODE_IDS=yes to also complete node IDs. 207 # An optional first argument `--id|--name` may be used to limit 208 # the output to the IDs or names of matching nodes. This setting takes 209 # precedence over the environment setting. 210 __docker_nodes() { 211 local fields='$2' # default: node name only 212 [ "${DOCKER_COMPLETION_SHOW_NODE_IDS}" = yes ] && fields='$1,$2' # ID and name 213 214 if [ "$1" = "--id" ] ; then 215 fields='$1' # IDs only 216 shift 217 elif [ "$1" = "--name" ] ; then 218 fields='$2' # names only 219 shift 220 fi 221 __docker_q node ls "$@" | tr -d '*' | awk "NR>1 {print $fields}" 222 } 223 224 # Applies completion of nodes based on the current value of `$cur` or 225 # the value of the optional first argument `--cur`, if given. 226 # Additional filters may be appended, see `__docker_nodes`. 227 __docker_complete_nodes() { 228 local current=$cur 229 if [ "$1" = "--cur" ] ; then 230 current="$2" 231 shift 2 232 fi 233 COMPREPLY=( $(compgen -W "$(__docker_nodes "$@")" -- "$current") ) 234 } 235 236 __docker_complete_nodes_plus_self() { 237 __docker_complete_nodes "$@" 238 COMPREPLY+=( self ) 239 } 240 241 # Returns a list of all services. Additional arguments to `docker service ls` 242 # may be specified in order to filter the service list, e.g. 243 # `__docker_services --filter name=xxx` 244 # By default, only node names are completed. 245 # Set DOCKER_COMPLETION_SHOW_SERVICE_IDS=yes to also complete service IDs. 246 # An optional first argument `--id|--name` may be used to limit 247 # the output to the IDs or names of matching services. This setting takes 248 # precedence over the environment setting. 249 __docker_services() { 250 local fields='$2' # default: service name only 251 [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name 252 253 if [ "$1" = "--id" ] ; then 254 fields='$1' # IDs only 255 shift 256 elif [ "$1" = "--name" ] ; then 257 fields='$2' # names only 258 shift 259 fi 260 __docker_q service ls "$@" | awk "NR>1 {print $fields}" 261 } 262 263 # Applies completion of services based on the current value of `$cur` or 264 # the value of the optional first argument `--cur`, if given. 265 # Additional filters may be appended, see `__docker_services`. 266 __docker_complete_services() { 267 local current=$cur 268 if [ "$1" = "--cur" ] ; then 269 current="$2" 270 shift 2 271 fi 272 COMPREPLY=( $(compgen -W "$(__docker_services "$@")" -- "$current") ) 273 } 274 275 # Appends the word passed as an argument to every word in `$COMPREPLY`. 276 # Normally you do this with `compgen -S`. This function exists so that you can use 277 # the __docker_complete_XXX functions in cases where you need a suffix. 278 __docker_append_to_completions() { 279 COMPREPLY=( ${COMPREPLY[@]/%/"$1"} ) 280 } 281 282 # Finds the position of the first word that is neither option nor an option's argument. 283 # If there are options that require arguments, you should pass a glob describing those 284 # options, e.g. "--option1|-o|--option2" 285 # Use this function to restrict completions to exact positions after the argument list. 286 __docker_pos_first_nonflag() { 287 local argument_flags=$1 288 289 local counter=$((${subcommand_pos:-${command_pos}} + 1)) 290 while [ $counter -le $cword ]; do 291 if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then 292 (( counter++ )) 293 # eat "=" in case of --option=arg syntax 294 [ "${words[$counter]}" = "=" ] && (( counter++ )) 295 else 296 case "${words[$counter]}" in 297 -*) 298 ;; 299 *) 300 break 301 ;; 302 esac 303 fi 304 305 # Bash splits words at "=", retaining "=" as a word, examples: 306 # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words 307 while [ "${words[$counter + 1]}" = "=" ] ; do 308 counter=$(( counter + 2)) 309 done 310 311 (( counter++ )) 312 done 313 314 echo $counter 315 } 316 317 # If we are currently completing the value of a map option (key=value) 318 # which matches the extglob given as an argument, returns key. 319 # This function is needed for key-specific completions. 320 __docker_map_key_of_current_option() { 321 local glob="$1" 322 323 local key glob_pos 324 if [ "$cur" = "=" ] ; then # key= case 325 key="$prev" 326 glob_pos=$((cword - 2)) 327 elif [[ $cur == *=* ]] ; then # key=value case (OSX) 328 key=${cur%=*} 329 glob_pos=$((cword - 1)) 330 elif [ "$prev" = "=" ] ; then 331 key=${words[$cword - 2]} # key=value case 332 glob_pos=$((cword - 3)) 333 else 334 return 335 fi 336 337 [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax 338 339 [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key" 340 } 341 342 # Returns the value of the first option matching option_glob. 343 # Valid values for option_glob are option names like '--log-level' and 344 # globs like '--log-level|-l' 345 # Only positions between the command and the current word are considered. 346 __docker_value_of_option() { 347 local option_extglob=$(__docker_to_extglob "$1") 348 349 local counter=$((command_pos + 1)) 350 while [ $counter -lt $cword ]; do 351 case ${words[$counter]} in 352 $option_extglob ) 353 echo ${words[$counter + 1]} 354 break 355 ;; 356 esac 357 (( counter++ )) 358 done 359 } 360 361 # Transforms a multiline list of strings into a single line string 362 # with the words separated by "|". 363 # This is used to prepare arguments to __docker_pos_first_nonflag(). 364 __docker_to_alternatives() { 365 local parts=( $1 ) 366 local IFS='|' 367 echo "${parts[*]}" 368 } 369 370 # Transforms a multiline list of options into an extglob pattern 371 # suitable for use in case statements. 372 __docker_to_extglob() { 373 local extglob=$( __docker_to_alternatives "$1" ) 374 echo "@($extglob)" 375 } 376 377 # Subcommand processing. 378 # Locates the first occurrence of any of the subcommands contained in the 379 # first argument. In case of a match, calls the corresponding completion 380 # function and returns 0. 381 # If no match is found, 1 is returned. The calling function can then 382 # continue processing its completion. 383 # 384 # TODO if the preceding command has options that accept arguments and an 385 # argument is equal ot one of the subcommands, this is falsely detected as 386 # a match. 387 __docker_subcommands() { 388 local subcommands="$1" 389 390 local counter=$(($command_pos + 1)) 391 while [ $counter -lt $cword ]; do 392 case "${words[$counter]}" in 393 $(__docker_to_extglob "$subcommands") ) 394 subcommand_pos=$counter 395 local subcommand=${words[$counter]} 396 local completions_func=_docker_${command}_${subcommand} 397 declare -F $completions_func >/dev/null && $completions_func 398 return 0 399 ;; 400 esac 401 (( counter++ )) 402 done 403 return 1 404 } 405 406 # suppress trailing whitespace 407 __docker_nospace() { 408 # compopt is not available in ancient bash versions 409 type compopt &>/dev/null && compopt -o nospace 410 } 411 412 __docker_complete_resolved_hostname() { 413 command -v host >/dev/null 2>&1 || return 414 COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') ) 415 } 416 417 __docker_local_interfaces() { 418 command -v ip >/dev/null 2>&1 || return 419 ip addr show scope global 2>/dev/null | sed -n 's| \+inet \([0-9.]\+\).* \([^ ]\+\)|\1 \2|p' 420 } 421 422 __docker_complete_local_interfaces() { 423 local additional_interface 424 if [ "$1" = "--add" ] ; then 425 additional_interface="$2" 426 fi 427 428 COMPREPLY=( $( compgen -W "$(__docker_local_interfaces) $additional_interface" -- "$cur" ) ) 429 } 430 431 __docker_complete_capabilities() { 432 # The list of capabilities is defined in types.go, ALL was added manually. 433 COMPREPLY=( $( compgen -W " 434 ALL 435 AUDIT_CONTROL 436 AUDIT_WRITE 437 AUDIT_READ 438 BLOCK_SUSPEND 439 CHOWN 440 DAC_OVERRIDE 441 DAC_READ_SEARCH 442 FOWNER 443 FSETID 444 IPC_LOCK 445 IPC_OWNER 446 KILL 447 LEASE 448 LINUX_IMMUTABLE 449 MAC_ADMIN 450 MAC_OVERRIDE 451 MKNOD 452 NET_ADMIN 453 NET_BIND_SERVICE 454 NET_BROADCAST 455 NET_RAW 456 SETFCAP 457 SETGID 458 SETPCAP 459 SETUID 460 SYS_ADMIN 461 SYS_BOOT 462 SYS_CHROOT 463 SYSLOG 464 SYS_MODULE 465 SYS_NICE 466 SYS_PACCT 467 SYS_PTRACE 468 SYS_RAWIO 469 SYS_RESOURCE 470 SYS_TIME 471 SYS_TTY_CONFIG 472 WAKE_ALARM 473 " -- "$cur" ) ) 474 } 475 476 __docker_complete_detach-keys() { 477 case "$prev" in 478 --detach-keys) 479 case "$cur" in 480 *,) 481 COMPREPLY=( $( compgen -W "${cur}ctrl-" -- "$cur" ) ) 482 ;; 483 *) 484 COMPREPLY=( $( compgen -W "ctrl-" -- "$cur" ) ) 485 ;; 486 esac 487 488 __docker_nospace 489 return 490 ;; 491 esac 492 return 1 493 } 494 495 __docker_complete_isolation() { 496 COMPREPLY=( $( compgen -W "default hyperv process" -- "$cur" ) ) 497 } 498 499 __docker_complete_log_drivers() { 500 COMPREPLY=( $( compgen -W " 501 awslogs 502 etwlogs 503 fluentd 504 gcplogs 505 gelf 506 journald 507 json-file 508 none 509 splunk 510 syslog 511 " -- "$cur" ) ) 512 } 513 514 __docker_complete_log_options() { 515 # see docs/reference/logging/index.md 516 local awslogs_options="awslogs-region awslogs-group awslogs-stream" 517 local fluentd_options="env fluentd-address fluentd-async-connect fluentd-buffer-limit fluentd-retry-wait fluentd-max-retries labels tag" 518 local gcplogs_options="env gcp-log-cmd gcp-project labels" 519 local gelf_options="env gelf-address gelf-compression-level gelf-compression-type labels tag" 520 local journald_options="env labels tag" 521 local json_file_options="env labels max-file max-size" 522 local syslog_options="env labels syslog-address syslog-facility syslog-format syslog-tls-ca-cert syslog-tls-cert syslog-tls-key syslog-tls-skip-verify tag" 523 local splunk_options="env labels splunk-caname splunk-capath splunk-format splunk-gzip splunk-gzip-level splunk-index splunk-insecureskipverify splunk-source splunk-sourcetype splunk-token splunk-url splunk-verify-connection tag" 524 525 local all_options="$fluentd_options $gcplogs_options $gelf_options $journald_options $json_file_options $syslog_options $splunk_options" 526 527 case $(__docker_value_of_option --log-driver) in 528 '') 529 COMPREPLY=( $( compgen -W "$all_options" -S = -- "$cur" ) ) 530 ;; 531 awslogs) 532 COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) ) 533 ;; 534 fluentd) 535 COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) ) 536 ;; 537 gcplogs) 538 COMPREPLY=( $( compgen -W "$gcplogs_options" -S = -- "$cur" ) ) 539 ;; 540 gelf) 541 COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) ) 542 ;; 543 journald) 544 COMPREPLY=( $( compgen -W "$journald_options" -S = -- "$cur" ) ) 545 ;; 546 json-file) 547 COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) ) 548 ;; 549 syslog) 550 COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) ) 551 ;; 552 splunk) 553 COMPREPLY=( $( compgen -W "$splunk_options" -S = -- "$cur" ) ) 554 ;; 555 *) 556 return 557 ;; 558 esac 559 560 __docker_nospace 561 } 562 563 __docker_complete_log_driver_options() { 564 local key=$(__docker_map_key_of_current_option '--log-opt') 565 case "$key" in 566 fluentd-async-connect) 567 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 568 return 569 ;; 570 gelf-address) 571 COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur##*=}" ) ) 572 __docker_nospace 573 return 574 ;; 575 gelf-compression-level) 576 COMPREPLY=( $( compgen -W "1 2 3 4 5 6 7 8 9" -- "${cur##*=}" ) ) 577 return 578 ;; 579 gelf-compression-type) 580 COMPREPLY=( $( compgen -W "gzip none zlib" -- "${cur##*=}" ) ) 581 return 582 ;; 583 syslog-address) 584 COMPREPLY=( $( compgen -W "tcp:// tcp+tls:// udp:// unix://" -- "${cur##*=}" ) ) 585 __docker_nospace 586 __ltrim_colon_completions "${cur}" 587 return 588 ;; 589 syslog-facility) 590 COMPREPLY=( $( compgen -W " 591 auth 592 authpriv 593 cron 594 daemon 595 ftp 596 kern 597 local0 598 local1 599 local2 600 local3 601 local4 602 local5 603 local6 604 local7 605 lpr 606 mail 607 news 608 syslog 609 user 610 uucp 611 " -- "${cur##*=}" ) ) 612 return 613 ;; 614 syslog-format) 615 COMPREPLY=( $( compgen -W "rfc3164 rfc5424 rfc5424micro" -- "${cur##*=}" ) ) 616 return 617 ;; 618 syslog-tls-ca-cert|syslog-tls-cert|syslog-tls-key) 619 _filedir 620 return 621 ;; 622 syslog-tls-skip-verify) 623 COMPREPLY=( $( compgen -W "true" -- "${cur##*=}" ) ) 624 return 625 ;; 626 splunk-url) 627 COMPREPLY=( $( compgen -W "http:// https://" -- "${cur##*=}" ) ) 628 __docker_nospace 629 __ltrim_colon_completions "${cur}" 630 return 631 ;; 632 splunk-gzip|splunk-insecureskipverify|splunk-verify-connection) 633 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 634 return 635 ;; 636 splunk-format) 637 COMPREPLY=( $( compgen -W "inline json raw" -- "${cur##*=}" ) ) 638 return 639 ;; 640 esac 641 return 1 642 } 643 644 __docker_complete_log_levels() { 645 COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) ) 646 } 647 648 __docker_complete_restart() { 649 case "$prev" in 650 --restart) 651 case "$cur" in 652 on-failure:*) 653 ;; 654 *) 655 COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") ) 656 ;; 657 esac 658 return 659 ;; 660 esac 661 return 1 662 } 663 664 # a selection of the available signals that is most likely of interest in the 665 # context of docker containers. 666 __docker_complete_signals() { 667 local signals=( 668 SIGCONT 669 SIGHUP 670 SIGINT 671 SIGKILL 672 SIGQUIT 673 SIGSTOP 674 SIGTERM 675 SIGUSR1 676 SIGUSR2 677 ) 678 COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) ) 679 } 680 681 __docker_complete_user_group() { 682 if [[ $cur == *:* ]] ; then 683 COMPREPLY=( $(compgen -g -- "${cur#*:}") ) 684 else 685 COMPREPLY=( $(compgen -u -S : -- "$cur") ) 686 __docker_nospace 687 fi 688 } 689 690 # global options that may appear after the docker command 691 _docker_docker() { 692 local boolean_options=" 693 $global_boolean_options 694 --help 695 --version -v 696 " 697 698 case "$prev" in 699 --config) 700 _filedir -d 701 return 702 ;; 703 --log-level|-l) 704 __docker_complete_log_levels 705 return 706 ;; 707 $(__docker_to_extglob "$global_options_with_args") ) 708 return 709 ;; 710 esac 711 712 case "$cur" in 713 -*) 714 COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) ) 715 ;; 716 *) 717 local counter=$( __docker_pos_first_nonflag "$(__docker_to_extglob "$global_options_with_args")" ) 718 if [ $cword -eq $counter ]; then 719 COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) ) 720 fi 721 ;; 722 esac 723 } 724 725 _docker_attach() { 726 __docker_complete_detach-keys && return 727 728 case "$cur" in 729 -*) 730 COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) ) 731 ;; 732 *) 733 local counter=$(__docker_pos_first_nonflag '--detach-keys') 734 if [ $cword -eq $counter ]; then 735 __docker_complete_containers_running 736 fi 737 ;; 738 esac 739 } 740 741 _docker_build() { 742 local options_with_args=" 743 --build-arg 744 --cgroup-parent 745 --cpuset-cpus 746 --cpuset-mems 747 --cpu-shares -c 748 --cpu-period 749 --cpu-quota 750 --file -f 751 --isolation 752 --label 753 --memory -m 754 --memory-swap 755 --shm-size 756 --tag -t 757 --ulimit 758 " 759 760 local boolean_options=" 761 --disable-content-trust=false 762 --force-rm 763 --help 764 --no-cache 765 --pull 766 --quiet -q 767 --rm 768 " 769 770 local all_options="$options_with_args $boolean_options" 771 772 case "$prev" in 773 --build-arg) 774 COMPREPLY=( $( compgen -e -- "$cur" ) ) 775 __docker_nospace 776 return 777 ;; 778 --file|-f) 779 _filedir 780 return 781 ;; 782 --isolation) 783 __docker_complete_isolation 784 return 785 ;; 786 --tag|-t) 787 __docker_complete_image_repos_and_tags 788 return 789 ;; 790 $(__docker_to_extglob "$options_with_args") ) 791 return 792 ;; 793 esac 794 795 case "$cur" in 796 -*) 797 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 798 ;; 799 *) 800 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 801 if [ $cword -eq $counter ]; then 802 _filedir -d 803 fi 804 ;; 805 esac 806 } 807 808 _docker_commit() { 809 case "$prev" in 810 --author|-a|--change|-c|--message|-m) 811 return 812 ;; 813 esac 814 815 case "$cur" in 816 -*) 817 COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) ) 818 ;; 819 *) 820 local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m') 821 822 if [ $cword -eq $counter ]; then 823 __docker_complete_containers_all 824 return 825 fi 826 (( counter++ )) 827 828 if [ $cword -eq $counter ]; then 829 __docker_complete_image_repos_and_tags 830 return 831 fi 832 ;; 833 esac 834 } 835 836 _docker_cp() { 837 case "$cur" in 838 -*) 839 COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) ) 840 ;; 841 *) 842 local counter=$(__docker_pos_first_nonflag) 843 if [ $cword -eq $counter ]; then 844 case "$cur" in 845 *:) 846 return 847 ;; 848 *) 849 # combined container and filename completion 850 _filedir 851 local files=( ${COMPREPLY[@]} ) 852 853 __docker_complete_containers_all 854 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 855 local containers=( ${COMPREPLY[@]} ) 856 857 COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) ) 858 if [[ "$COMPREPLY" == *: ]]; then 859 __docker_nospace 860 fi 861 return 862 ;; 863 esac 864 fi 865 (( counter++ )) 866 867 if [ $cword -eq $counter ]; then 868 if [ -e "$prev" ]; then 869 __docker_complete_containers_all 870 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 871 __docker_nospace 872 else 873 _filedir 874 fi 875 return 876 fi 877 ;; 878 esac 879 } 880 881 _docker_create() { 882 _docker_run 883 } 884 885 _docker_daemon() { 886 local boolean_options=" 887 $global_boolean_options 888 --disable-legacy-registry 889 --help 890 --icc=false 891 --ip-forward=false 892 --ip-masq=false 893 --iptables=false 894 --ipv6 895 --live-restore 896 --raw-logs 897 --selinux-enabled 898 --userland-proxy=false 899 " 900 local options_with_args=" 901 $global_options_with_args 902 --add-runtime 903 --api-cors-header 904 --authorization-plugin 905 --bip 906 --bridge -b 907 --cgroup-parent 908 --cluster-advertise 909 --cluster-store 910 --cluster-store-opt 911 --config-file 912 --containerd 913 --default-gateway 914 --default-gateway-v6 915 --default-ulimit 916 --dns 917 --dns-search 918 --dns-opt 919 --exec-opt 920 --exec-root 921 --fixed-cidr 922 --fixed-cidr-v6 923 --graph -g 924 --group -G 925 --init-path 926 --insecure-registry 927 --ip 928 --label 929 --log-driver 930 --log-opt 931 --max-concurrent-downloads 932 --max-concurrent-uploads 933 --mtu 934 --oom-score-adjust 935 --pidfile -p 936 --registry-mirror 937 --storage-driver -s 938 --storage-opt 939 --userns-remap 940 " 941 942 __docker_complete_log_driver_options && return 943 944 key=$(__docker_map_key_of_current_option '--cluster-store-opt') 945 case "$key" in 946 kv.*file) 947 cur=${cur##*=} 948 _filedir 949 return 950 ;; 951 esac 952 953 local key=$(__docker_map_key_of_current_option '--storage-opt') 954 case "$key" in 955 dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion) 956 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 957 return 958 ;; 959 dm.fs) 960 COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) ) 961 return 962 ;; 963 dm.thinpooldev) 964 cur=${cur##*=} 965 _filedir 966 return 967 ;; 968 esac 969 970 case "$prev" in 971 --authorization-plugin) 972 __docker_complete_plugins Authorization 973 return 974 ;; 975 --cluster-store) 976 COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) ) 977 __docker_nospace 978 return 979 ;; 980 --cluster-store-opt) 981 COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) ) 982 __docker_nospace 983 return 984 ;; 985 --config-file|--containerd|--init-path|--pidfile|-p|--tlscacert|--tlscert|--tlskey) 986 _filedir 987 return 988 ;; 989 --exec-root|--graph|-g) 990 _filedir -d 991 return 992 ;; 993 --log-driver) 994 __docker_complete_log_drivers 995 return 996 ;; 997 --storage-driver|-s) 998 COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) ) 999 return 1000 ;; 1001 --storage-opt) 1002 local btrfs_options="btrfs.min_space" 1003 local devicemapper_options=" 1004 dm.basesize 1005 dm.blkdiscard 1006 dm.blocksize 1007 dm.fs 1008 dm.loopdatasize 1009 dm.loopmetadatasize 1010 dm.min_free_space 1011 dm.mkfsarg 1012 dm.mountopt 1013 dm.override_udev_sync_check 1014 dm.thinpooldev 1015 dm.use_deferred_deletion 1016 dm.use_deferred_removal 1017 " 1018 local zfs_options="zfs.fsname" 1019 1020 case $(__docker_value_of_option '--storage-driver|-s') in 1021 '') 1022 COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) ) 1023 ;; 1024 btrfs) 1025 COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) ) 1026 ;; 1027 devicemapper) 1028 COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) ) 1029 ;; 1030 zfs) 1031 COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) ) 1032 ;; 1033 *) 1034 return 1035 ;; 1036 esac 1037 __docker_nospace 1038 return 1039 ;; 1040 --log-level|-l) 1041 __docker_complete_log_levels 1042 return 1043 ;; 1044 --log-opt) 1045 __docker_complete_log_options 1046 return 1047 ;; 1048 --userns-remap) 1049 __docker_complete_user_group 1050 return 1051 ;; 1052 $(__docker_to_extglob "$options_with_args") ) 1053 return 1054 ;; 1055 esac 1056 1057 case "$cur" in 1058 -*) 1059 COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) 1060 ;; 1061 esac 1062 } 1063 1064 _docker_diff() { 1065 case "$cur" in 1066 -*) 1067 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1068 ;; 1069 *) 1070 local counter=$(__docker_pos_first_nonflag) 1071 if [ $cword -eq $counter ]; then 1072 __docker_complete_containers_all 1073 fi 1074 ;; 1075 esac 1076 } 1077 1078 _docker_events() { 1079 local key=$(__docker_map_key_of_current_option '-f|--filter') 1080 case "$key" in 1081 container) 1082 cur="${cur##*=}" 1083 __docker_complete_containers_all 1084 return 1085 ;; 1086 daemon) 1087 local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p') 1088 COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) ) 1089 return 1090 ;; 1091 event) 1092 COMPREPLY=( $( compgen -W " 1093 attach 1094 commit 1095 connect 1096 copy 1097 create 1098 delete 1099 destroy 1100 detach 1101 die 1102 disconnect 1103 exec_create 1104 exec_detach 1105 exec_start 1106 export 1107 health_status 1108 import 1109 kill 1110 load 1111 mount 1112 oom 1113 pause 1114 pull 1115 push 1116 reload 1117 rename 1118 resize 1119 restart 1120 save 1121 start 1122 stop 1123 tag 1124 top 1125 unmount 1126 unpause 1127 untag 1128 update 1129 " -- "${cur##*=}" ) ) 1130 return 1131 ;; 1132 image) 1133 cur="${cur##*=}" 1134 __docker_complete_images 1135 return 1136 ;; 1137 network) 1138 cur="${cur##*=}" 1139 __docker_complete_networks 1140 return 1141 ;; 1142 type) 1143 COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) ) 1144 return 1145 ;; 1146 volume) 1147 cur="${cur##*=}" 1148 __docker_complete_volumes 1149 return 1150 ;; 1151 esac 1152 1153 case "$prev" in 1154 --filter|-f) 1155 COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) ) 1156 __docker_nospace 1157 return 1158 ;; 1159 --since|--until) 1160 return 1161 ;; 1162 esac 1163 1164 case "$cur" in 1165 -*) 1166 COMPREPLY=( $( compgen -W "--filter -f --help --since --until --format" -- "$cur" ) ) 1167 ;; 1168 esac 1169 } 1170 1171 _docker_exec() { 1172 __docker_complete_detach-keys && return 1173 1174 case "$prev" in 1175 --user|-u) 1176 __docker_complete_user_group 1177 return 1178 ;; 1179 esac 1180 1181 case "$cur" in 1182 -*) 1183 COMPREPLY=( $( compgen -W "--detach -d --detach-keys --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) ) 1184 ;; 1185 *) 1186 __docker_complete_containers_running 1187 ;; 1188 esac 1189 } 1190 1191 _docker_export() { 1192 case "$cur" in 1193 -*) 1194 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1195 ;; 1196 *) 1197 local counter=$(__docker_pos_first_nonflag) 1198 if [ $cword -eq $counter ]; then 1199 __docker_complete_containers_all 1200 fi 1201 ;; 1202 esac 1203 } 1204 1205 _docker_help() { 1206 local counter=$(__docker_pos_first_nonflag) 1207 if [ $cword -eq $counter ]; then 1208 COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) ) 1209 fi 1210 } 1211 1212 _docker_history() { 1213 case "$cur" in 1214 -*) 1215 COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) ) 1216 ;; 1217 *) 1218 local counter=$(__docker_pos_first_nonflag) 1219 if [ $cword -eq $counter ]; then 1220 __docker_complete_images 1221 fi 1222 ;; 1223 esac 1224 } 1225 1226 _docker_images() { 1227 local key=$(__docker_map_key_of_current_option '--filter|-f') 1228 case "$key" in 1229 before) 1230 cur="${cur##*=}" 1231 __docker_complete_images 1232 return 1233 ;; 1234 dangling) 1235 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 1236 return 1237 ;; 1238 label) 1239 return 1240 ;; 1241 since) 1242 cur="${cur##*=}" 1243 __docker_complete_images 1244 return 1245 ;; 1246 esac 1247 1248 case "$prev" in 1249 --filter|-f) 1250 COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) ) 1251 __docker_nospace 1252 return 1253 ;; 1254 --format) 1255 return 1256 ;; 1257 esac 1258 1259 case "$cur" in 1260 -*) 1261 COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) ) 1262 ;; 1263 =) 1264 return 1265 ;; 1266 *) 1267 __docker_complete_image_repos 1268 ;; 1269 esac 1270 } 1271 1272 _docker_import() { 1273 case "$prev" in 1274 --change|-c|--message|-m) 1275 return 1276 ;; 1277 esac 1278 1279 case "$cur" in 1280 -*) 1281 COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) ) 1282 ;; 1283 *) 1284 local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m') 1285 if [ $cword -eq $counter ]; then 1286 return 1287 fi 1288 (( counter++ )) 1289 1290 if [ $cword -eq $counter ]; then 1291 __docker_complete_image_repos_and_tags 1292 return 1293 fi 1294 ;; 1295 esac 1296 } 1297 1298 _docker_info() { 1299 case "$prev" in 1300 --format|-f) 1301 return 1302 ;; 1303 esac 1304 1305 case "$cur" in 1306 -*) 1307 COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) 1308 ;; 1309 esac 1310 } 1311 1312 _docker_inspect() { 1313 case "$prev" in 1314 --format|-f) 1315 return 1316 ;; 1317 --type) 1318 COMPREPLY=( $( compgen -W "image container" -- "$cur" ) ) 1319 return 1320 ;; 1321 1322 esac 1323 1324 case "$cur" in 1325 -*) 1326 COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) ) 1327 ;; 1328 *) 1329 case $(__docker_value_of_option --type) in 1330 '') 1331 __docker_complete_containers_and_images 1332 ;; 1333 container) 1334 __docker_complete_containers_all 1335 ;; 1336 image) 1337 __docker_complete_images 1338 ;; 1339 esac 1340 esac 1341 } 1342 1343 _docker_kill() { 1344 case "$prev" in 1345 --signal|-s) 1346 __docker_complete_signals 1347 return 1348 ;; 1349 esac 1350 1351 case "$cur" in 1352 -*) 1353 COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) ) 1354 ;; 1355 *) 1356 __docker_complete_containers_running 1357 ;; 1358 esac 1359 } 1360 1361 _docker_load() { 1362 case "$prev" in 1363 --input|-i) 1364 _filedir 1365 return 1366 ;; 1367 esac 1368 1369 case "$cur" in 1370 -*) 1371 COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) ) 1372 ;; 1373 esac 1374 } 1375 1376 _docker_login() { 1377 case "$prev" in 1378 --password|-p|--username|-u) 1379 return 1380 ;; 1381 esac 1382 1383 case "$cur" in 1384 -*) 1385 COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) ) 1386 ;; 1387 esac 1388 } 1389 1390 _docker_logout() { 1391 case "$cur" in 1392 -*) 1393 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1394 ;; 1395 esac 1396 } 1397 1398 _docker_logs() { 1399 case "$prev" in 1400 --since|--tail) 1401 return 1402 ;; 1403 esac 1404 1405 case "$cur" in 1406 -*) 1407 COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) ) 1408 ;; 1409 *) 1410 local counter=$(__docker_pos_first_nonflag '--since|--tail') 1411 if [ $cword -eq $counter ]; then 1412 __docker_complete_containers_all 1413 fi 1414 ;; 1415 esac 1416 } 1417 1418 _docker_network_connect() { 1419 local options_with_args=" 1420 --alias 1421 --ip 1422 --ip6 1423 --link 1424 --link-local-ip 1425 " 1426 1427 local boolean_options=" 1428 --help 1429 " 1430 1431 case "$prev" in 1432 --link) 1433 case "$cur" in 1434 *:*) 1435 ;; 1436 *) 1437 __docker_complete_containers_running 1438 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 1439 __docker_nospace 1440 ;; 1441 esac 1442 return 1443 ;; 1444 $(__docker_to_extglob "$options_with_args") ) 1445 return 1446 ;; 1447 esac 1448 1449 case "$cur" in 1450 -*) 1451 COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) 1452 ;; 1453 *) 1454 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 1455 if [ $cword -eq $counter ]; then 1456 __docker_complete_networks 1457 elif [ $cword -eq $(($counter + 1)) ]; then 1458 __docker_complete_containers_all 1459 fi 1460 ;; 1461 esac 1462 } 1463 1464 _docker_network_create() { 1465 case "$prev" in 1466 --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet) 1467 return 1468 ;; 1469 --ipam-driver) 1470 COMPREPLY=( $( compgen -W "default" -- "$cur" ) ) 1471 return 1472 ;; 1473 --driver|-d) 1474 local plugins="$(__docker_plugins Network) macvlan" 1475 # remove drivers that allow one instance only 1476 plugins=${plugins/ host / } 1477 plugins=${plugins/ null / } 1478 COMPREPLY=( $(compgen -W "$plugins" -- "$cur") ) 1479 return 1480 ;; 1481 --label) 1482 return 1483 ;; 1484 esac 1485 1486 case "$cur" in 1487 -*) 1488 COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) ) 1489 ;; 1490 esac 1491 } 1492 1493 _docker_network_disconnect() { 1494 case "$cur" in 1495 -*) 1496 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1497 ;; 1498 *) 1499 local counter=$(__docker_pos_first_nonflag) 1500 if [ $cword -eq $counter ]; then 1501 __docker_complete_networks 1502 elif [ $cword -eq $(($counter + 1)) ]; then 1503 __docker_complete_containers_in_network "$prev" 1504 fi 1505 ;; 1506 esac 1507 } 1508 1509 _docker_network_inspect() { 1510 case "$prev" in 1511 --format|-f) 1512 return 1513 ;; 1514 esac 1515 1516 case "$cur" in 1517 -*) 1518 COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) 1519 ;; 1520 *) 1521 __docker_complete_networks 1522 esac 1523 } 1524 1525 _docker_network_ls() { 1526 local key=$(__docker_map_key_of_current_option '--filter|-f') 1527 case "$key" in 1528 driver) 1529 local plugins=" $(__docker_plugins Network) " 1530 COMPREPLY=( $(compgen -W "$plugins" -- "${cur##*=}") ) 1531 return 1532 ;; 1533 id) 1534 cur="${cur##*=}" 1535 __docker_complete_network_ids 1536 return 1537 ;; 1538 name) 1539 cur="${cur##*=}" 1540 __docker_complete_network_names 1541 return 1542 ;; 1543 type) 1544 COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) ) 1545 return 1546 ;; 1547 esac 1548 1549 case "$prev" in 1550 --filter|-f) 1551 COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) ) 1552 __docker_nospace 1553 return 1554 ;; 1555 --format) 1556 return 1557 ;; 1558 esac 1559 1560 case "$cur" in 1561 -*) 1562 COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) ) 1563 ;; 1564 esac 1565 } 1566 1567 _docker_network_rm() { 1568 case "$cur" in 1569 -*) 1570 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1571 ;; 1572 *) 1573 __docker_complete_networks type=custom 1574 esac 1575 } 1576 1577 _docker_network() { 1578 local subcommands=" 1579 connect 1580 create 1581 disconnect 1582 inspect 1583 ls 1584 rm 1585 " 1586 __docker_subcommands "$subcommands" && return 1587 1588 case "$cur" in 1589 -*) 1590 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1591 ;; 1592 *) 1593 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 1594 ;; 1595 esac 1596 } 1597 1598 _docker_service() { 1599 local subcommands=" 1600 create 1601 inspect 1602 ls list 1603 rm remove 1604 scale 1605 ps 1606 update 1607 " 1608 __docker_subcommands "$subcommands" && return 1609 1610 case "$cur" in 1611 -*) 1612 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1613 ;; 1614 *) 1615 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 1616 ;; 1617 esac 1618 } 1619 1620 _docker_service_create() { 1621 _docker_service_update 1622 } 1623 1624 _docker_service_inspect() { 1625 case "$prev" in 1626 --format|-f) 1627 return 1628 ;; 1629 esac 1630 1631 case "$cur" in 1632 -*) 1633 COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) ) 1634 ;; 1635 *) 1636 __docker_complete_services 1637 esac 1638 } 1639 1640 _docker_service_list() { 1641 _docker_service_ls 1642 } 1643 1644 _docker_service_ls() { 1645 local key=$(__docker_map_key_of_current_option '--filter|-f') 1646 case "$key" in 1647 id) 1648 __docker_complete_services --cur "${cur##*=}" --id 1649 return 1650 ;; 1651 name) 1652 __docker_complete_services --cur "${cur##*=}" --name 1653 return 1654 ;; 1655 esac 1656 1657 case "$prev" in 1658 --filter|-f) 1659 COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) ) 1660 __docker_nospace 1661 return 1662 ;; 1663 esac 1664 1665 case "$cur" in 1666 -*) 1667 COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) ) 1668 ;; 1669 esac 1670 } 1671 1672 _docker_service_remove() { 1673 _docker_service_rm 1674 } 1675 1676 _docker_service_rm() { 1677 case "$cur" in 1678 -*) 1679 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1680 ;; 1681 *) 1682 __docker_complete_services 1683 esac 1684 } 1685 1686 _docker_service_scale() { 1687 case "$cur" in 1688 -*) 1689 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1690 ;; 1691 *) 1692 __docker_complete_services 1693 __docker_append_to_completions "=" 1694 __docker_nospace 1695 ;; 1696 esac 1697 } 1698 1699 _docker_service_ps() { 1700 local key=$(__docker_map_key_of_current_option '--filter|-f') 1701 case "$key" in 1702 desired-state) 1703 COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) ) 1704 return 1705 ;; 1706 name) 1707 __docker_complete_services --cur "${cur##*=}" --name 1708 return 1709 ;; 1710 esac 1711 1712 case "$prev" in 1713 --filter|-f) 1714 COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) ) 1715 __docker_nospace 1716 return 1717 ;; 1718 esac 1719 1720 case "$cur" in 1721 -*) 1722 COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) ) 1723 ;; 1724 *) 1725 local counter=$(__docker_pos_first_nonflag '--filter|-f') 1726 if [ $cword -eq $counter ]; then 1727 __docker_complete_services 1728 fi 1729 ;; 1730 esac 1731 } 1732 1733 _docker_service_update() { 1734 local $subcommand="${words[$subcommand_pos]}" 1735 1736 local options_with_args=" 1737 --constraint 1738 --endpoint-mode 1739 --env -e 1740 --group-add 1741 --label -l 1742 --limit-cpu 1743 --limit-memory 1744 --log-driver 1745 --log-opt 1746 --mount 1747 --name 1748 --network 1749 --publish -p 1750 --replicas 1751 --reserve-cpu 1752 --reserve-memory 1753 --restart-condition 1754 --restart-delay 1755 --restart-max-attempts 1756 --restart-window 1757 --stop-grace-period 1758 --update-delay 1759 --update-failure-action 1760 --update-parallelism 1761 --user -u 1762 --workdir -w 1763 " 1764 1765 local boolean_options=" 1766 --help 1767 --with-registry-auth 1768 " 1769 1770 __docker_complete_log_driver_options && return 1771 1772 if [ "$subcommand" = "create" ] ; then 1773 options_with_args="$options_with_args 1774 --container-label 1775 --mode 1776 " 1777 1778 case "$prev" in 1779 --mode) 1780 COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) ) 1781 return 1782 ;; 1783 esac 1784 fi 1785 if [ "$subcommand" = "update" ] ; then 1786 options_with_args="$options_with_args 1787 --arg 1788 --container-label-add 1789 --container-label-rm 1790 --group-rm 1791 --image 1792 " 1793 1794 case "$prev" in 1795 --group-rm) 1796 COMPREPLY=( $(compgen -g -- "$cur") ) 1797 return 1798 ;; 1799 --image) 1800 __docker_complete_image_repos_and_tags 1801 return 1802 ;; 1803 esac 1804 fi 1805 1806 case "$prev" in 1807 --endpoint-mode) 1808 COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) ) 1809 return 1810 ;; 1811 --env|-e) 1812 # we do not append a "=" here because "-e VARNAME" is legal systax, too 1813 COMPREPLY=( $( compgen -e -- "$cur" ) ) 1814 __docker_nospace 1815 return 1816 ;; 1817 --group-add) 1818 COMPREPLY=( $(compgen -g -- "$cur") ) 1819 return 1820 ;; 1821 --log-driver) 1822 __docker_complete_log_drivers 1823 return 1824 ;; 1825 --log-opt) 1826 __docker_complete_log_options 1827 return 1828 ;; 1829 --network) 1830 __docker_complete_networks 1831 return 1832 ;; 1833 --restart-condition) 1834 COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) ) 1835 return 1836 ;; 1837 --user|-u) 1838 __docker_complete_user_group 1839 return 1840 ;; 1841 $(__docker_to_extglob "$options_with_args") ) 1842 return 1843 ;; 1844 esac 1845 1846 case "$cur" in 1847 -*) 1848 COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) 1849 ;; 1850 *) 1851 if [ "$subcommand" = "update" ] ; then 1852 __docker_complete_services 1853 fi 1854 esac 1855 } 1856 1857 _docker_swarm() { 1858 local subcommands=" 1859 init 1860 join 1861 join-token 1862 leave 1863 update 1864 " 1865 __docker_subcommands "$subcommands" && return 1866 1867 case "$cur" in 1868 -*) 1869 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1870 ;; 1871 *) 1872 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 1873 ;; 1874 esac 1875 } 1876 1877 _docker_swarm_init() { 1878 case "$prev" in 1879 --advertise-addr) 1880 if [[ $cur == *: ]] ; then 1881 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 1882 else 1883 __docker_complete_local_interfaces 1884 __docker_nospace 1885 fi 1886 return 1887 ;; 1888 --listen-addr) 1889 if [[ $cur == *: ]] ; then 1890 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 1891 else 1892 __docker_complete_local_interfaces --add 0.0.0.0 1893 __docker_nospace 1894 fi 1895 return 1896 ;; 1897 esac 1898 1899 case "$cur" in 1900 -*) 1901 COMPREPLY=( $( compgen -W "--advertise-addr --force-new-cluster --help --listen-addr" -- "$cur" ) ) 1902 ;; 1903 esac 1904 } 1905 1906 _docker_swarm_join() { 1907 case "$prev" in 1908 --advertise-addr) 1909 if [[ $cur == *: ]] ; then 1910 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 1911 else 1912 __docker_complete_local_interfaces 1913 __docker_nospace 1914 fi 1915 return 1916 ;; 1917 --listen-addr) 1918 if [[ $cur == *: ]] ; then 1919 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 1920 else 1921 __docker_complete_local_interfaces --add 0.0.0.0 1922 __docker_nospace 1923 fi 1924 return 1925 ;; 1926 --token) 1927 return 1928 ;; 1929 esac 1930 1931 case "$cur" in 1932 -*) 1933 COMPREPLY=( $( compgen -W "--advertise-addr --help --listen-addr --token" -- "$cur" ) ) 1934 ;; 1935 *:) 1936 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 1937 ;; 1938 esac 1939 } 1940 1941 _docker_swarm_join-token() { 1942 case "$cur" in 1943 -*) 1944 COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) ) 1945 ;; 1946 *) 1947 local counter=$( __docker_pos_first_nonflag ) 1948 if [ $cword -eq $counter ]; then 1949 COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) ) 1950 fi 1951 ;; 1952 esac 1953 } 1954 1955 _docker_swarm_leave() { 1956 case "$cur" in 1957 -*) 1958 COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) ) 1959 ;; 1960 esac 1961 } 1962 1963 _docker_swarm_update() { 1964 case "$prev" in 1965 --cert-expiry|--dispatcher-heartbeat|--task-history-limit) 1966 return 1967 ;; 1968 esac 1969 1970 case "$cur" in 1971 -*) 1972 COMPREPLY=( $( compgen -W "--cert-expiry --dispatcher-heartbeat --help --task-history-limit" -- "$cur" ) ) 1973 ;; 1974 esac 1975 } 1976 1977 _docker_node() { 1978 local subcommands=" 1979 demote 1980 inspect 1981 ls list 1982 promote 1983 rm remove 1984 ps 1985 update 1986 " 1987 __docker_subcommands "$subcommands" && return 1988 1989 case "$cur" in 1990 -*) 1991 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1992 ;; 1993 *) 1994 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 1995 ;; 1996 esac 1997 } 1998 1999 _docker_node_demote() { 2000 case "$cur" in 2001 -*) 2002 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2003 ;; 2004 *) 2005 __docker_complete_nodes --filter role=manager 2006 esac 2007 } 2008 2009 _docker_node_inspect() { 2010 case "$prev" in 2011 --format|-f) 2012 return 2013 ;; 2014 esac 2015 2016 case "$cur" in 2017 -*) 2018 COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) ) 2019 ;; 2020 *) 2021 __docker_complete_nodes_plus_self 2022 esac 2023 } 2024 2025 _docker_node_list() { 2026 _docker_node_ls 2027 } 2028 2029 _docker_node_ls() { 2030 local key=$(__docker_map_key_of_current_option '--filter|-f') 2031 case "$key" in 2032 id) 2033 __docker_complete_nodes --cur "${cur##*=}" --id 2034 return 2035 ;; 2036 name) 2037 __docker_complete_nodes --cur "${cur##*=}" --name 2038 return 2039 ;; 2040 esac 2041 2042 case "$prev" in 2043 --filter|-f) 2044 COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) ) 2045 __docker_nospace 2046 return 2047 ;; 2048 esac 2049 2050 case "$cur" in 2051 -*) 2052 COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) ) 2053 ;; 2054 esac 2055 } 2056 2057 _docker_node_promote() { 2058 case "$cur" in 2059 -*) 2060 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2061 ;; 2062 *) 2063 __docker_complete_nodes --filter role=worker 2064 esac 2065 } 2066 2067 _docker_node_remove() { 2068 _docker_node_rm 2069 } 2070 2071 _docker_node_rm() { 2072 case "$cur" in 2073 -*) 2074 COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) ) 2075 ;; 2076 *) 2077 __docker_complete_nodes 2078 esac 2079 } 2080 2081 _docker_node_ps() { 2082 local key=$(__docker_map_key_of_current_option '--filter|-f') 2083 case "$key" in 2084 desired-state) 2085 COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) ) 2086 return 2087 ;; 2088 name) 2089 __docker_complete_services --cur "${cur##*=}" --name 2090 return 2091 ;; 2092 esac 2093 2094 case "$prev" in 2095 --filter|-f) 2096 COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) ) 2097 __docker_nospace 2098 return 2099 ;; 2100 esac 2101 2102 case "$cur" in 2103 -*) 2104 COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) ) 2105 ;; 2106 *) 2107 __docker_complete_nodes_plus_self 2108 ;; 2109 esac 2110 } 2111 2112 _docker_node_update() { 2113 case "$prev" in 2114 --availability) 2115 COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) ) 2116 return 2117 ;; 2118 --role) 2119 COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) ) 2120 return 2121 ;; 2122 --label-add|--label-rm) 2123 return 2124 ;; 2125 esac 2126 2127 case "$cur" in 2128 -*) 2129 COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) ) 2130 ;; 2131 *) 2132 __docker_complete_nodes 2133 esac 2134 } 2135 2136 _docker_pause() { 2137 case "$cur" in 2138 -*) 2139 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2140 ;; 2141 *) 2142 local counter=$(__docker_pos_first_nonflag) 2143 if [ $cword -eq $counter ]; then 2144 __docker_complete_containers_pauseable 2145 fi 2146 ;; 2147 esac 2148 } 2149 2150 _docker_port() { 2151 case "$cur" in 2152 -*) 2153 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2154 ;; 2155 *) 2156 local counter=$(__docker_pos_first_nonflag) 2157 if [ $cword -eq $counter ]; then 2158 __docker_complete_containers_all 2159 fi 2160 ;; 2161 esac 2162 } 2163 2164 _docker_ps() { 2165 local key=$(__docker_map_key_of_current_option '--filter|-f') 2166 case "$key" in 2167 ancestor) 2168 cur="${cur##*=}" 2169 __docker_complete_images 2170 return 2171 ;; 2172 before) 2173 cur="${cur##*=}" 2174 __docker_complete_containers_all 2175 return 2176 ;; 2177 id) 2178 cur="${cur##*=}" 2179 __docker_complete_container_ids 2180 return 2181 ;; 2182 is-task) 2183 COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) ) 2184 return 2185 ;; 2186 name) 2187 cur="${cur##*=}" 2188 __docker_complete_container_names 2189 return 2190 ;; 2191 network) 2192 cur="${cur##*=}" 2193 __docker_complete_networks 2194 return 2195 ;; 2196 since) 2197 cur="${cur##*=}" 2198 __docker_complete_containers_all 2199 return 2200 ;; 2201 status) 2202 COMPREPLY=( $( compgen -W "created dead exited paused restarting running removing" -- "${cur##*=}" ) ) 2203 return 2204 ;; 2205 volume) 2206 cur="${cur##*=}" 2207 __docker_complete_volumes 2208 return 2209 ;; 2210 esac 2211 2212 case "$prev" in 2213 --filter|-f) 2214 COMPREPLY=( $( compgen -S = -W "ancestor before exited id label name network since status volume" -- "$cur" ) ) 2215 __docker_nospace 2216 return 2217 ;; 2218 --format|--last|-n) 2219 return 2220 ;; 2221 esac 2222 2223 case "$cur" in 2224 -*) 2225 COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) ) 2226 ;; 2227 esac 2228 } 2229 2230 _docker_pull() { 2231 case "$cur" in 2232 -*) 2233 COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) ) 2234 ;; 2235 *) 2236 local counter=$(__docker_pos_first_nonflag) 2237 if [ $cword -eq $counter ]; then 2238 for arg in "${COMP_WORDS[@]}"; do 2239 case "$arg" in 2240 --all-tags|-a) 2241 __docker_complete_image_repos 2242 return 2243 ;; 2244 esac 2245 done 2246 __docker_complete_image_repos_and_tags 2247 fi 2248 ;; 2249 esac 2250 } 2251 2252 _docker_push() { 2253 case "$cur" in 2254 -*) 2255 COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) ) 2256 ;; 2257 *) 2258 local counter=$(__docker_pos_first_nonflag) 2259 if [ $cword -eq $counter ]; then 2260 __docker_complete_image_repos_and_tags 2261 fi 2262 ;; 2263 esac 2264 } 2265 2266 _docker_rename() { 2267 case "$cur" in 2268 -*) 2269 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2270 ;; 2271 *) 2272 local counter=$(__docker_pos_first_nonflag) 2273 if [ $cword -eq $counter ]; then 2274 __docker_complete_containers_all 2275 fi 2276 ;; 2277 esac 2278 } 2279 2280 _docker_restart() { 2281 case "$prev" in 2282 --time|-t) 2283 return 2284 ;; 2285 esac 2286 2287 case "$cur" in 2288 -*) 2289 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 2290 ;; 2291 *) 2292 __docker_complete_containers_all 2293 ;; 2294 esac 2295 } 2296 2297 _docker_rm() { 2298 case "$cur" in 2299 -*) 2300 COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) ) 2301 ;; 2302 *) 2303 for arg in "${COMP_WORDS[@]}"; do 2304 case "$arg" in 2305 --force|-f) 2306 __docker_complete_containers_all 2307 return 2308 ;; 2309 esac 2310 done 2311 __docker_complete_containers_stopped 2312 ;; 2313 esac 2314 } 2315 2316 _docker_rmi() { 2317 case "$cur" in 2318 -*) 2319 COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) ) 2320 ;; 2321 *) 2322 __docker_complete_images 2323 ;; 2324 esac 2325 } 2326 2327 _docker_run() { 2328 local options_with_args=" 2329 --add-host 2330 --attach -a 2331 --blkio-weight 2332 --blkio-weight-device 2333 --cap-add 2334 --cap-drop 2335 --cgroup-parent 2336 --cidfile 2337 --cpu-period 2338 --cpu-quota 2339 --cpuset-cpus 2340 --cpuset-mems 2341 --cpu-shares -c 2342 --device 2343 --device-read-bps 2344 --device-read-iops 2345 --device-write-bps 2346 --device-write-iops 2347 --dns 2348 --dns-opt 2349 --dns-search 2350 --entrypoint 2351 --env -e 2352 --env-file 2353 --expose 2354 --group-add 2355 --hostname -h 2356 --ip 2357 --ip6 2358 --ipc 2359 --isolation 2360 --kernel-memory 2361 --label-file 2362 --label -l 2363 --link 2364 --link-local-ip 2365 --log-driver 2366 --log-opt 2367 --mac-address 2368 --memory -m 2369 --memory-swap 2370 --memory-swappiness 2371 --memory-reservation 2372 --name 2373 --network 2374 --network-alias 2375 --oom-score-adj 2376 --pid 2377 --pids-limit 2378 --publish -p 2379 --restart 2380 --runtime 2381 --security-opt 2382 --shm-size 2383 --stop-signal 2384 --storage-opt 2385 --tmpfs 2386 --sysctl 2387 --ulimit 2388 --user -u 2389 --userns 2390 --uts 2391 --volume-driver 2392 --volumes-from 2393 --volume -v 2394 --workdir -w 2395 " 2396 2397 local boolean_options=" 2398 --disable-content-trust=false 2399 --help 2400 --interactive -i 2401 --oom-kill-disable 2402 --privileged 2403 --publish-all -P 2404 --read-only 2405 --tty -t 2406 " 2407 2408 if [ "$command" = "run" ] ; then 2409 options_with_args="$options_with_args 2410 --detach-keys 2411 --health-cmd 2412 --health-interval 2413 --health-retries 2414 --health-timeout 2415 " 2416 boolean_options="$boolean_options 2417 --detach -d 2418 --no-healthcheck 2419 --rm 2420 --sig-proxy=false 2421 " 2422 __docker_complete_detach-keys && return 2423 fi 2424 2425 local all_options="$options_with_args $boolean_options" 2426 2427 2428 __docker_complete_log_driver_options && return 2429 __docker_complete_restart && return 2430 2431 local key=$(__docker_map_key_of_current_option '--security-opt') 2432 case "$key" in 2433 label) 2434 [[ $cur == *: ]] && return 2435 COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") ) 2436 if [ "${COMPREPLY[*]}" != "disable" ] ; then 2437 __docker_nospace 2438 fi 2439 return 2440 ;; 2441 seccomp) 2442 local cur=${cur##*=} 2443 _filedir 2444 COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) ) 2445 return 2446 ;; 2447 esac 2448 2449 case "$prev" in 2450 --add-host) 2451 case "$cur" in 2452 *:) 2453 __docker_complete_resolved_hostname 2454 return 2455 ;; 2456 esac 2457 ;; 2458 --attach|-a) 2459 COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) ) 2460 return 2461 ;; 2462 --cap-add|--cap-drop) 2463 __docker_complete_capabilities 2464 return 2465 ;; 2466 --cidfile|--env-file|--label-file) 2467 _filedir 2468 return 2469 ;; 2470 --device|--tmpfs|--volume|-v) 2471 case "$cur" in 2472 *:*) 2473 # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) 2474 ;; 2475 '') 2476 COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) 2477 __docker_nospace 2478 ;; 2479 /*) 2480 _filedir 2481 __docker_nospace 2482 ;; 2483 esac 2484 return 2485 ;; 2486 --env|-e) 2487 # we do not append a "=" here because "-e VARNAME" is legal systax, too 2488 COMPREPLY=( $( compgen -e -- "$cur" ) ) 2489 __docker_nospace 2490 return 2491 ;; 2492 --ipc) 2493 case "$cur" in 2494 *:*) 2495 cur="${cur#*:}" 2496 __docker_complete_containers_running 2497 ;; 2498 *) 2499 COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) ) 2500 if [ "$COMPREPLY" = "container:" ]; then 2501 __docker_nospace 2502 fi 2503 ;; 2504 esac 2505 return 2506 ;; 2507 --isolation) 2508 __docker_complete_isolation 2509 return 2510 ;; 2511 --link) 2512 case "$cur" in 2513 *:*) 2514 ;; 2515 *) 2516 __docker_complete_containers_running 2517 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 2518 __docker_nospace 2519 ;; 2520 esac 2521 return 2522 ;; 2523 --log-driver) 2524 __docker_complete_log_drivers 2525 return 2526 ;; 2527 --log-opt) 2528 __docker_complete_log_options 2529 return 2530 ;; 2531 --network) 2532 case "$cur" in 2533 container:*) 2534 local cur=${cur#*:} 2535 __docker_complete_containers_all 2536 ;; 2537 *) 2538 COMPREPLY=( $( compgen -W "$(__docker_plugins Network) $(__docker_networks) container:" -- "$cur") ) 2539 if [ "${COMPREPLY[*]}" = "container:" ] ; then 2540 __docker_nospace 2541 fi 2542 ;; 2543 esac 2544 return 2545 ;; 2546 --pid) 2547 case "$cur" in 2548 *:*) 2549 cur="${cur#*:}" 2550 __docker_complete_containers_running 2551 ;; 2552 *) 2553 COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) ) 2554 if [ "$COMPREPLY" = "container:" ]; then 2555 __docker_nospace 2556 fi 2557 ;; 2558 esac 2559 return 2560 ;; 2561 --runtime) 2562 __docker_complete_runtimes 2563 return 2564 ;; 2565 --security-opt) 2566 COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") ) 2567 if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then 2568 __docker_nospace 2569 fi 2570 return 2571 ;; 2572 --storage-opt) 2573 COMPREPLY=( $( compgen -W "size" -S = -- "$cur") ) 2574 __docker_nospace 2575 return 2576 ;; 2577 --user|-u) 2578 __docker_complete_user_group 2579 return 2580 ;; 2581 --userns) 2582 COMPREPLY=( $( compgen -W "host" -- "$cur" ) ) 2583 return 2584 ;; 2585 --volume-driver) 2586 __docker_complete_plugins Volume 2587 return 2588 ;; 2589 --volumes-from) 2590 __docker_complete_containers_all 2591 return 2592 ;; 2593 $(__docker_to_extglob "$options_with_args") ) 2594 return 2595 ;; 2596 esac 2597 2598 case "$cur" in 2599 -*) 2600 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 2601 ;; 2602 *) 2603 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 2604 if [ $cword -eq $counter ]; then 2605 __docker_complete_images 2606 fi 2607 ;; 2608 esac 2609 } 2610 2611 _docker_save() { 2612 case "$prev" in 2613 --output|-o) 2614 _filedir 2615 return 2616 ;; 2617 esac 2618 2619 case "$cur" in 2620 -*) 2621 COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) ) 2622 ;; 2623 *) 2624 __docker_complete_images 2625 ;; 2626 esac 2627 } 2628 2629 _docker_search() { 2630 local key=$(__docker_map_key_of_current_option '--filter|-f') 2631 case "$key" in 2632 is-automated) 2633 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 2634 return 2635 ;; 2636 is-official) 2637 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 2638 return 2639 ;; 2640 esac 2641 2642 case "$prev" in 2643 --filter|-f) 2644 COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) ) 2645 __docker_nospace 2646 return 2647 ;; 2648 --limit) 2649 return 2650 ;; 2651 esac 2652 2653 case "$cur" in 2654 -*) 2655 COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) ) 2656 ;; 2657 esac 2658 } 2659 2660 _docker_start() { 2661 __docker_complete_detach-keys && return 2662 2663 case "$cur" in 2664 -*) 2665 COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) ) 2666 ;; 2667 *) 2668 __docker_complete_containers_stopped 2669 ;; 2670 esac 2671 } 2672 2673 _docker_stats() { 2674 case "$prev" in 2675 --format) 2676 return 2677 ;; 2678 esac 2679 2680 case "$cur" in 2681 -*) 2682 COMPREPLY=( $( compgen -W "--all -a --format --help --no-stream" -- "$cur" ) ) 2683 ;; 2684 *) 2685 __docker_complete_containers_running 2686 ;; 2687 esac 2688 } 2689 2690 _docker_stop() { 2691 case "$prev" in 2692 --time|-t) 2693 return 2694 ;; 2695 esac 2696 2697 case "$cur" in 2698 -*) 2699 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 2700 ;; 2701 *) 2702 __docker_complete_containers_running 2703 ;; 2704 esac 2705 } 2706 2707 _docker_tag() { 2708 case "$cur" in 2709 -*) 2710 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2711 ;; 2712 *) 2713 local counter=$(__docker_pos_first_nonflag) 2714 2715 if [ $cword -eq $counter ]; then 2716 __docker_complete_image_repos_and_tags 2717 return 2718 fi 2719 (( counter++ )) 2720 2721 if [ $cword -eq $counter ]; then 2722 __docker_complete_image_repos_and_tags 2723 return 2724 fi 2725 ;; 2726 esac 2727 } 2728 2729 _docker_unpause() { 2730 case "$cur" in 2731 -*) 2732 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2733 ;; 2734 *) 2735 local counter=$(__docker_pos_first_nonflag) 2736 if [ $cword -eq $counter ]; then 2737 __docker_complete_containers_unpauseable 2738 fi 2739 ;; 2740 esac 2741 } 2742 2743 _docker_update() { 2744 local options_with_args=" 2745 --blkio-weight 2746 --cpu-period 2747 --cpu-quota 2748 --cpuset-cpus 2749 --cpuset-mems 2750 --cpu-shares -c 2751 --kernel-memory 2752 --memory -m 2753 --memory-reservation 2754 --memory-swap 2755 --restart 2756 " 2757 2758 local boolean_options=" 2759 --help 2760 " 2761 2762 local all_options="$options_with_args $boolean_options" 2763 2764 __docker_complete_restart && return 2765 2766 case "$prev" in 2767 $(__docker_to_extglob "$options_with_args") ) 2768 return 2769 ;; 2770 esac 2771 2772 case "$cur" in 2773 -*) 2774 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 2775 ;; 2776 *) 2777 __docker_complete_containers_all 2778 ;; 2779 esac 2780 } 2781 2782 _docker_top() { 2783 case "$cur" in 2784 -*) 2785 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2786 ;; 2787 *) 2788 local counter=$(__docker_pos_first_nonflag) 2789 if [ $cword -eq $counter ]; then 2790 __docker_complete_containers_running 2791 fi 2792 ;; 2793 esac 2794 } 2795 2796 _docker_version() { 2797 case "$cur" in 2798 -*) 2799 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2800 ;; 2801 esac 2802 } 2803 2804 _docker_volume_create() { 2805 case "$prev" in 2806 --driver|-d) 2807 __docker_complete_plugins Volume 2808 return 2809 ;; 2810 --label|--opt|-o) 2811 return 2812 ;; 2813 esac 2814 2815 case "$cur" in 2816 -*) 2817 COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) ) 2818 ;; 2819 esac 2820 } 2821 2822 _docker_volume_inspect() { 2823 case "$prev" in 2824 --format|-f) 2825 return 2826 ;; 2827 esac 2828 2829 case "$cur" in 2830 -*) 2831 COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) 2832 ;; 2833 *) 2834 __docker_complete_volumes 2835 ;; 2836 esac 2837 } 2838 2839 _docker_volume_ls() { 2840 local key=$(__docker_map_key_of_current_option '--filter|-f') 2841 case "$key" in 2842 dangling) 2843 COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) ) 2844 return 2845 ;; 2846 driver) 2847 cur=${cur##*=} 2848 __docker_complete_plugins Volume 2849 return 2850 ;; 2851 name) 2852 cur=${cur##*=} 2853 __docker_complete_volumes 2854 return 2855 ;; 2856 esac 2857 2858 case "$prev" in 2859 --filter|-f) 2860 COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) ) 2861 __docker_nospace 2862 return 2863 ;; 2864 --format) 2865 return 2866 ;; 2867 esac 2868 2869 case "$cur" in 2870 -*) 2871 COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) ) 2872 ;; 2873 esac 2874 } 2875 2876 _docker_volume_rm() { 2877 case "$cur" in 2878 -*) 2879 COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) 2880 ;; 2881 *) 2882 __docker_complete_volumes 2883 ;; 2884 esac 2885 } 2886 2887 _docker_volume() { 2888 local subcommands=" 2889 create 2890 inspect 2891 ls 2892 rm 2893 " 2894 __docker_subcommands "$subcommands" && return 2895 2896 case "$cur" in 2897 -*) 2898 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2899 ;; 2900 *) 2901 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 2902 ;; 2903 esac 2904 } 2905 2906 _docker_wait() { 2907 case "$cur" in 2908 -*) 2909 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2910 ;; 2911 *) 2912 __docker_complete_containers_all 2913 ;; 2914 esac 2915 } 2916 2917 _docker() { 2918 local previous_extglob_setting=$(shopt -p extglob) 2919 shopt -s extglob 2920 2921 local commands=( 2922 attach 2923 build 2924 commit 2925 cp 2926 create 2927 daemon 2928 diff 2929 events 2930 exec 2931 export 2932 history 2933 images 2934 import 2935 info 2936 inspect 2937 kill 2938 load 2939 login 2940 logout 2941 logs 2942 network 2943 node 2944 pause 2945 port 2946 ps 2947 pull 2948 push 2949 rename 2950 restart 2951 rm 2952 rmi 2953 run 2954 save 2955 search 2956 service 2957 start 2958 stats 2959 stop 2960 swarm 2961 tag 2962 top 2963 unpause 2964 update 2965 version 2966 volume 2967 wait 2968 ) 2969 2970 # These options are valid as global options for all client commands 2971 # and valid as command options for `docker daemon` 2972 local global_boolean_options=" 2973 --debug -D 2974 --tls 2975 --tlsverify 2976 " 2977 local global_options_with_args=" 2978 --config 2979 --host -H 2980 --log-level -l 2981 --tlscacert 2982 --tlscert 2983 --tlskey 2984 " 2985 2986 local host config 2987 2988 COMPREPLY=() 2989 local cur prev words cword 2990 _get_comp_words_by_ref -n : cur prev words cword 2991 2992 local command='docker' command_pos=0 subcommand_pos 2993 local counter=1 2994 while [ $counter -lt $cword ]; do 2995 case "${words[$counter]}" in 2996 # save host so that completion can use custom daemon 2997 --host|-H) 2998 (( counter++ )) 2999 host="${words[$counter]}" 3000 ;; 3001 # save config so that completion can use custom configuration directories 3002 --config) 3003 (( counter++ )) 3004 config="${words[$counter]}" 3005 ;; 3006 $(__docker_to_extglob "$global_options_with_args") ) 3007 (( counter++ )) 3008 ;; 3009 -*) 3010 ;; 3011 =) 3012 (( counter++ )) 3013 ;; 3014 *) 3015 command="${words[$counter]}" 3016 command_pos=$counter 3017 break 3018 ;; 3019 esac 3020 (( counter++ )) 3021 done 3022 3023 local binary="${words[0]}" 3024 if [[ $binary == ?(*/)dockerd ]] ; then 3025 # for the dockerd binary, we reuse completion of `docker daemon`. 3026 # dockerd does not have subcommands and global options. 3027 command=daemon 3028 command_pos=0 3029 fi 3030 3031 local completions_func=_docker_${command} 3032 declare -F $completions_func >/dev/null && $completions_func 3033 3034 eval "$previous_extglob_setting" 3035 return 0 3036 } 3037 3038 eval "$__docker_previous_extglob_setting" 3039 unset __docker_previous_extglob_setting 3040 3041 complete -F _docker docker dockerd