github.com/uppal0016/docker_new@v0.0.0-20240123060250-1c98be13ac2c/contrib/completion/bash/docker (about)

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