2022-08-13 21:55:35 +02:00
|
|
|
# vim: set tabstop=2 shiftwidth=2 expandtab:
|
2022-02-13 21:20:01 +02:00
|
|
|
|
2022-08-11 20:48:41 +02:00
|
|
|
_GO_TASK_COMPLETION_LIST_OPTION='--list-all'
|
2022-05-22 16:16:50 +02:00
|
|
|
|
2022-08-11 20:48:41 +02:00
|
|
|
function _task()
|
2019-08-30 01:59:03 +02:00
|
|
|
{
|
2022-08-13 21:55:35 +02:00
|
|
|
local cur prev words cword
|
|
|
|
_init_completion -n : || return
|
2019-08-30 01:59:03 +02:00
|
|
|
|
2022-09-08 19:03:29 +02:00
|
|
|
# Check for `--` within command-line and quit or strip suffix.
|
|
|
|
local i
|
|
|
|
for i in "${!words[@]}"; do
|
|
|
|
if [ "${words[$i]}" == "--" ]; then
|
|
|
|
# Do not complete words following `--` passed to CLI_ARGS.
|
|
|
|
[ $cword -gt $i ] && return
|
|
|
|
# Remove the words following `--` to not put --list in CLI_ARGS.
|
|
|
|
words=( "${words[@]:0:$i}" )
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-08-13 21:55:35 +02:00
|
|
|
# Handle special arguments of options.
|
|
|
|
case "$prev" in
|
|
|
|
-d|--dir)
|
|
|
|
_filedir -d
|
|
|
|
return $?
|
|
|
|
;;
|
|
|
|
-t|--taskfile)
|
|
|
|
_filedir yaml || return $?
|
|
|
|
_filedir yml
|
|
|
|
return $?
|
|
|
|
;;
|
|
|
|
-o|--output)
|
|
|
|
COMPREPLY=( $( compgen -W "interleaved group prefixed" -- $cur ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
2019-08-30 01:59:03 +02:00
|
|
|
|
2022-08-13 21:55:35 +02:00
|
|
|
# Handle normal options.
|
|
|
|
case "$cur" in
|
|
|
|
-*)
|
|
|
|
COMPREPLY=( $( compgen -W "$(_parse_help $1)" -- $cur ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
2022-08-11 20:48:41 +02:00
|
|
|
|
2022-08-23 18:03:15 +02:00
|
|
|
# Prepare task name completions.
|
2022-09-08 19:03:29 +02:00
|
|
|
local tasks=( $( "${words[@]}" --silent $_GO_TASK_COMPLETION_LIST_OPTION 2> /dev/null ) )
|
2022-08-13 21:55:35 +02:00
|
|
|
COMPREPLY=( $( compgen -W "${tasks[*]}" -- "$cur" ) )
|
2022-08-23 18:03:15 +02:00
|
|
|
|
|
|
|
# Post-process because task names might contain colons.
|
2022-08-13 21:55:35 +02:00
|
|
|
__ltrim_colon_completions "$cur"
|
2019-08-30 01:59:03 +02:00
|
|
|
}
|
|
|
|
|
2022-08-11 20:48:41 +02:00
|
|
|
complete -F _task task
|