[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 0f2656669fbdf627a3ddf11bdb72e3ec9cef68fd

Guillaume Rousse guillomovitch at zarb.org
Mon Mar 30 20:05:41 UTC 2009


The following commit has been merged in the master branch:
commit 2c3fd00439d4d5e6effa4c7dc4e24a55b6d9efbe
Author: Guillaume Rousse <guillomovitch at zarb.org>
Date:   Mon Mar 30 21:56:09 2009 +0200

    factorize session completions

diff --git a/contrib/screen b/contrib/screen
index 7996f4f..2ac22b1 100644
--- a/contrib/screen
+++ b/contrib/screen
@@ -6,6 +6,19 @@
 # screen(1) completion
 #
 have screen &&
+_screen_sessions()
+{
+	local pattern
+
+	if [ -n "$1" ]; then
+		pattern=".*$1.*"
+	else
+	pattern=".*"
+	fi
+
+	COMPREPLY=( $( command screen -ls | \
+		sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\)'$pattern'$|\1|p' ) )
+} &&
 _screen()
 {
 	local cur prev preprev
@@ -16,32 +29,34 @@ _screen()
 
 	[ "$COMP_CWORD" -ge 2 ] && preprev=${COMP_WORDS[COMP_CWORD-2]}
 
-	if [ "$preprev" = "-d" -o "$preprev" = "-D" -a "$prev" = "-r" -o \
-	     "$prev" = "-R" ]; then
-		# list all
-		COMPREPLY=( $( command screen -ls | \
-				sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*$|\1|p' ) )
-	else
-		case "$prev" in
+	case "$preprev" in
+		-[dD])
+			_screen_sessions
+			return 0
+		;;
+	esac
+
+	case "$prev" in
 		-[rR])
 			# list detached
-			COMPREPLY=( $( command screen -ls | \
-					sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*Detached.*$|\1|p' ) )
+			_screen_sessions 'Detached'
+			return 0
 			;;
 		-[dDx])
 			# list attached
-			COMPREPLY=( $( command screen -ls | \
-					sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*Attached.*$|\1|p' ) )
+			_screen_sessions 'Attached'
+			return 0
 			;;
 		-s)
 			# shells
 			COMPREPLY=( $( grep ^${cur:-[^#]} /etc/shells ) )
 			;;
-		*)
+		-c)
+			_filedirs
+			return 0
 			;;
 		esac
 	fi
 
-	return 0
 } &&
 complete -F _screen $default screen

-- 
bash-completion



More information about the Bash-completion-commits mailing list