diff --git a/conf.d/forgit.plugin.fish b/conf.d/forgit.plugin.fish index 2ea5215..4340745 100644 --- a/conf.d/forgit.plugin.fish +++ b/conf.d/forgit.plugin.fish @@ -62,18 +62,24 @@ function forgit::log -d "git commit viewer" end ## git diff viewer -function forgit::diff -d "git diff viewer" +function forgit::diff -d "git diff viewer" --argument-names arg1 arg2 forgit::inside_work_tree || return 1 - if count $argv > /dev/null - if git rev-parse "$argv[1]" > /dev/null 2>&1 - set commit "$argv[1]" && set files "$argv[2..]" + if test -n "$arg1" + # If this first arg is a commit hash + if git rev-parse "$arg1" > /dev/null 2>&1 + if git rev-parse "$arg2" > /dev/null 2>&1 + set commits "$arg1 $arg2" && set files "$argv[3..-1]" + else + set commits "$arg1" && set files "$argv[2..-1]" + end else set files "$argv" end end set repo (git rev-parse --show-toplevel) - set preview "echo {} |sed 's/.*] //' | xargs -I% git diff --color=always $commit -- '$repo/%' | $forgit_diff_pager" + set preview "echo {} | sed 's/.*] *//' | sed 's/ -> / /' | xargs -I% git diff --color=always $commits -- '$repo/%' | $forgit_diff_pager" + set opts " $FORGIT_FZF_DEFAULT_OPTS +m -0 --bind=\"enter:execute($preview |env LESS='-r' less)\" @@ -81,7 +87,10 @@ function forgit::diff -d "git diff viewer" $FORGIT_DIFF_FZF_OPTS " - eval "git diff --name-only $commit -- $files*| sed -E 's/^(.)[[:space:]]+(.*)\$/[\1] \2/'" | env FZF_DEFAULT_OPTS="$opts" fzf + eval git diff --name-only $commit -- $files* | + sed -E 's/^(.)[[:space:]]+(.*)\$/[\1] \2/' | + sed 's/\t/ -> /2' | expand -t 8 | + env FZF_DEFAULT_OPTS="$opts" fzf end # git add selector