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