github.com/endocode/docker@v1.4.2-0.20160113120958-46eb4700391e/contrib/completion/bash/docker (about)

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