mirror of
https://github.com/go-task/task.git
synced 2026-09-01 19:50:16 +02:00
The engine shipped opt-in behind --new-completion, with the old scripts still on --completion. That split was never released, so flip it now rather than carry a third flag through a deprecation later. --completion serves the engine wrappers; the hand-written scripts move to completion/legacy/ and stay reachable via --legacy-completion for a release or two. .goreleaser.yml needed to follow: it packages the static files from completion/ into the deb/rpm/apk contents and the Homebrew cask, so leaving it untouched would have shipped the engine to anyone running `eval "$(task --completion zsh)"` and the old scripts to everyone installing from a package. The paths it references are unchanged and now resolve to the wrappers. Its archive glob is narrowed at the same time, so the test harness under completion/tests/ stops being shipped in the release archives.
99 lines
3.0 KiB
Fish
99 lines
3.0 KiB
Fish
# Thin wrapper around `task __complete`: all suggestion logic lives in the Go engine.
|
|
|
|
set -l GO_TASK_PROGNAME (if set -q GO_TASK_PROGNAME; echo $GO_TASK_PROGNAME; else if set -q TASK_EXE; echo $TASK_EXE; else; echo task; end)
|
|
|
|
# Completion directives, mirroring internal/complete/complete.go. `math` has no
|
|
# bitwise operators, hence __task_test_bit. NoSpace (2) and KeepOrder (32) need
|
|
# none: fish appends no space and keeps the order.
|
|
set -g __task_directive_no_file_comp 4
|
|
set -g __task_directive_filter_file_ext 8
|
|
set -g __task_directive_filter_dirs 16
|
|
|
|
function __task_test_bit --argument-names value bit
|
|
test (math "floor($value / $bit) % 2") -eq 1
|
|
end
|
|
|
|
function __task_complete --inherit-variable GO_TASK_PROGNAME
|
|
set -l tokens (commandline -opc)
|
|
set -l current (commandline -ct)
|
|
set -l args
|
|
if test (count $tokens) -gt 1
|
|
set args $tokens[2..-1]
|
|
end
|
|
set args $args $current
|
|
|
|
set -l output ($GO_TASK_PROGNAME __complete $args 2>/dev/null)
|
|
set -l count (count $output)
|
|
if test $count -eq 0
|
|
return
|
|
end
|
|
|
|
set -l last $output[$count]
|
|
if not string match -q ':*' -- $last
|
|
# Protocol violation: emit raw lines as a fallback.
|
|
printf '%s\n' $output
|
|
return
|
|
end
|
|
|
|
set -l directive (string replace -r '^:' '' -- $last)
|
|
set -l data
|
|
if test $count -gt 1
|
|
set data $output[1..(math $count - 1)]
|
|
end
|
|
|
|
# The registration below passes `--no-files`, so every file-completion
|
|
# directive must be served here or nothing is offered at all.
|
|
|
|
# fish replaces the whole token, so an inline `--flag=` must be kept on every
|
|
# candidate.
|
|
set -l flagpfx ""
|
|
set -l pathcur $current
|
|
if string match -qr '^--?[^=]+=' -- $current
|
|
set flagpfx (string replace -r '=.*$' '=' -- $current)
|
|
set pathcur (string replace -r '^--?[^=]+=' '' -- $current)
|
|
end
|
|
|
|
# __fish_complete_suffix prioritizes the extension instead of filtering.
|
|
if __task_test_bit $directive $__task_directive_filter_file_ext
|
|
for entry in (__fish_complete_path $pathcur)
|
|
set -l name (string split -f1 \t -- $entry)
|
|
if string match -qr '/$' -- $name
|
|
printf '%s%s\n' $flagpfx $entry
|
|
continue
|
|
end
|
|
for ext in $data
|
|
if string match -qr "\.$ext\$" -- $name
|
|
printf '%s%s\n' $flagpfx $entry
|
|
break
|
|
end
|
|
end
|
|
end
|
|
return
|
|
end
|
|
|
|
if __task_test_bit $directive $__task_directive_filter_dirs
|
|
for entry in (__fish_complete_directories $pathcur)
|
|
printf '%s%s\n' $flagpfx $entry
|
|
end
|
|
return
|
|
end
|
|
|
|
for line in $data
|
|
printf '%s\n' $line
|
|
end
|
|
|
|
# NoFileComp unset → offer files too (DirectiveDefault).
|
|
if not __task_test_bit $directive $__task_directive_no_file_comp
|
|
for entry in (__fish_complete_path $pathcur)
|
|
printf '%s%s\n' $flagpfx $entry
|
|
end
|
|
end
|
|
end
|
|
|
|
# fish accumulates `complete` entries instead of replacing them, so an older
|
|
# completion would keep contributing alongside the engine.
|
|
complete -c $GO_TASK_PROGNAME -e
|
|
|
|
# `--no-files` keeps fish from mixing in files against the engine's directive.
|
|
complete -c $GO_TASK_PROGNAME --no-files -a "(__task_complete)"
|