- 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:
parent
c57877f92e
commit
226779870d
@ -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>
|
||||||
#
|
#
|
||||||
@ -2484,15 +2484,18 @@ 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
|
||||||
|
cspec=$( complete -p $cmd )
|
||||||
if [ "${cspec#* -F }" != "$cspec" ]; then
|
if [ "${cspec#* -F }" != "$cspec" ]; then
|
||||||
# complete -F <function>
|
# complete -F <function>
|
||||||
#
|
#
|
||||||
@ -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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user