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

@ -37,6 +37,14 @@ _ap_bin()
opts+=" --sim-port-in" opts+=" --sim-port-in"
opts+=" --sim-port-out" opts+=" --sim-port-out"
opts+=" --irlock-port" 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}) ) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
} }

View File

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

View File

@ -46,8 +46,8 @@ _waf()
for i in $( seq 0 $lim ) for i in $( seq 0 $lim )
do do
if [[ $opts == *"${COMP_WORDS[i]}"* ]]; then 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 fi
done done