route(1) completion code cleanups.

This commit is contained in:
Ville Skyttä 2009-10-31 13:50:23 +02:00
parent 774d50a9c9
commit 50b4b8459f

View File

@ -84,23 +84,18 @@ _route()
return 0
fi
COMPREPLY=( $( compgen -W 'add del -host -net netmask metric mss \
window irtt reject mod dyn reinstate dev \
default gw' -- "$cur" ) )
COMPREPLY=( $( echo " ${COMP_WORDS[@]}" | \
(while read -d ' ' i; do
[ "$i" == "" ] && continue
# flatten array with spaces on either side,
# otherwise we cannot grep on word
# boundaries of first and last word
COMPREPLY=" ${COMPREPLY[@]} "
# remove word from list of completions
COMPREPLY=( ${COMPREPLY/ $i / } )
# Remove already given options from completions
local i found
for opt in add del -host -net netmask metric mss window irtt reject mod \
dyn reinstate dev default gw; do
found=false
for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do
[ "${COMP_WORDS[i]}" = "$opt" ] && found=true && break
done
echo "${COMPREPLY[@]}")
) )
return 0
$found || COMPREPLY[${#COMPREPLY[@]}]="$opt"
done
COMPREPLY=( $( compgen -W '"${COMPREPLY[@]}"' -- "$cur" ) )
} &&
complete -F _route route