[Bash-completion-commits] ./current r1136: fixed _command() to correctly prune the command line

David Paleino d.paleino at gmail.com
Mon Jun 23 09:44:42 UTC 2008


------------------------------------------------------------
revno: 1136
committer: David Paleino <d.paleino at gmail.com>
branch nick: current
timestamp: Mon 2008-06-23 11:44:42 +0200
message:
  fixed _command() to correctly prune the command line
modified:
  bash_completion
  debian/changelog
-------------- next part --------------
=== modified file 'bash_completion'
--- a/bash_completion	2008-06-23 09:33:52 +0000
+++ b/bash_completion	2008-06-23 09:44:42 +0000
@@ -3199,24 +3199,24 @@
 	local cur func cline cspec noglob cmd done i \
 	      _COMMAND_FUNC _COMMAND_FUNC_ARGS
 
+	_remove_comp_word
 	COMPREPLY=()
 	cur=`_get_cword`
 	# If the the first arguments following our meta-command-invoker are
 	# switches, get rid of them. Most definitely not foolproof.
 	done=
 	while [ -z $done ] ; do
-	cmd=${COMP_WORDS[1]}
-	    if [[ "$cmd" == -* ]] && [ $COMP_CWORD -gt 1 ]; then
-		for (( i=1 ; i<=COMP_CWORD ; i++)) ; do
-		    COMP_WORDS[i]=${COMP_WORDS[i+1]}
-		done
-		COMP_CWORD=$(($COMP_CWORD-1))
+	cmd=${COMP_WORDS[0]}
+	    if [[ "$cmd" == -* ]] && [ $COMP_CWORD -ge 1 ]; then
+	    	_remove_comp_word
+	    elif [[ "$cmd" == -* ]] && [[ $COMP_CWORD -eq 0 ]]; then
+	    	return
 	    else
-		done=1
+			done=1
 	    fi
 	done
 
-	if [ $COMP_CWORD -eq 1 ]; then
+	if [ $COMP_CWORD -eq 0 ]; then
 		COMPREPLY=( $( compgen -c -- $cur ) )
 	elif complete -p $cmd &>/dev/null; then
 		cspec=$( complete -p $cmd )
@@ -3227,35 +3227,19 @@
 			# so we can set them before handing off to regular
 			# completion routine
 
-			# set current token number to 1 less than now
-			COMP_CWORD=$(( $COMP_CWORD - 1 ))
-
 			# get function name
 			func=${cspec#*-F }
 			func=${func%% *}
-			# get current command line minus initial command
-			cline="${COMP_LINE#*( )$1 }"
-			# save noglob state
-		      	shopt -qo noglob; noglob=$?
-			# turn on noglob, as things like 'sudo ls *<Tab>'
-			# don't work otherwise
-		  	shopt -so noglob
-			# split current command line tokens into array
-			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=`_get_cword`
-			_COMMAND_FUNC=$func
-			_COMMAND_FUNC_ARGS=( $cmd $2 $3 )
-			COMP_LINE=$cline
-			COMP_POINT=$(( ${COMP_POINT} - ${#1} - 1 ))
-			$func $cmd $2 $3
+			
+			if [[ ${#COMP_WORDS[@]} -ge 2 ]]; then
+				$func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" "${COMP_WORDS[${#COMP_WORDS[@]}-2]}"
+			else
+				$func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1}}"
+			fi
+
 			# remove any \: generated by a command that doesn't
 			# default to filenames or dirnames (e.g. sudo chown)
+			# FIXME: I'm pretty sure this does not work!
 			if [ "${cspec#*-o }" != "$cspec" ]; then
 				cspec=${cspec#*-o }
 				cspec=${cspec%% *}

=== modified file 'debian/changelog'
--- a/debian/changelog	2008-06-23 09:33:52 +0000
+++ b/debian/changelog	2008-06-23 09:44:42 +0000
@@ -9,8 +9,9 @@
     - fixed _cvs()
     - _known_hosts(): use files from UserKnownHostsFile options in 
                       addition to standard ones.
+    - fixed _command() to correctly prune the command line
 
- -- David Paleino <d.paleino at gmail.com>  Mon, 23 Jun 2008 11:33:28 +0200
+ -- David Paleino <d.paleino at gmail.com>  Mon, 23 Jun 2008 11:44:08 +0200
 
 bash-completion (20080617.3) unstable; urgency=low
 



More information about the Bash-completion-commits mailing list