diff --git a/bash_completion b/bash_completion index a7662877..d7254a07 100644 --- a/bash_completion +++ b/bash_completion @@ -3199,24 +3199,24 @@ _command() 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 @@ _command() # 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 *' - # 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 ) - 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%% *} diff --git a/debian/changelog b/debian/changelog index 0dadc20d..1710da90 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,8 +9,9 @@ bash-completion (20080617.4) UNRELEASED; urgency=low - fixed _cvs() - _known_hosts(): use files from UserKnownHostsFile options in addition to standard ones. + - fixed _command() to correctly prune the command line - -- David Paleino Mon, 23 Jun 2008 11:33:28 +0200 + -- David Paleino Mon, 23 Jun 2008 11:44:08 +0200 bash-completion (20080617.3) unstable; urgency=low