From a381ac2691b7c1d52ec7436a7c97ba91b3d496aa Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Fri, 19 Sep 2014 19:00:29 -0700 Subject: 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. --- share/completions/git.fish | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'share/completions') diff --git a/share/completions/git.fish b/share/completions/git.fish index 0c774cd0..5fda2935 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -91,6 +91,24 @@ function __fish_git_aliases command git config --get-regexp '^alias\.' | sed -n "s/^alias\.\([^ ]*\).*/\1/p" 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 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) 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' -- cgit v1.2.3