- patch from Ilya <ilya@po4ta.com> to fix _command(), so that (in his words):

- Now work ok for commands with spaces
  - Work if command completion is set with complete -W '...'
  - Work in case when complete -F function and function use COMP_POINT or
    COMP_LINE
  - Fixed bug of incorrect completion list in case 'sudo vim <Tab>'
This commit is contained in:
ianmacd 2003-06-07 21:09:34 +00:00
parent c57877f92e
commit 226779870d

View File

@ -1,6 +1,6 @@
# bash_completion - some programmable completion functions for bash 2.05b # bash_completion - some programmable completion functions for bash 2.05b
# #
# $Id: bash_completion,v 1.576 2003/06/07 22:59:37 ianmacd Exp $ # $Id: bash_completion,v 1.577 2003/06/07 23:09:34 ianmacd Exp $
# #
# Copyright (C) Ian Macdonald <ian@caliban.org> # Copyright (C) Ian Macdonald <ian@caliban.org>
# #
@ -1302,14 +1302,14 @@ _rpm()
cur=${COMP_WORDS[COMP_CWORD]} cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]} prev=${COMP_WORDS[COMP_CWORD-1]}
options="" options=""
ver=$(rpm --version); ver=${ver##* } ver=$(rpm --version); ver=${ver##* }
if [[ "$ver" > "4.0.4" ]]; then if [[ "$ver" > "4.0.4" ]]; then
options="--nodigest" options="--nodigest"
fi fi
if [[ "$ver" > "4.0.99" ]]; then if [[ "$ver" > "4.0.99" ]]; then
options="$options --nosignature" options="$options --nosignature"
fi fi
if [ $COMP_CWORD -eq 1 ]; then if [ $COMP_CWORD -eq 1 ]; then
# first parameter on line # first parameter on line
@ -2484,16 +2484,19 @@ fi
# #
_command() _command()
{ {
local cur func cline cspec noglob local cur func cline cspec noglob IFS=$' \t\n' cmd
COMPREPLY=() COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]} cur=${COMP_WORDS[COMP_CWORD]}
cmd=${COMP_WORDS[1]}
if [ $COMP_CWORD -eq 1 ]; then if [ $COMP_CWORD -eq 1 ]; then
IFS=$'\n\t'
COMPREPLY=( $( compgen -c -- $cur ) ) COMPREPLY=( $( compgen -c -- $cur ) )
elif complete -p ${COMP_WORDS[1]} &>/dev/null; then IFS=$' \t\n'
cspec=$( complete -p ${COMP_WORDS[1]} ) elif complete -p $cmd &>/dev/null; then
if [ "${cspec#*-F }" != "$cspec" ]; then cspec=$( complete -p $cmd )
if [ "${cspec#* -F }" != "$cspec" ]; then
# complete -F <function> # complete -F <function>
# #
# COMP_CWORD and COMP_WORDS() are not read-only, # COMP_CWORD and COMP_WORDS() are not read-only,
@ -2516,26 +2519,31 @@ _command()
COMP_WORDS=( $cline ) COMP_WORDS=( $cline )
# reset noglob if necessary # reset noglob if necessary
[ $noglob -eq 1 ] && shopt -uo noglob [ $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 # 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)
if [ "${cspec#*-o }" != "$cspec" ]; then if [ "${cspec#*-o }" != "$cspec" ]; then
cspec=${cspec#*-o } cspec=${cspec#*-o }
cspec=${cspec%% *} cspec=${cspec%% *}
if [[ "$cspec" != @(dir|file)names ]]; then if [[ "$cspec" != @(dir|file)names ]]; then
COMPREPLY=( "${COMPREPLY[@]//\\\\:/:}" ) IFS=$'\n\t'
COMPREPLY=( ${COMPREPLY[@]//\\\\:/:} )
IFS=$' \t\n'
fi fi
fi fi
elif [ "${cspec#*-[abcdefgjkvu]}" != "$cspec" ]; then elif [ -n "$cspec" ]; then
# complete -[abcdefgjkvu] cspec=${cspec#complete};
func=$( echo $cspec | \ cspec=${cspec%%$cmd};
sed -e 's/^.*\(-[abcdefgjkvu]\).*$/\1/' ) IFS=$'\n\t'
COMPREPLY=( $( compgen $func -- $cur ) ) COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) );
elif [ "${cspec#*-A}" != "$cspec" ]; then IFS=$' \t\n'
# complete -A <type>
func=${cspec#*-A }
func=${func%% *}
COMPREPLY=( $( compgen -A $func -- $cur ) )
fi fi
fi fi
@ -2546,7 +2554,7 @@ complete -F _command $filenames nohup exec nice eval strace time ltrace then \
_root_command() _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 complete -F _root_command $filenames sudo fakeroot
@ -4731,11 +4739,11 @@ _dict()
case "$prev" in case "$prev" in
-@(d|-database|i|info)) -@(d|-database|i|info))
COMPREPLY=( $( compgen -W '$( _dictdata -D )' -- "$cur" ) ) COMPREPLY=( $( compgen -W '$( _dictdata -D )' -- "$cur" ) )
return 0 return 0
;; ;;
-@(s|-strategy)) -@(s|-strategy))
COMPREPLY=( $( compgen -W '$( _dictdata -S )' -- "$cur" ) ) COMPREPLY=( $( compgen -W '$( _dictdata -S )' -- "$cur" ) )
return 0 return 0
;; ;;
*) *)