Parsodus/Parsodus-completion.bash

65 lines
1.8 KiB
Bash

_Parsodus_completion ()
{
local langs
langs='c++ cpp cxx'
local opts
opts='-h --help --version -d --outputdir -l --language -n --name'
# local prev
COMPREPLY=()
local cur
cur=${COMP_WORDS[COMP_CWORD]}
local prev
local pprev
if [ $COMP_CWORD -gt 1 ]; then
prev=${COMP_WORDS[ $(( $COMP_CWORD - 1 )) ]}
fi
if [ $COMP_CWORD -gt 2 ]; then
pprev=${COMP_WORDS[ $(( $COMP_CWORD - 2 )) ]}
fi
case "$cur" in
-*)
COMPREPLY=( $(compgen -W "$opts" -- $cur) )
;;
=*)
case "$prev" in
--language)
COMPREPLY=( $(compgen -W "$langs" ))
;;
--outputdir)
COMPREPLY=( $(compgen -d ) )
;;
esac
;;
*)
if [ "$prev" == "=" ]; then
case "$pprev" in
--language)
COMPREPLY=( $(compgen -W "$langs" -- $cur))
;;
--outputdir)
COMPREPLY=( $(compgen -d -- $cur) )
;;
esac
else
case "$prev" in
-l|--language)
COMPREPLY=( $(compgen -W "$langs" -- $cur))
;;
-d|--outputdir)
COMPREPLY=( $(compgen -d -S "/" -- $cur) )
[[ $COMPREPLY == */ ]] && compopt -o nospace
;;
*)
COMPREPLY=( $(compgen -f -X '!*.pds' -- $cur) $(compgen -d -S "/" -- $cur))
[[ $COMPREPLY == */ ]] && compopt -o nospace
;;
esac
fi
;;
esac
}
complete -F _Parsodus_completion Parsodus