From 39e3c3c0b12a6cc458703653fcf4aad306618f1d Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 8 May 2018 23:14:49 +0200 Subject: [PATCH] [git completions] Readd "unique remote branches" This is based on what the official git completions do, and it's quite fast. Also only complete files after a "--" separator for `checkout`. Fixes #4858. --- share/completions/git.fish | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/share/completions/git.fish b/share/completions/git.fish index dd827c884..8e4c7e1b0 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -32,6 +32,17 @@ function __fish_git_branches | string replace -r '^refs/remotes/(.*)$' '$1\tRemote Branch' end +function __fish_git_unique_remote_branches + # `git checkout` accepts remote branches without the remote part + # if they are unambiguous. + # E.g. if only alice has a "frobulate" branch + # `git checkout frobulate` is equivalent to `git checkout -b frobulate --track alice/frobulate`. + command git for-each-ref --format="%(refname:strip=3)" \ + --sort="refname:strip=3" \ + "refs/remotes/*/$match*" "refs/remotes/*/*/**" | \ + uniq -u +end + function __fish_git_tags command git tag --sort=-creatordate 2>/dev/null end @@ -613,9 +624,10 @@ complete -f -c git -n '__fish_git_using_command add' -a '(__fish_git_files modif ### checkout complete -f -c git -n '__fish_git_needs_command' -a checkout -d 'Checkout and switch to a branch' -complete -k -f -c git -n '__fish_git_using_command checkout' -a '(__fish_git_branches)' -complete -k -f -c git -n '__fish_git_using_command checkout' -a '(__fish_git_heads)' -d 'Head' -complete -k -f -c git -n '__fish_git_using_command checkout' -a '(__fish_git_tags)' -d 'Tag' +complete -k -f -c git -n '__fish_git_using_command checkout; and not contains -- -- (commandline -op)' -a '(__fish_git_branches)' +complete -k -f -c git -n '__fish_git_using_command checkout; and not contains -- -- (commandline -op)' -a '(__fish_git_heads)' -d 'Head' +complete -k -f -c git -n '__fish_git_using_command checkout; and not contains -- -- (commandline -op)' -a '(__fish_git_tags)' -d 'Tag' +complete -k -f -c git -n '__fish_git_using_command checkout; and not contains -- -- (commandline -op)' -a '(__fish_git_unique_remote_branches)' -d 'Unique Remote Branch' complete -k -f -c git -n '__fish_git_using_command checkout' -a '(__fish_git_files modified deleted)' complete -f -c git -n '__fish_git_using_command checkout' -s b -d 'Create a new branch' complete -f -c git -n '__fish_git_using_command checkout' -s t -l track -d 'Track a new branch'