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