diff --git a/share/completions/git.fish b/share/completions/git.fish index 0c774cd0b..5fda2935c 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'