From fce6aad00fc805329a92345fcf0e94e881fa9a76 Mon Sep 17 00:00:00 2001 From: Pierre Kancir Date: Mon, 28 Oct 2019 12:41:00 +0100 Subject: [PATCH] Tools: add initial bash completion --- Tools/completion/bash/_sim_vehicle | 141 +++++++++++++++++++++++++++++ Tools/completion/bash/_waf | 67 ++++++++++++++ Tools/completion/completion.bash | 6 ++ 3 files changed, 214 insertions(+) create mode 100644 Tools/completion/bash/_sim_vehicle create mode 100644 Tools/completion/bash/_waf create mode 100644 Tools/completion/completion.bash diff --git a/Tools/completion/bash/_sim_vehicle b/Tools/completion/bash/_sim_vehicle new file mode 100644 index 0000000000..fc08f7552b --- /dev/null +++ b/Tools/completion/bash/_sim_vehicle @@ -0,0 +1,141 @@ +#!/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]}"/} + fi + done + + # TODO: generate for waf help + case $prev in + -v | --vehicle) + opts="ArduCopter AntennaTracker APMrover2 ArduSub ArduPlane" + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + ;; + -f | --frame) + opts="" + if [[ ${COMP_WORDS[@]} == *"ArduCopter"* ]]; then + opts+=" +" + opts+=" X" + opts+=" airsim-copter" + opts+=" coaxcopter" + opts+=" djix" + opts+=" dodeca-hexa" + opts+=" gazebo-iris" + opts+=" heli" + opts+=" heli-compound" + opts+=" heli-dual" + opts+=" hexa" + opts+=" octa" + opts+=" octa-quad" + opts+=" quad" + opts+=" scrimmage-copter" + opts+=" singlecopter" + opts+=" tri" + opts+=" y6" + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + fi + if [[ ${COMP_WORDS[@]} == *"AntennaTracker"* ]]; then + opts+=" tracker" + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + fi + if [[ ${COMP_WORDS[@]} == *"APMrover2"* ]]; then + opts+=" balancebot" + opts+=" gazebo-rover" + opts+=" rover" + opts+=" rover-skid" + opts+=" sailboat" + opts+=" sailboat-motor" + opts+=" balancebot" + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + fi + if [[ ${COMP_WORDS[@]} == *"ArduSub"* ]]; then + opts+=" gazebo-bluerov2" + opts+=" vectored" + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + fi + if [[ ${COMP_WORDS[@]} == *"ArduPlane"* ]]; then + opts+=" CRRCSim" + opts+=" gazebo-zephyr" + opts+=" jsbsim" + opts+=" plane" + opts+=" plane-dspoilers" + opts+=" plane-elevon" + opts+=" plane-jet" + opts+=" plane-tailsitter" + opts+=" plane-vtailjet" + opts+=" quadplane" + opts+=" quadplane-cl84" + opts+=" quadplane-tilttrivec" + opts+=" quadplane-tri" + opts+=" scrimmage-plane" + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + fi + ;; + esac + + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) +} + +complete -F _sim_vehicle sim_vehicle.py + diff --git a/Tools/completion/bash/_waf b/Tools/completion/bash/_waf new file mode 100644 index 0000000000..b5db0e0ea9 --- /dev/null +++ b/Tools/completion/bash/_waf @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +_waf() +{ + 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+=" -v --verbose" + opts+=" --debug" + opts+=" --bootloader" + opts+=" --default-parameters" + opts+=" --enable-sfml" + opts+=" --enable-sfml-audio" + opts+=" --sitl-osd" + opts+=" --sitl-rgbled" + opts+=" --build-dates" + opts+=" --sitl-flash-storage" + opts+=" --upload" + opts+=" --board" + + opts+=" AP_Periph" + opts+=" copter" + opts+=" heli" + opts+=" plane" + opts+=" rover" + opts+=" sub" + opts+=" antennatracker" + opts+=" tools" + opts+=" examples" + opts+=" bootloader" + opts+=" iofirmware" + opts+=" list" + opts+=" all" + opts+=" build" + opts+=" configure" + opts+=" clean" + opts+=" distclean" + + # 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]}"} + fi + done + + # TODO: generate for waf help + case $prev in + --board) + opts="CubeBlack bbbmini fmuv2 fmuv3 fmuv4 iomcu sitl" + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + ;; + esac + + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) +} + + +complete -F _waf waf diff --git a/Tools/completion/completion.bash b/Tools/completion/completion.bash new file mode 100644 index 0000000000..4970f81aa7 --- /dev/null +++ b/Tools/completion/completion.bash @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +_AP_COMPLETION_DIR=$(builtin cd "`dirname "${BASH_SOURCE[0]}"`" > /dev/null && pwd) +source "$_AP_COMPLETION_DIR/bash/_waf" +source "$_AP_COMPLETION_DIR/bash/_sim_vehicle" +