From 836b6bea73b6e8da657471d8b919ed347dfa62e5 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 18 Dec 2015 17:07:43 +0100 Subject: [PATCH] git completions: Add commit hashes for `show` That's probably the part where commit hashes are most used, we can add the other subcommands later. This generates a _lot_ of options, so hooking it up everywhere would be unwise, though our pager helps quite nicely with filtering - typing "Branch" will filter out the commits, and typing other things will filter the subjects, which is quite cool. --- share/completions/git.fish | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/share/completions/git.fish b/share/completions/git.fish index 076a54a9b..acb3ff42a 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -1,6 +1,15 @@ # fish completion for git # Use 'command git' to avoid interactions for aliases from git to (e.g.) hub +function __fish_git_commits + # Complete commits with their subject line as the description + # This allows filtering by subject with the new pager! + # Because even subject lines can be quite long, + # trim them (abbrev'd hash+tab+subject) to 70 characters + command git log --pretty=tformat:"%h"\t"%s" \ + | string replace -r '(.{70}).+' '$1...' +end + function __fish_git_branches command git branch --no-color -a ^/dev/null | __fish_sgrep -v ' -> ' | string trim -c "* " | string replace -r "^remotes/" "" end @@ -219,6 +228,7 @@ complete -f -c git -n "__fish_git_using_command remote; and __fish_seen_subcomma complete -f -c git -n '__fish_git_needs_command' -a show -d 'Shows the last commit of a branch' complete -f -c git -n '__fish_git_using_command show' -a '(__fish_git_branches)' -d 'Branch' complete -f -c git -n '__fish_git_using_command show' -a '(__fish_git_unique_remote_branches)' -d 'Remote branch' +complete -f -c git -n '__fish_git_using_command show' -a '(__fish_git_commits)' # TODO options ### show-branch