From 50b4b8459f6cf100d96b7720a40b1b9c1a02568a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 31 Oct 2009 13:50:23 +0200 Subject: [PATCH] route(1) completion code cleanups. --- contrib/net-tools | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/contrib/net-tools b/contrib/net-tools index b144762a..a88aa2ac 100644 --- a/contrib/net-tools +++ b/contrib/net-tools @@ -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