ardupilot/Tools/completion/bash/_sim_vehicle

97 lines
2.7 KiB
Plaintext
Raw Normal View History

2019-10-28 08:41:00 -03:00
#!/usr/bin/env bash
_sim_vehicle() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD - 1]}"
# TODO: generate for waf help
opts="--help -h"
opts+=" -j --jobs"
opts+=" -N --no-rebuild"
opts+=" -D --debug"
opts+=" -c --clean"
opts+=" -I --instance"
opts+=" -V --valgrind"
opts+=" --callgrind"
opts+=" -T --tracker"
opts+=" -A --sitl-instance-args"
opts+=" -G --gdb"
opts+=" -g --gdb-stopped"
opts+=" --lldb"
opts+=" --lldb-stopped"
opts+=" -d --delay-start"
opts+=" -B --breakpoint"
opts+=" -M --mavlink-gimbal"
opts+=" -L --location"
opts+=" -l --custom-location"
opts+=" -S --speedup"
opts+=" -t --tracker-location"
opts+=" -w --wipe-eeprom"
opts+=" -m --mavproxy-args"
opts+=" --strace"
opts+=" --model"
opts+=" --use-dir"
opts+=" --no-mavproxy"
opts+=" --fresh-params"
opts+=" --mcast"
opts+=" --osd"
opts+=" --tonealarm"
opts+=" --rgbled"
opts+=" --add-param-file"
opts+=" --no-extra-ports"
opts+=" -Z --swarm"
opts+=" --flash-storage"
opts+=" --out"
opts+=" --map"
opts+=" --console"
opts+=" --aircraft"
opts+=" --moddebug"
opts+=" -v --vehicle"
opts+=" -f --frame"
# Prevent word reuse TODO: add -vvv case
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]}/}
2019-10-28 08:41:00 -03:00
fi
done
case $prev in
-v | --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 --list-vehicle)
2019-10-28 08:41:00 -03:00
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
-f | --frame)
# get the calling program, remove anything after the space == all commands arguments
local caller; caller=$(echo $@ | sed 's/ .*//g');
# 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;
for v in $supported_vehicle_list
do
if [[ ${COMP_WORDS[@]} == *"$v"* ]]
then
frames=$($caller --list-frame "$v")
break
fi
done
COMPREPLY=($(compgen -W "${frames}" -- ${cur}))
return 0
2019-10-28 08:41:00 -03:00
;;
esac
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
}
complete -F _sim_vehicle sim_vehicle.py