diff --git a/share/completions/git.fish b/share/completions/git.fish index 91934ff9a..e4b4ae7f7 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -2242,15 +2242,13 @@ end # source git-* commands' autocompletion file if exists set -f __fish_git_custom_commands_completion -for file in $PATHgitdash - test ! -x $file - and continue - - set -l subcommand (path basename $file) +for file in (path filter -xZ -- $PATHgitdash | path basename) # Already seen this command earlier in $PATH. - contains -- $subcommand $__fish_git_custom_commands_completion + contains -- $file $__fish_git_custom_commands_completion and continue - complete -c git -f -n "__fish_git_using_command $subcommand" -a "(__fish_git_complete_custom_command $subcommand)" + # Running `git foo` ends up running `git-foo`, so we need to ignore the `git-` here. + set -l cmd (string replace -r '^git-' '' -- $file) + complete -c git -f -n "__fish_git_using_command $cmd" -a "(__fish_git_complete_custom_command $cmd)" set -a __fish_git_custom_commands_completion $subcommand end diff --git a/tests/checks/git.fish b/tests/checks/git.fish index 4fc6f76e4..f5b337a1a 100644 --- a/tests/checks/git.fish +++ b/tests/checks/git.fish @@ -33,6 +33,19 @@ git init >/dev/null 2>&1 # First set up a test alias - *before loading the completions* git config --local alias.re 'restore --staged' +# Test custom command completions by adding a command: + +set -p PATH $PWD +echo "echo foo" > git-frobnicate +chmod +x git-frobnicate + +complete -c git-frobnicate -xa 'foo bar baz' + +complete -C'git frobnicate ' +#CHECK: bar +#CHECK: baz +#CHECK: foo + complete -C'git ' | grep '^add'\t # (note: actual tab character in the check here) #CHECK: add Add file contents to the staging area @@ -41,9 +54,11 @@ touch foo complete -C'git add ' #CHECK: foo Untracked file +#CHECK: git-frobnicate Untracked file complete -C'git add :' #CHECK: :/:foo Untracked file +#CHECK: :/:git-frobnicate Untracked file git config alias.s status complete 'git s --s' @@ -71,7 +86,7 @@ set -g __fish_git_prompt_show_informative_status 1 set -g __fish_git_prompt_showuntrackedfiles 1 fish_git_prompt echo -#CHECK: (newbranch|…1) +#CHECK: (newbranch|…2) set -e __fish_git_prompt_show_informative_status set -e __fish_git_prompt_showuntrackedfiles