From 2a95b283eed1bf0b1ba46758bf2f7605f03544b1 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Thu, 24 Sep 2020 22:11:38 +0200 Subject: [PATCH] completions/git: complete only right commit if cursor is beyond the ".." This enables completion for the right part of a range in many cases, like `git log HEAD~10..`. --- share/completions/git.fish | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/share/completions/git.fish b/share/completions/git.fish index b484c21eb..03459a006 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -520,9 +520,17 @@ function __fish_git_ranges return 0 end + set -l from_refs + if commandline -ct | string match -q '*..*' + # If the cursor is right of a .. range operator, only complete the right part. + set from_refs $from + else + set from_refs (__fish_git_refs | string match -e "$from" | string replace -r \t'.*$' '') + end + set -l to $both[2] # Remove description from the from-ref, not the to-ref. - for from_ref in (__fish_git_refs | string match -e "$from" | string replace -r \t'.*$' '') + for from_ref in $from_refs for to_ref in (__fish_git_refs | string match "*$to*") # if $to is empty, this correctly matches everything printf "%s..%s\n" $from_ref $to_ref end