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