From 618705285dcb15416a3e739a3135740f37408940 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Fri, 25 Sep 2020 06:01:11 +0200 Subject: [PATCH] completions/git: support ... range notation https://git-scm.com/docs/gitrevisions#_revision_range_summary --- share/completions/git.fish | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/share/completions/git.fish b/share/completions/git.fish index 03459a006..c9708c370 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -511,12 +511,18 @@ function __fish_git_needs_rev_files end function __fish_git_ranges - set -l both (commandline -ot | string split "..") + set -l both (commandline -ot | string replace -r '\.{2,3}' \n\$0\n) set -l from $both[1] + set -l dots $both[2] # If we didn't need to split (or there's nothing _to_ split), complete only the first part - # Note that status here is from `string split` because `set` doesn't alter it + # Note that status here is from `string replace` because `set` doesn't alter it if test -z "$from" -o $status -gt 0 - __fish_git_refs + if commandline -ct | string match -q '*..*' + # The cursor is right of a .. range operator, make sure to include them first. + __fish_git_refs | string replace -r '' "$dots" + else + __fish_git_refs | string replace \t "$dots"\t + end return 0 end @@ -528,11 +534,11 @@ function __fish_git_ranges set from_refs (__fish_git_refs | string match -e "$from" | string replace -r \t'.*$' '') end - set -l to $both[2] + set -l to $both[3] # Remove description from the from-ref, not the to-ref. 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 + printf "%s%s%s\n" $from_ref $dots $to_ref end end end