فهرست منبع

Bash completion: avoid 'compopt: command not found' errors on Mac OS

The shell builtin `compopt` is not available on the outdated bash
version 3.2.57 that ships with Mac OS.
It is used in Docker's bash completion to suppress trailing spaces
in advanced completions of hash map options, e.g. `--log-opt`.

If `compopt` is not available, the new behavior is to do nothing,
i.e. the user will have to delete the additional space.

Signed-off-by: Harald Albers <github@albersweb.de>
Harald Albers 9 سال پیش
والد
کامیت
9d8f9943e9
1فایلهای تغییر یافته به همراه22 افزوده شده و 16 حذف شده
  1. 22 16
      contrib/completion/bash/docker

+ 22 - 16
contrib/completion/bash/docker

@@ -212,6 +212,12 @@ __docker_to_extglob() {
 	echo "@($extglob)"
 	echo "@($extglob)"
 }
 }
 
 
+# suppress trailing whitespace
+__docker_nospace() {
+	# compopt is not available in ancient bash versions
+	type compopt &>/dev/null && compopt -o nospace
+}
+
 __docker_resolve_hostname() {
 __docker_resolve_hostname() {
 	command -v host >/dev/null 2>&1 || return
 	command -v host >/dev/null 2>&1 || return
 	COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
 	COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
@@ -305,7 +311,7 @@ __docker_log_driver_options() {
 			;;
 			;;
 	esac
 	esac
 
 
-	compopt -o nospace
+	__docker_nospace
 }
 }
 
 
 __docker_complete_log_driver_options() {
 __docker_complete_log_driver_options() {
@@ -314,12 +320,12 @@ __docker_complete_log_driver_options() {
 	case "${words[$cword-2]}$prev=" in
 	case "${words[$cword-2]}$prev=" in
 		*gelf-address=*)
 		*gelf-address=*)
 			COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur#=}" ) )
 			COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur#=}" ) )
-			compopt -o nospace
+			__docker_nospace
 			return
 			return
 			;;
 			;;
 		*syslog-address=*)
 		*syslog-address=*)
 			COMPREPLY=( $( compgen -W "tcp udp unix" -S "://" -- "${cur#=}" ) )
 			COMPREPLY=( $( compgen -W "tcp udp unix" -S "://" -- "${cur#=}" ) )
-			compopt -o nospace
+			__docker_nospace
 			return
 			return
 			;;
 			;;
 		*syslog-facility=*)
 		*syslog-facility=*)
@@ -492,7 +498,7 @@ _docker_cp() {
 					*)
 					*)
 						__docker_containers_all
 						__docker_containers_all
 						COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
 						COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
-						compopt -o nospace
+						__docker_nospace
 						return
 						return
 						;;
 						;;
 				esac
 				esac
@@ -599,7 +605,7 @@ _docker_daemon() {
 					return
 					return
 					;;
 					;;
 			esac
 			esac
-			compopt -o nospace
+			__docker_nospace
 			return
 			return
 			;;
 			;;
 		--log-level|-l)
 		--log-level|-l)
@@ -662,7 +668,7 @@ _docker_events() {
 	case "$prev" in
 	case "$prev" in
 		--filter|-f)
 		--filter|-f)
 			COMPREPLY=( $( compgen -S = -W "container event image" -- "$cur" ) )
 			COMPREPLY=( $( compgen -S = -W "container event image" -- "$cur" ) )
-			compopt -o nospace
+			__docker_nospace
 			return
 			return
 			;;
 			;;
 		--since|--until)
 		--since|--until)
@@ -777,7 +783,7 @@ _docker_images() {
 		--filter|-f)
 		--filter|-f)
 			COMPREPLY=( $( compgen -W "dangling=true label=" -- "$cur" ) )
 			COMPREPLY=( $( compgen -W "dangling=true label=" -- "$cur" ) )
 			if [ "$COMPREPLY" = "label=" ]; then
 			if [ "$COMPREPLY" = "label=" ]; then
-				compopt -o nospace
+				__docker_nospace
 			fi
 			fi
 			return
 			return
 			;;
 			;;
@@ -975,7 +981,7 @@ _docker_ps() {
 			;;
 			;;
 		--filter|-f)
 		--filter|-f)
 			COMPREPLY=( $( compgen -S = -W "ancestor exited id label name status" -- "$cur" ) )
 			COMPREPLY=( $( compgen -S = -W "ancestor exited id label name status" -- "$cur" ) )
-			compopt -o nospace
+			__docker_nospace
 			return
 			return
 			;;
 			;;
 		--format|-n)
 		--format|-n)
@@ -1207,18 +1213,18 @@ _docker_run() {
 					;;
 					;;
 				'')
 				'')
 					COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
 					COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
-					compopt -o nospace
+					__docker_nospace
 					;;
 					;;
 				/*)
 				/*)
 					_filedir
 					_filedir
-					compopt -o nospace
+					__docker_nospace
 					;;
 					;;
 			esac
 			esac
 			return
 			return
 			;;
 			;;
 		--env|-e)
 		--env|-e)
 			COMPREPLY=( $( compgen -e -- "$cur" ) )
 			COMPREPLY=( $( compgen -e -- "$cur" ) )
-			compopt -o nospace
+			__docker_nospace
 			return
 			return
 			;;
 			;;
 		--ipc)
 		--ipc)
@@ -1230,7 +1236,7 @@ _docker_run() {
 				*)
 				*)
 					COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
 					COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
 					if [ "$COMPREPLY" = "container:" ]; then
 					if [ "$COMPREPLY" = "container:" ]; then
-						compopt -o nospace
+						__docker_nospace
 					fi
 					fi
 					;;
 					;;
 			esac
 			esac
@@ -1243,7 +1249,7 @@ _docker_run() {
 				*)
 				*)
 					__docker_containers_running
 					__docker_containers_running
 					COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
 					COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
-					compopt -o nospace
+					__docker_nospace
 					;;
 					;;
 			esac
 			esac
 			return
 			return
@@ -1265,7 +1271,7 @@ _docker_run() {
 				*)
 				*)
 					COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") )
 					COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") )
 					if [ "${COMPREPLY[*]}" = "container:" ] ; then
 					if [ "${COMPREPLY[*]}" = "container:" ] ; then
-						compopt -o nospace
+						__docker_nospace
 					fi
 					fi
 					;;
 					;;
 			esac
 			esac
@@ -1289,12 +1295,12 @@ _docker_run() {
 					local cur=${cur##*:}
 					local cur=${cur##*:}
 					COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") )
 					COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") )
 					if [ "${COMPREPLY[*]}" != "disable" ] ; then
 					if [ "${COMPREPLY[*]}" != "disable" ] ; then
-						compopt -o nospace
+						__docker_nospace
 					fi
 					fi
 					;;
 					;;
 				*)
 				*)
 					COMPREPLY=( $( compgen -W "label apparmor" -S ":" -- "$cur") )
 					COMPREPLY=( $( compgen -W "label apparmor" -S ":" -- "$cur") )
-					compopt -o nospace
+					__docker_nospace
 					;;
 					;;
 			esac
 			esac
 			return
 			return