From 5736e28693d2ac2bbd41f1a9e65969bd717e7891 Mon Sep 17 00:00:00 2001 From: Pierre Kancir Date: Fri, 3 Apr 2020 17:38:17 +0200 Subject: [PATCH] Tools: completion bash: correct word reuse skipping --- Tools/completion/bash/_ap_bin | 66 +++++++++++++++++------------- Tools/completion/bash/_sim_vehicle | 4 +- Tools/completion/bash/_waf | 6 +-- 3 files changed, 42 insertions(+), 34 deletions(-) diff --git a/Tools/completion/bash/_ap_bin b/Tools/completion/bash/_ap_bin index a119d04169..fc3367da94 100644 --- a/Tools/completion/bash/_ap_bin +++ b/Tools/completion/bash/_ap_bin @@ -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}) ) } diff --git a/Tools/completion/bash/_sim_vehicle b/Tools/completion/bash/_sim_vehicle index 64d80edcec..0c6bc1fcca 100644 --- a/Tools/completion/bash/_sim_vehicle +++ b/Tools/completion/bash/_sim_vehicle @@ -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 diff --git a/Tools/completion/bash/_waf b/Tools/completion/bash/_waf index 98e504c0c7..27703ad756 100644 --- a/Tools/completion/bash/_waf +++ b/Tools/completion/bash/_waf @@ -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}))