Tools: completion bash: fix and simplify frames completion

This commit is contained in:
Pierre Kancir 2020-07-09 21:28:47 +02:00 committed by Peter Barker
parent ad7f62b23d
commit 7292ee8ec6
1 changed files with 2 additions and 5 deletions

View File

@ -65,7 +65,7 @@ _sim_vehicle() {
# get the calling program, remove anything after the space == all commands arguments
local caller; caller=$(echo $@ | sed 's/ .*//g');
# get options between "vehicle type " and closing ")", remove line return, remove spaces, anything before the opening (, remove the "|" and closing ")"
opts=$($caller --help | sed -n '/vehicle type/,/)/p' | sed -e '1d' | tr -d '()' | tr '\n' ' ' | sed -e 's/ //g' -e 's/.*(//g' -e 's/[|)]/ /g')
opts=$($caller --list-vehicle)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
@ -75,16 +75,13 @@ _sim_vehicle() {
# Get everything between "frame type" and "-C", remove first and last line, get line starting with caracters and ": " sequence, remove spaces and :
local supported_vehicle_list=$($caller --help | sed -n '/frame type/,/-C/p' | sed -e '1d' -e '$d' | sed -n 's/\(.*: \).*/\1/p' | sed -e 's/ //g' -e 's/://g')
local frames;
local count=1;
for v in $supported_vehicle_list
do
if [[ ${COMP_WORDS[@]} == *"$v"* ]]
then
# Get everything between "frame type" and "-C", remove first and last line and change starting space by " :", change newlines to space, remove spaces then change vehicle type enclose by ":" by newline and change "|" by space, remove first line, get line "count" that match supported_vehicle_list[count]
frames=$($caller --help | sed -n '/frame type/,/-C/p' | sed -e '1d' -e '$d' -e 's/^\s*A/ :A/g' | tr '\n' ' ' | sed -e 's/ //g' -e 's/:\w*:/\n/g' -e 's/[|]/ /g' | sed '1d' | sed "${count}q;d")
frames=$($caller --list-frame "$v")
break
fi
count=$(( $count + 1 ))
done
COMPREPLY=($(compgen -W "${frames}" -- ${cur}))
return 0