2019-10-28 08:41:00 -03:00
#!/usr/bin/env bash
_waf()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
2020-12-31 13:43:48 -04:00
# don't complet =
_init_completion -n = || return
2019-10-28 08:41:00 -03:00
# TODO: generate for waf help
2020-12-31 13:43:48 -04:00
opts="-h"
opts+=" -j "
opts+=" -v "
2019-10-28 08:41:00 -03:00
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"
2024-01-16 02:12:10 -04:00
opts+=" submodule_force_clean"
opts+=" submodulesync"
2019-10-28 08:41:00 -03:00
# Prevent word reuse TODO: add -vvv case
lim=$((COMP_CWORD - 1))
for i in $( seq 0 $lim )
do
if [[ $opts == *"${COMP_WORDS[i]}"* ]]; then
2020-04-03 12:38:17 -03:00
opts=${opts//${COMP_WORDS[i]}/}
opts=${opts//--${COMP_WORDS[i]}/}
2019-10-28 08:41:00 -03:00
fi
done
2020-04-03 12:38:17 -03:00
case $prev in
2019-11-14 09:27:04 -04:00
--board)
2020-02-11 23:23:11 -04:00
opts=$(./waf list_boards | sed -e '$d')
2019-11-14 09:27:04 -04:00
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
esac
2019-10-28 08:41:00 -03:00
2020-12-31 13:43:48 -04:00
case $cur in
--targets=*)
cur=${cur#*=}
2021-01-09 12:24:45 -04:00
if [ -z "$_waf_comp_targets" ]; then
# list target without color, remove Lua embedding, remove empty and space only line, remove objs/*, remove path for lua binding, remove trailing spaces, change line return for space
_waf_comp_targets=$(./waf list -c no | sed -e '/^Embedding/d' -e '/^ *$/d' -e '/objs\//d' -e '$d' -e '/^\//d' | tr -d " " | tr '\n' ' ')
fi
opts=$_waf_comp_targets
2020-12-31 13:43:48 -04:00
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
esac
COMPREPLY=( $(compgen -W '$(_parse_help "$1")' -- "$cur") $(compgen -W "${opts}" -- ${cur}) )
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
2019-10-28 08:41:00 -03:00
}
complete -F _waf waf