Skip to content

Commit 647b218

Browse files
committed
forgit show: add key binding to display the commit message
Alt-T can now be used to toggle between showing the diff and the commit message in the fzf preview window. This requires fzf >= 0.49.0.
1 parent 580c5cb commit 647b218

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

bin/git-forgit

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,18 @@ _forgit_show_view() {
353353
repo=$(git rev-parse --show-toplevel)
354354
cd "$repo" || return 1
355355
echo "$input_line" | _forgit_get_files_from_diff_line | xargs -0 \
356-
"$FORGIT" exec_show "${commit}" -U"$diff_context" -- | _forgit_pager diff
356+
"$FORGIT" exec_show "${commit}^{commit}" -U"$diff_context" -- | _forgit_pager diff
357+
}
358+
359+
_forgit_show_preview() {
360+
local input_line=$1
361+
local diff_context=$2
362+
local commit=$3
363+
if [[ "$FZF_PREVIEW_LABEL" =~ "Diff" ]]; then
364+
_forgit_show_view "${input_line}" "${diff_context}" "${commit}"
365+
else
366+
git show --quiet --color=always "${FZF_PROMPT%% *}"
367+
fi
357368
}
358369

359370
_forgit_show_enter() {
@@ -381,8 +392,12 @@ _forgit_show() {
381392
opts="
382393
$FORGIT_FZF_DEFAULT_OPTS
383394
+m -0 --bind=\"enter:execute($FORGIT show_enter {} $escaped_commit | $FORGIT pager enter)\"
384-
--preview=\"$FORGIT show_view {} '$_forgit_preview_context' $escaped_commit\"
395+
--preview=\"$FORGIT show_preview {} '$_forgit_preview_context' $escaped_commit\"
396+
--preview-label=\" Diff \"
385397
--bind=\"alt-e:execute($FORGIT edit_diffed_file {})+refresh-preview\"
398+
--bind \"alt-t:transform:[[ ! \$FZF_PREVIEW_LABEL =~ 'Diff' ]] &&
399+
echo 'change-preview-label( Diff )+refresh-preview' ||
400+
echo 'change-preview-label( Commit Message )+refresh-preview'\"
386401
$FORGIT_DIFF_FZF_OPTS
387402
--prompt=\"${commit} > \"
388403
"
@@ -1104,7 +1119,7 @@ private_commands=(
11041119
"revert_preview"
11051120
"reset_head_preview"
11061121
"show_enter"
1107-
"show_view"
1122+
"show_preview"
11081123
"stash_push_preview"
11091124
"stash_show_preview"
11101125
"yank_sha"

0 commit comments

Comments
 (0)