fix(fish): completions fail to load with fish >= 4.8.0

Fish started shipping git completions in the binary with 4.2.0 and deprecated the old completion
files with 4.8.0.

Update forgit’s fish completion loader to support both models:

* prefer `status get-file completions/git.fish` (binary-embedded completions)
* fall back to `$__fish_data_dir/completions/git.fish` (completion files)

Also refactors loading into a helper function to allow early returns and reduce nesting.
This commit is contained in:
sandroid 2026-09-08 21:17:44 +02:00
parent d7d53288f9
commit 7070af0c01
No known key found for this signature in database
GPG key ID: 91418C9982B8B76E

View file

@ -20,8 +20,29 @@ function __fish_forgit_worktrees
git worktree list --porcelain 2>/dev/null | string match -r '^worktree .+' | string replace 'worktree ' ''
end
# Load helper functions in git completion file
not functions -q __fish_git && source $__fish_data_dir/completions/git.fish
# Load git completion functions
function __fish_forgit_load_git_completions
if functions -q __fish_git
return 0
end
# Fish >= 4.2.0 ships git completions in its binary
if set --local git_completions (status get-file completions/git.fish)
printf '%s\n' $git_completions | source
return 0
end
# Older fish versions ship completions in a file
set --local git_completions_file "$__fish_data_dir/completions/git.fish"
if test -f "$git_completions_file"
source "$git_completions_file"
return 0
end
return 1
end
__fish_forgit_load_git_completions || exit
# No file completion by default
complete -c git-forgit -x