fixed _command() to correctly prune the command line

This commit is contained in:
David Paleino 2008-06-23 11:44:42 +02:00
parent 68f63fc9ed
commit 2f07561d2a
2 changed files with 18 additions and 33 deletions

View File

@ -3199,24 +3199,24 @@ _command()
local cur func cline cspec noglob cmd done i \ local cur func cline cspec noglob cmd done i \
_COMMAND_FUNC _COMMAND_FUNC_ARGS _COMMAND_FUNC _COMMAND_FUNC_ARGS
_remove_comp_word
COMPREPLY=() COMPREPLY=()
cur=`_get_cword` cur=`_get_cword`
# If the the first arguments following our meta-command-invoker are # If the the first arguments following our meta-command-invoker are
# switches, get rid of them. Most definitely not foolproof. # switches, get rid of them. Most definitely not foolproof.
done= done=
while [ -z $done ] ; do while [ -z $done ] ; do
cmd=${COMP_WORDS[1]} cmd=${COMP_WORDS[0]}
if [[ "$cmd" == -* ]] && [ $COMP_CWORD -gt 1 ]; then if [[ "$cmd" == -* ]] && [ $COMP_CWORD -ge 1 ]; then
for (( i=1 ; i<=COMP_CWORD ; i++)) ; do _remove_comp_word
COMP_WORDS[i]=${COMP_WORDS[i+1]} elif [[ "$cmd" == -* ]] && [[ $COMP_CWORD -eq 0 ]]; then
done return
COMP_CWORD=$(($COMP_CWORD-1))
else else
done=1 done=1
fi fi
done done
if [ $COMP_CWORD -eq 1 ]; then if [ $COMP_CWORD -eq 0 ]; then
COMPREPLY=( $( compgen -c -- $cur ) ) COMPREPLY=( $( compgen -c -- $cur ) )
elif complete -p $cmd &>/dev/null; then elif complete -p $cmd &>/dev/null; then
cspec=$( complete -p $cmd ) cspec=$( complete -p $cmd )
@ -3227,35 +3227,19 @@ _command()
# so we can set them before handing off to regular # so we can set them before handing off to regular
# completion routine # completion routine
# set current token number to 1 less than now
COMP_CWORD=$(( $COMP_CWORD - 1 ))
# get function name # get function name
func=${cspec#*-F } func=${cspec#*-F }
func=${func%% *} func=${func%% *}
# get current command line minus initial command
cline="${COMP_LINE#*( )$1 }" if [[ ${#COMP_WORDS[@]} -ge 2 ]]; then
# save noglob state $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" "${COMP_WORDS[${#COMP_WORDS[@]}-2]}"
shopt -qo noglob; noglob=$? else
# turn on noglob, as things like 'sudo ls *<Tab>' $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1}}"
# don't work otherwise fi
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
# remove any \: generated by a command that doesn't # remove any \: generated by a command that doesn't
# default to filenames or dirnames (e.g. sudo chown) # default to filenames or dirnames (e.g. sudo chown)
# FIXME: I'm pretty sure this does not work!
if [ "${cspec#*-o }" != "$cspec" ]; then if [ "${cspec#*-o }" != "$cspec" ]; then
cspec=${cspec#*-o } cspec=${cspec#*-o }
cspec=${cspec%% *} cspec=${cspec%% *}

3
debian/changelog vendored
View File

@ -9,8 +9,9 @@ bash-completion (20080617.4) UNRELEASED; urgency=low
- fixed _cvs() - fixed _cvs()
- _known_hosts(): use files from UserKnownHostsFile options in - _known_hosts(): use files from UserKnownHostsFile options in
addition to standard ones. addition to standard ones.
- fixed _command() to correctly prune the command line
-- David Paleino <d.paleino@gmail.com> Mon, 23 Jun 2008 11:33:28 +0200 -- David Paleino <d.paleino@gmail.com> Mon, 23 Jun 2008 11:44:08 +0200
bash-completion (20080617.3) unstable; urgency=low bash-completion (20080617.3) unstable; urgency=low