diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c73dabd8c..b2e64b4e8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -360,7 +360,7 @@ Completions - The ``make`` completions no longer second-guess make's file detection, fixing target completion in some cases (:issue:`7535`). - The command completions now correctly print the description even if the command was fully matched (like in ``ls``). - The ``set`` completions no longer hide variables starting with ``__``, they are sorted last instead. -- Completion scripts for custom Git subcommands like ``git-xyz`` are now loaded with Git completions. The completions can now be defined directly on the subcommand (using ``complete git-xyz``), and completion for ``git xyz`` will work. (:issue:`7075`, :issue:`7652`) +- Completion scripts for custom Git subcommands like ``git-xyz`` are now loaded with Git completions. The completions can now be defined directly on the subcommand (using ``complete git-xyz``), and completion for ``git xyz`` will work. (:issue:`7075`, :issue:`7652`, :issue:`4358`) Changes not visible to users ---------------------------- diff --git a/share/completions/git.fish b/share/completions/git.fish index 60dcbf9ee..6c888a649 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -1909,26 +1909,18 @@ function __fish_git_complete_custom_command -a subcommand complete -C "git-$subcommand $subcommand_args "(commandline -ct) end -# Get the path to the generated completions -# If $XDG_DATA_HOME is set, that's it, if not, it will be removed and ~/.local/share will remain. -set -l generated_path $XDG_DATA_HOME/fish/generated_completions ~/.local/share/fish/generated_completions - -# We don't want to modify $fish_complete_path here, so we make a copy. -set -l complete_dirs $fish_complete_path - -# Remove the path to the generated completions if it is in the list -set -l ind (contains -i -- $generated_path[1] $complete_dirs); and set -e complete_dirs[$ind] - # source git-* commands' autocompletion file if exists set -l __fish_git_custom_commands_completion -for git_ext in $complete_dirs/git-*.fish - # ignore this completion as executable does not exists - set -l subcommand (string replace -r '.*/git-([^/]*)\.fish' '$1' $git_ext) - not command -q git-$subcommand +for file in $PATH/git-* + not command -q $file and continue - # already sourced this git-* completion file from some other dir + + set -l subcommand (string replace -r -- '.*/git-([^/]*)$' '$1' $file) + + # Already seen this command earlier in $PATH. contains -- $subcommand $__fish_git_custom_commands_completion and continue + complete -C "git-$subcommand " >/dev/null if [ (complete git-$subcommand | count) -gt 0 ] complete git -f -n "__fish_git_using_command $subcommand" -a "(__fish_git_complete_custom_command $subcommand)"