Sophie

Sophie

distrib > * > 2008.0 > x86_64 > by-pkgid > e5f4880dd4fb4bb2a0c92ea012333474 > files > 2

dkms-2.0.17-13mdv2008.0.src.rpm

--- SOURCES/dkms.bash-completion	2006/12/31 12:46:27	102948
+++ SOURCES/dkms.bash-completion	2007/01/14 18:00:38	108845
@@ -1,6 +1,20 @@
 # bash completion for dkms
 # Copied from the Mandriva dkms package
 
+# complete on full directory names under $1
+_subdirectories()
+{
+	COMPREPLY=( $( command ls -F $1 2>/dev/null | awk -F \/ '/\/$/ \
+		{print $1}' | grep "^$cur" ) )
+}
+
+# complete on $2 part of filenames matching pattern $1 under /usr/src
+_filename_parts()
+{
+	COMPREPLY=( $( command ls -F /usr/src 2>/dev/null | grep -E '^'$1'/$' \
+		| sed -r -e 's/^([^-]+)-(.+)\/$/\'$2'/' | grep "^$cur" ) )
+}
+
 _dkms()
 {
 	local cur prev command module i
@@ -15,9 +29,14 @@
 	else
 
 		prev=${COMP_WORDS[COMP_CWORD-1]}
+		command=${COMP_WORDS[1]}
 		case $prev in
 			-m)
-				COMPREPLY=( $( command ls -F /var/lib/dkms | grep '/$' | sed -e 's|/$||' | grep "^$cur" ) )
+				if [ "$command" = 'add' ]; then
+					_filename_parts '.*-.*' 1
+				else
+					_subdirectories /var/lib/dkms
+				fi
 				return 0
 				;;
 			-v)
@@ -28,7 +47,11 @@
 					fi
 				done
 				if [ -n "$module" ]; then
-					COMPREPLY=( $( command ls -F /var/lib/dkms/$module | grep '/$' | sed -e 's|/$||' | grep "^$cur" ) )
+					if [ "$command" = 'add' ]; then
+						_filename_parts "$module-.*" 2
+					else
+						_subdirectories /var/lib/dkms/$module
+					fi
 					return 0
 				fi
 				;;
@@ -46,7 +69,6 @@
 				;;
 		esac
 
-		command=${COMP_WORDS[1]}
 
 		if [[ "$cur" == -* ]]; then
 			case $command in