From 631cca8c128dbf18b6dca5d72020a82aab4d9cb3 Mon Sep 17 00:00:00 2001 From: Wenxuan Zhang Date: Sat, 3 Aug 2019 11:59:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Support=20diff=20with=20?= =?UTF-8?q?given=20commit=20(and=20paths).#27?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- forgit.plugin.zsh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index b371af5..6d80247 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -28,17 +28,22 @@ forgit::log() { # git diff viewer forgit::diff() { forgit::inside_work_tree || return 1 - local cmd files opts - cmd="git diff --color=always -- {} $forgit_emojify $forgit_fancy" - files="$*" - [[ $# -eq 0 ]] && files=$(git rev-parse --show-toplevel) + local cmd files opts commit + [[ $# -ne 0 ]] && { + if git rev-parse "$1" -- &>/dev/null ; then + commit="$1" && files=("${@:2}") + else + files=("$@") + fi + } + cmd="git diff --color=always $commit -- {} $forgit_emojify $forgit_fancy" opts=" $FORGIT_FZF_DEFAULT_OPTS +m -0 --preview=\"$cmd\" --bind=\"enter:execute($cmd |LESS='-R' less)\" $FORGIT_DIFF_FZF_OPTS " - git ls-files --modified "$files" | + eval "git diff --name-only $commit -- ${files[*]}"| FZF_DEFAULT_OPTS="$opts" fzf }