Tools: completion bash: correct word reuse skipping

This commit is contained in:
Pierre Kancir 2020-04-03 17:38:17 +02:00 committed by Andrew Tridgell
parent 3262175f86
commit 5736e28693
3 changed files with 42 additions and 34 deletions

View File

@ -8,35 +8,43 @@ _ap_bin()
opts="--help -h"
opts+=" --wipe -w"
opts+=" --unhide-groups -u"
opts+=" --speedup -s SPEEDUP"
opts+=" --rate -r"
opts+=" --console -C"
opts+=" --instance -I"
opts+=" --synthetic-clock -S"
opts+=" --home -O"
opts+=" --model -M"
opts+=" --config"
opts+=" --fg -F"
opts+=" --disable-fgview"
opts+=" --gimbal"
opts+=" --autotest-dir"
opts+=" --defaults"
opts+=" --uartA"
opts+=" --uartB"
opts+=" --uartC"
opts+=" --uartD"
opts+=" --uartE"
opts+=" --uartF"
opts+=" --uartG"
opts+=" --uartH"
opts+=" --rtscts"
opts+=" --base-port"
opts+=" --rc-in-port"
opts+=" --sim-address"
opts+=" --sim-port-in"
opts+=" --sim-port-out"
opts+=" --irlock-port"
opts+=" --unhide-groups -u"
opts+=" --speedup -s SPEEDUP"
opts+=" --rate -r"
opts+=" --console -C"
opts+=" --instance -I"
opts+=" --synthetic-clock -S"
opts+=" --home -O"
opts+=" --model -M"
opts+=" --config"
opts+=" --fg -F"
opts+=" --disable-fgview"
opts+=" --gimbal"
opts+=" --autotest-dir"
opts+=" --defaults"
opts+=" --uartA"
opts+=" --uartB"
opts+=" --uartC"
opts+=" --uartD"
opts+=" --uartE"
opts+=" --uartF"
opts+=" --uartG"
opts+=" --uartH"
opts+=" --rtscts"
opts+=" --base-port"
opts+=" --rc-in-port"
opts+=" --sim-address"
opts+=" --sim-port-in"
opts+=" --sim-port-out"
opts+=" --irlock-port"
# Prevent word reuse
lim=$((COMP_CWORD - 1))
for i in $(seq 0 $lim); do
if [[ $opts == *"${COMP_WORDS[i]}"* ]]; then
opts=${opts//${COMP_WORDS[i]}/}
opts=${opts//--${COMP_WORDS[i]}/}
fi
done
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
}

View File

@ -55,8 +55,8 @@ _sim_vehicle() {
lim=$((COMP_CWORD - 1))
for i in $(seq 0 $lim); do
if [[ $opts == *"${COMP_WORDS[i]}"* ]]; then
opts=${opts/" ${COMP_WORDS[i]}"/}
opts=${opts/" --${COMP_WORDS[i]}"/}
opts=${opts//${COMP_WORDS[i]}/}
opts=${opts//--${COMP_WORDS[i]}/}
fi
done

View File

@ -46,12 +46,12 @@ _waf()
for i in $( seq 0 $lim )
do
if [[ $opts == *"${COMP_WORDS[i]}"* ]]; then
opts=${opts/" ${COMP_WORDS[i]}"}
opts=${opts/" --${COMP_WORDS[i]}"}
opts=${opts//${COMP_WORDS[i]}/}
opts=${opts//--${COMP_WORDS[i]}/}
fi
done
case $prev in
case $prev in
--board)
opts=$(./waf list_boards | sed -e '$d')
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))