Merge remote-tracking branch 'origin/master' into slackware

This commit is contained in:
Igor Murzov 2011-05-02 03:11:39 +04:00
commit 08d170d2a4
9 changed files with 146 additions and 34 deletions

View File

@ -344,7 +344,7 @@ __reassemble_comp_words_by_ref()
# @param $2 words Name of variable to return words to
# @param $3 cword Name of variable to return cword to
# @param $4 cur Name of variable to return current word to complete to
# @see ___get_cword_at_cursor_by_ref()
# @see __reassemble_comp_words_by_ref()
__get_cword_at_cursor_by_ref()
{
local cword words=()
@ -366,7 +366,7 @@ __get_cword_at_cursor_by_ref()
((index--))
done
# Does found word matches cword?
# Does found word match cword?
if [[ "$i" -lt "$cword" ]]; then
# No, cword lies further;
local old_size="${#cur}"
@ -633,6 +633,7 @@ _filedir()
if [[ "$1" != -d ]]; then
# Munge xspec to contain uppercase version too
# http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
xspec=${1:+"!*.@($1|${1^^})"}
toks+=( $( compgen -f -X "$xspec" -- $quoted ) )
fi
@ -736,7 +737,7 @@ _init_completion()
i=$(( ++i ))
fi
done
prev=${words[cword-1]}
[[ $cword -ge 1 ]] && prev=${words[cword-1]} || prev=
return 0
}
@ -747,32 +748,33 @@ _init_completion()
#
_parse_help()
{
# Print first found long option, or first short if not found.
local line i option option2 IFS=$' \t\n,/|'
eval local cmd=$1
"$cmd" ${2:---help} 2>&1 | awk \
'{
if ($0 !~ /^[ \t]*-/) { next }
gsub("[,/|]", " ");
x = -1;
for (i = 1; i <= NF; i++) {
if ($i ~ /^--[^-]/) { x = i ; break }
if ($i !~ /^-/) { break }
}
if (x == -1) { x = 1 }
if ($x ~ /^---/) { next }
if ($x ~ /^--?[[]no[]]./) {
y = $x ; sub("[[]no[]]", "", y)
z = $x ; sub("[[]no[]]", "no", z)
sub("[=<{[].*", "", y)
sub("[=<{[].*", "", z)
print y
print z
}
else {
sub("[=<{[].*", "", $x)
print $x
}
}'
"$cmd" ${2:---help} 2>&1 | while read line; do
[[ $line == *([ $'\t'])-* ]] || continue
# Take first found long option, or first one (short) if not found.
option=
for i in $line; do
case $i in
---*) break ;;
--?*) option=$i ; break ;;
-?*) [[ $option ]] || option=$i ;;
*) break ;;
esac
done
[[ $option ]] || continue
# Expand --[no]foo to --foo and --nofoo
if [[ $option == *\[no\]?* ]]; then
option2=${option/\[no\]/}
printf '%s\n' "${option2%%[=<{[]*}"
option=${option/\[no\]/no}
fi
printf '%s\n' "${option%%[=<{[]*}"
done
}
# This function completes on signal names
@ -1722,6 +1724,7 @@ _filedir_xspec()
))
# Munge xspec to contain uppercase version too
# http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
eval xspec="${xspec}"
local matchop=!
if [[ $xspec == !* ]]; then

View File

@ -27,6 +27,7 @@ bashcomp_DATA = abook \
cowsay \
cpan2dist \
cpio \
cppcheck \
crontab \
cups \
cryptsetup \

View File

@ -32,7 +32,7 @@ _autoconf()
$split && return 0
if [[ "$cur" == -* ]]; then
_longopt $1
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return
fi
@ -69,7 +69,7 @@ _autoreconf()
$split && return 0
if [[ "$cur" == -* ]]; then
_longopt $1
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return 0
fi
@ -103,7 +103,7 @@ _autoscan()
$split && return 0
if [[ "$cur" == -* ]]; then
_longopt $1
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return 0
fi

View File

@ -28,7 +28,7 @@ _automake()
$split && return 0
if [[ "$cur" == -* ]]; then
_longopt $1
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return
fi
@ -67,7 +67,7 @@ _aclocal()
$split && return 0
_longopt $1
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
} &&
complete -F _aclocal aclocal aclocal-1.11

62
completions/cppcheck Normal file
View File

@ -0,0 +1,62 @@
# bash completion for cppcheck(1)
have cppcheck || return
_cppcheck()
{
local cur prev words cword
_init_completion -n = || return
local split=false
_split_longopt && split=true
case $prev in
--append|--exitcode-suppressions|--file-list|--rule-file|\
--suppressions-list)
_filedir
return
;;
-D*|--rule|--suppress|--template)
return
;;
--enable)
COMPREPLY=( $( compgen -W 'all style information unusedFunction
missingInclude' -- "$cur" ) )
return
;;
--exitcode)
COMPREPLY=( $( compgen -W '{0..255}' -- "$cur" ) )
return
;;
-I|-i)
_filedir -d
return
;;
-j)
COMPREPLY=( $( compgen -W '{2..16}' -- "$cur" ) )
return
;;
--xml-version)
COMPREPLY=( $( compgen -W '1 2' -- "$cur" ) )
return
;;
esac
$split && return
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == @(-D|*=) ]] && compopt -o nospace
else
_filedir @(cpp|cxx|cc|c++|c|tpp|txx)
fi
} &&
complete -F _cppcheck cppcheck
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh

View File

@ -40,7 +40,8 @@ _xsltproc()
return 0
if [[ "$cur" == -* ]]; then
_longopt xsltproc
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
COMPREPLY=( "${COMPREPLY[@]%:}" )
else
_filedir '@(xsl|xslt|xml)'
fi

View File

@ -0,0 +1 @@
assert_source_completions cppcheck

View File

@ -0,0 +1,20 @@
proc setup {} {
save_env
}
proc teardown {} {
assert_env_unmodified
}
setup
assert_complete_any "cppcheck "
sync_after_int
teardown

View File

@ -48,6 +48,22 @@ assert_bash_list {" a"} $cmd $test
sync_after_int
set test "|a "; # | = cursor position
set cmd {COMP_WORDS=(a); COMP_CWORD=0; COMP_LINE='a '; COMP_POINT=0; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
assert_bash_list {" "} $cmd $test
sync_after_int
set test " | a "; # | = cursor position
set cmd {COMP_WORDS=(a); COMP_CWORD=0; COMP_LINE=' a '; COMP_POINT=1; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
assert_bash_list {" "} $cmd $test
sync_after_int
set test "a b |"; # | = cursor position
set cmd {COMP_WORDS=(a b ''); COMP_CWORD=2; COMP_LINE='a b '; COMP_POINT=4; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
assert_bash_list {" b"} $cmd $test
@ -72,6 +88,14 @@ assert_bash_list {"b a"} $cmd $test
sync_after_int
set test "a | b"; # | = cursor position
set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=2; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
assert_bash_list {" a"} $cmd $test
sync_after_int
set test {a b\ c| should return b\ c}; # | = cursor position
set cmd {COMP_WORDS=(a 'b\ c'); COMP_CWORD=1; COMP_LINE='a b\ c'; COMP_POINT=6; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
assert_bash_list {"b\\ c a"} $cmd $test