Files
task/completion.go
Valentin Maerten ed7a206e19 feat(completion): unify shell completions behind an opt-in task __complete engine
Bash, Fish, Zsh, Nushell and PowerShell now share a single backend: `task __complete` returns the suggestions plus a directive, and every wrapper is a thin shim around it. All five shells offer the same suggestions — task names, aliases, flags, flag values and per-task CLI variables. The Zsh `show-aliases` and `verbose` zstyles keep working, now backed by the `--no-aliases` and `--no-descriptions` completion flags.

The engine is opt-in via `task --new-completion <shell>`, leaving `--completion` and the legacy scripts untouched; it will become the default in a future release. The new wrappers live under `completion/next/`.

Completing a keystroke never reaches the network, never blocks on a stdin entrypoint, and honors every flag that decides how the Taskfile is loaded. Ref resolution shared by `requires` and enum completion moved to `internal/refs`.

A cross-shell test suite exercises the protocol in Go with thin shell smoke tests, and runs in CI.
2026-08-20 14:18:54 +02:00

75 lines
1.8 KiB
Go

package task
import (
_ "embed"
"fmt"
)
//go:embed completion/bash/task.bash
var completionBash string
//go:embed completion/fish/task.fish
var completionFish string
//go:embed completion/nu/task-completions.nu
var completionNu string
//go:embed completion/ps/task.ps1
var completionPowershell string
//go:embed completion/zsh/_task
var completionZsh string
// Thin wrappers around the `task __complete` engine, served via
// `--new-completion` until the engine becomes the default.
//go:embed completion/next/bash/task.bash
var completionBashNext string
//go:embed completion/next/fish/task.fish
var completionFishNext string
//go:embed completion/next/nu/task-completions.nu
var completionNuNext string
//go:embed completion/next/ps/task.ps1
var completionPowershellNext string
//go:embed completion/next/zsh/_task
var completionZshNext string
// The maps accept `nushell` as an alias of `nu`.
var completionScripts = map[string]string{
"bash": completionBash,
"fish": completionFish,
"nu": completionNu,
"nushell": completionNu,
"powershell": completionPowershell,
"zsh": completionZsh,
}
var completionScriptsNext = map[string]string{
"bash": completionBashNext,
"fish": completionFishNext,
"nu": completionNuNext,
"nushell": completionNuNext,
"powershell": completionPowershellNext,
"zsh": completionZshNext,
}
func Completion(shell string) (string, error) {
return completionScript(completionScripts, shell)
}
func CompletionNext(shell string) (string, error) {
return completionScript(completionScriptsNext, shell)
}
func completionScript(scripts map[string]string, shell string) (string, error) {
script, ok := scripts[shell]
if !ok {
return "", fmt.Errorf("unknown shell: %s", shell)
}
return script, nil
}