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..`.
This commit is contained in:
Johannes Altmanninger 2020-09-24 22:11:38 +02:00
parent 16ae532368
commit 2a95b283ee

View file

@ -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