Protect java class completion from unusual input, get rid of one grep.

This commit is contained in:
Ville Skyttä 2009-05-13 00:01:35 +03:00
parent 147642d722
commit f5991cc3c1

View File

@ -4735,19 +4735,19 @@ _java_classes()
# parse each classpath element for classes # parse each classpath element for classes
for i in ${classpath//:/ }; do for i in ${classpath//:/ }; do
if [ -r $i ] && [[ "$i" == *.@(jar|zip) ]]; then if [ -r $i ] && [[ "$i" == *.@(jar|zip) ]]; then
if type zipinfo &> /dev/null; then if type zipinfo &>/dev/null; then
COMPREPLY=( "${COMPREPLY[@]}" $( zipinfo -1 \ COMPREPLY=( "${COMPREPLY[@]}" $( zipinfo -1 \
"$i" | grep "^$cur" | grep '\.class$' | \ "$i" "$cur*" 2>/dev/null | \
grep -v "\\$" ) ) grep '^[^$]*\.class$' ) )
else else
COMPREPLY=( "${COMPREPLY[@]}" $( jar tf "$i" \ COMPREPLY=( "${COMPREPLY[@]}" $( jar tf "$i" \
"$cur" | grep "\.class$" | grep -v "\\$" ) ) "$cur" | grep '^[^$]*\.class$' ) )
fi fi
elif [ -d $i ]; then elif [ -d $i ]; then
i=${i%/} i=${i%/}
# See bug #496828 # See Debian bug #496828
COMPREPLY=( "${COMPREPLY[@]}" $( find "$i" -type f \ COMPREPLY=( "${COMPREPLY[@]}" $( find "$i" -type f \
-maxdepth 1 -path "$i/$cur*.class" 2>/dev/null | \ -maxdepth 1 -path "$i/$cur*.class" 2>/dev/null | \
grep -v "\\$" | sed -e "s|^$i/||" ) ) grep -v "\\$" | sed -e "s|^$i/||" ) )