fix: completion

This commit is contained in:
Janik von Rotz committed 2026-07-18 21:09:22 +02:00
1 parent cbfc16a5e4
commit eb75914131
1 file changed
+16 -19
+16 -19
View File
@@ -55,24 +55,18 @@ output_completion_script() {
# Fish completion script
cat << 'EOF'
# Taskfile completion for fish
function _task_completions
# Get the current word being typed
set cur (commandline -p)
# Get the previous word
set prev (commandline -oprev)
# Get the available commands from `task help`
set commands (./task help | grep -A100 -e '---' | awk '{print $2}' | sed 's/^[[:space:]]*//' | grep -v '^$' | tr '\n' ' ')
if test (count (commandline -opc)) -eq 1
# Provide completions for the command part (second word)
complete -c task -f -n "__fish_seen_subcommand_from $prev" -a "$commands"
else if test (count (commandline -opc)) -eq 2
# Provide file path completions for the third parameter
complete -c task -f -n "__fish_seen_subcommand_from $prev" -a (ls)
end
function __task_commands
./task help 2>/dev/null | grep -A100 -e '---' | awk '{print $2}' | sed 's/^[[:space:]]*//' | grep -v '^$'
end
# First argument position: offer the list of task commands.
complete -c task -f -n '__fish_use_subcommand' -a '(__task_commands)'
complete -c t -f -n '__fish_use_subcommand' -a '(__task_commands)'
# Once a command has already been typed, fall back to file completion.
complete -c task -f -n 'not __fish_use_subcommand' -a '(__fish_complete_path)'
complete -c t -f -n 'not __fish_use_subcommand' -a '(__fish_complete_path)'
EOF
elif [[ "$shell_type" == "zsh" ]]; then
# ZSH completion script
@@ -81,9 +75,11 @@ EOF
_task_completions() {
local reply
local si=$IFS
# NOTE: reply is built by splitting on newlines (IFS=$'\n'), so do NOT
# collapse the lines with `tr '\n' ' '` before the command substitution,
# or the whole list ends up as a single array element.
IFS=$'
' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" ./task help | grep -A999 -e '---' | awk '{print $2}' | sed 's/^[[:space:]]*//' | grep -v '^$' | tr '
' ' '))
' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" ./task help | grep -A999 -e '---' | awk '{print $2}' | sed 's/^[[:space:]]*//' | grep -v '^$'))
IFS=$si
if [[ ${#reply} -gt 0 ]]; then
_describe 'values' reply
@@ -108,6 +104,7 @@ _task_completions() {
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# compgen -W wants a single space-separated string, so tr is fine here.
commands=$(./task help | grep -A999 -e '---' | awk '{print $2}' | sed 's/^[[:space:]]*//' | grep -v '^$' | tr '\n' ' ')
if [[ ${COMP_CWORD} == 1 ]]; then
@@ -123,4 +120,4 @@ complete -F _task_completions task
complete -F _task_completions t
EOF
fi
}
}