Complete custom git commands in $PATH

Git treats executables in $PATH that start with "git-" as custom
subcommands. Add completion support for them.

Fixes #1680.
This commit is contained in:
Kevin Ballard 2014-09-19 19:00:29 -07:00
parent e2be71cbe4
commit a381ac2691

View file

@ -91,6 +91,24 @@ function __fish_git_aliases
command git config --get-regexp '^alias\.' | sed -n "s/^alias\.\([^ ]*\).*/\1/p" command git config --get-regexp '^alias\.' | sed -n "s/^alias\.\([^ ]*\).*/\1/p"
end end
function __fish_git_custom_commands
# complete all commands starting with git-
# however, a few builtin commands are placed into $PATH by git because
# they're used by the ssh transport. We could filter them out by checking
# if any of these completion results match the name of the builtin git commands,
# but it's simpler just to blacklist these names. They're unlikely to change,
# and the failure mode is we accidentally complete a plumbing command.
set -l IFS \n
for name in (builtin complete -Cgit- | sed 's/^git-\([^[:space:]]*\).*/\1/')
switch $name
case cvsserver receive-pack shell upload-archive upload-pack
# skip these
case \*
echo $name
end
end
end
# general options # general options
complete -f -c git -n 'not __fish_git_needs_command' -l help -d 'Display the manual of a git command' complete -f -c git -n 'not __fish_git_needs_command' -l help -d 'Display the manual of a git command'
@ -392,3 +410,6 @@ complete -f -c git -n '__fish_git_needs_command' -a whatchanged -d 'Show logs wi
## Aliases (custom user-defined commands) ## Aliases (custom user-defined commands)
complete -c git -n '__fish_git_needs_command' -a '(__fish_git_aliases)' -d 'Alias (user-defined command)' complete -c git -n '__fish_git_needs_command' -a '(__fish_git_aliases)' -d 'Alias (user-defined command)'
## Custom commands (git-* commands installed in the PATH)
complete -c git -n '__fish_git_needs_command' -a '(__fish_git_custom_commands)' -d 'Custom command'