Index: bash_completion
===================================================================
RCS file: /var/cvs/bash_completion/bash_completion,v
retrieving revision 1.576
retrieving revision 1.577
diff -u -r1.576 -r1.577
--- bash_completion	7 Jun 2003 22:59:37 -0000	1.576
+++ bash_completion	7 Jun 2003 23:09:34 -0000	1.577
@@ -2484,16 +2484,19 @@
 #
 _command()
 {
-	local cur func cline cspec noglob
+	local cur func cline cspec noglob IFS=$' \t\n' cmd
 
 	COMPREPLY=()
 	cur=${COMP_WORDS[COMP_CWORD]}
+	cmd=${COMP_WORDS[1]}
 
 	if [ $COMP_CWORD -eq 1 ]; then
+		IFS=$'\n\t'
 		COMPREPLY=( $( compgen -c -- $cur ) )
-	elif complete -p ${COMP_WORDS[1]} &>/dev/null; then
-		cspec=$( complete -p ${COMP_WORDS[1]} )
-		if [ "${cspec#*-F }" != "$cspec" ]; then
+		IFS=$' \t\n'
+	elif complete -p $cmd &>/dev/null; then
+		cspec=$( complete -p $cmd )
+		if [ "${cspec#* -F }" != "$cspec" ]; then
 			# complete -F <function>
 			#
 			# COMP_CWORD and COMP_WORDS() are not read-only,
@@ -2516,26 +2519,31 @@
 			COMP_WORDS=( $cline )
 			# reset noglob if necessary
 			[ $noglob -eq 1 ] && shopt -uo noglob
-			$func $cline
+			# this is needed in case user finished entering command and pressed tab (e.g. sudo ls <Tab>)
+			COMP_CWORD=$(( $COMP_CWORD > 0 ? $COMP_CWORD : 1 ))
+			cur=${COMP_WORDS[COMP_CWORD]}
+			_COMMAND_FUNC=$func
+			_COMMAND_FUNC_ARGS=( $cmd $2 $3 )
+			COMP_LINE=$cline
+			COMP_POINT=$(( ${COMP_POINT} - ${#1} - 1 ))
+			$func $cmd $2 $3
 			# remove any \: generated by a command that doesn't
 			# default to filenames or dirnames (e.g. sudo chown)
 			if [ "${cspec#*-o }" != "$cspec" ]; then
 				cspec=${cspec#*-o }
 				cspec=${cspec%% *}
 				if [[ "$cspec" != @(dir|file)names ]]; then
-					COMPREPLY=( "${COMPREPLY[@]//\\\\:/:}" )
+					IFS=$'\n\t'
+					COMPREPLY=( ${COMPREPLY[@]//\\\\:/:} )
+					IFS=$' \t\n'
 				fi
 			fi
-		elif [ "${cspec#*-[abcdefgjkvu]}" != "$cspec" ]; then
-			# complete -[abcdefgjkvu]
-			func=$( echo $cspec | \
-				sed -e 's/^.*\(-[abcdefgjkvu]\).*$/\1/' )
-			COMPREPLY=( $( compgen $func -- $cur ) )
-		elif [ "${cspec#*-A}" != "$cspec" ]; then
-			# complete -A <type>
-			func=${cspec#*-A }
-			func=${func%% *}
-			COMPREPLY=( $( compgen -A $func -- $cur ) )
+		elif [ -n "$cspec" ]; then
+			cspec=${cspec#complete};
+			cspec=${cspec%%$cmd};
+			IFS=$'\n\t'
+			COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) );
+			IFS=$' \t\n'
 		fi
 	fi
 
@@ -2546,7 +2554,7 @@
 
 _root_command()
 {
-	PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin _command $1
+	PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin _command $1 $2 $3
 }
 complete -F _root_command $filenames sudo fakeroot
 
