Tools: completion zsh: fix and simplify frames completion

This commit is contained in:
Pierre Kancir 2020-07-09 21:12:48 +02:00 committed by Peter Barker
parent be36ac836e
commit ad7f62b23d
1 changed files with 5 additions and 20 deletions

View File

@ -51,15 +51,14 @@ _sim_vehicle() {
'--aircraft=[store state and logs in named directory]:AIRCRAFT:' \
'--moddebug=[mavproxy module debug]:int:' \
'(-v --vehicle)'{-v,--vehicle}'[vehicle type]:vehicle:_sim_vehicle_vehicles' \
'(-f --frame)'{-f,--frame}'[set vehicle frame type]:frame:_copter_frames' \
'(-f --frame)'{-f,--frame}'[set vehicle frame type]:frame:_vehicle_frames' \
&& ret=0
}
_get_vehicle_type() {
# get options between "vehicle type " and closing ")", remove line return, remove spaces, anything before the opening (, remove the "|" and closing ")"
vehicles=( $($caller --help | sed -n '/vehicle type/,/)/p' | sed -e '1d' | tr -d '()' | tr '\n' ' ' | sed -e 's/ //g' -e 's/.*(//g' -e 's/[|)]/ /g') )
vehicles=( $($caller --list-vehicle) )
}
(( $+functions[_sim_vehicle_vehicles] )) ||
@ -68,8 +67,8 @@ _sim_vehicle_vehicles() {
_describe -t vehicles 'vehicle' vehicles "$@" && ret=0
}
(( $+functions[_copter_frames] )) ||
_copter_frames() {
(( $+functions[_vehicle_frames] )) ||
_vehicle_frames() {
search_vehicle=true
local_current=$CURRENT
vehicle=''
@ -90,22 +89,8 @@ do
local_current=$(( $local_current - 1 ))
done
# to get the vehicle list :
# 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 [ "$v" = "$vehicle" ]
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"))
break
fi
count=$(( $count + 1 ))
done
frames=( $($caller --list-frame $vehicle) )
_describe -t frames 'frame' frames "$@" && ret=0
}