# 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' | tr '\n' ' ' | sed -e 's/ //g' -e 's/.*(//g' -e 's/[|)]/ /g')
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
return 0
;;
;;
-f | --frame)
-f | --frame)
opts=""
# get the calling program, remove anything after the space == all commands arguments
if [[ ${COMP_WORDS[@]} == *"ArduCopter"* ]]; then
local caller; caller=$(echo $@ | sed 's/ .*//g');
opts+=" +"
# Get everything between "frame type" and "-C", remove first and last line, get line starting with caracters and ": " sequence, remove spaces and :
opts+=" X"
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')
opts+=" airsim-copter"
local frames;
opts+=" coaxcopter"
local count=1;
opts+=" djix"
for v in $supported_vehicle_list
opts+=" dodeca-hexa"
do
opts+=" gazebo-iris"
if [[ ${COMP_WORDS[@]} == *"$v"* ]]
opts+=" heli"
then
opts+=" heli-compound"
# 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]
opts+=" heli-dual"
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")
opts+=" hexa"
break
opts+=" octa"
fi
opts+=" octa-quad"
count=$(( $count + 1 ))
opts+=" quad"
done
opts+=" scrimmage-copter"
COMPREPLY=($(compgen -W "${frames}" -- ${cur}))
opts+=" singlecopter"
return 0
opts+=" tri"
opts+=" y6"
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
fi
if [[ ${COMP_WORDS[@]} == *"AntennaTracker"* ]]; then
local context state state_descr line curcontext="$curcontext"
local context state state_descr line curcontext="$curcontext"
@ -58,96 +60,61 @@ _sim_vehicle() {
}
}
# TODO : generate with regex from sim_vehicle help
_get_vehicle_type() {
# get the calling program, remove anything after the space == all commands arguments
local caller; caller=$(echo ${words[@]} | sed 's/ .*//g');
# 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' | tr '\n' ' ' | sed -e 's/ //g' -e 's/.*(//g' -e 's/[|)]/ /g') )
# get the calling program, remove anything after the space == all commands arguments
local caller; caller=$(echo ${words[@]} | sed 's/ .*//g');
# 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 frames;
case $vehicle in
local count=1;
("ArduCopter")
for v in $supported_vehicle_list
frames=(
do
'+:Copter type +' \
if [ "$v" = "$vehicle" ]
'X:Copter type X' \
then
'airsim-copter:Copter for AirSim' \
# 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]
'coaxcopter:Copter type Coaxial' \
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"))
'djix:Copter type DJI X' \
break
'dodeca-hexa:Copter type Dodeca-hexa' \
fi
'gazebo-iris:Copter type iris for Gazebo' \
count=$(( $count + 1 ))
'heli:Heli' \
done
'heli-compound:Heli with compound' \
'heli-dual:Dual Heli' \
'hexa:Copter type hexa' \
'octa:Copter type octa' \
'octa-quad:Copter type octa-quad' \
'quad:Copter type quad' \
'scrimmage-copter:Copter for scrimmage' \
'singlecopter:Copter type singlecopter' \
'tri:Copter type tri' \
'y6:Copter type y6' \
);;
("APMrover2")
frames=(
'balancebot:Balance Bot' \
'gazebo-rover:Rover for Gazebo' \
'rover:Rover type ackerman' \
'rover-skid:Rover type skidsteering' \
'sailboat:Boat type sailboat' \
'sailboat-motor:Boat type sailboat with motor' \
'balancebot:Balance Bot' \
);;
("ArduSub")
frames=(
'gazebo-bluerov2:Sub for Gazebo' \
'vectored:Sub vectored' \
);;
("AntennaTracker")
frames=(
'tracker:Antenna Tracker' \
);;
("ArduPlane")
frames=(
'CRRCSim:Plane for CRRCSim' \
'gazebo-zephyr:Plane for Gazebo' \
'jsbsim:Plane for jsbsim' \
'plane:Plane type plane' \
'plane-dspoilers:Plane with dspoilers' \
'plane-elevon:Plane with elevon' \
'plane-jet:Plane type jet' \
'plane-tailsitter:Plane type tailsitter' \
'plane-vtailjet:Plane type vtail' \
'quadplane:Plane type quadplane' \
'quadplane-cl84:Plane type quadplane-cl84' \
'quadplane-tilttrivec:Plane type quadplane-tilttrivec' \