From 39ee4fe70dd461da38c05acb7379f5cc2b000b7e Mon Sep 17 00:00:00 2001 From: carlfriedrich Date: Thu, 9 Jan 2025 19:55:18 +0100 Subject: [PATCH] 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. --- bin/git-forgit | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index d1aaa9a..6f00825 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -353,7 +353,18 @@ _forgit_show_view() { repo=$(git rev-parse --show-toplevel) cd "$repo" || return 1 echo "$input_line" | _forgit_get_files_from_diff_line | xargs -0 \ - "$FORGIT" exec_show "${commit}" -U"$diff_context" -- | _forgit_pager diff + "$FORGIT" exec_show "${commit}^{commit}" -U"$diff_context" -- | _forgit_pager diff +} + +_forgit_show_preview() { + local input_line=$1 + local diff_context=$2 + local commit=$3 + if [[ "$FZF_PREVIEW_LABEL" =~ "Diff" ]]; then + _forgit_show_view "${input_line}" "${diff_context}" "${commit}" + else + git show --quiet --color=always "${FZF_PROMPT%% *}" + fi } _forgit_show_enter() { @@ -381,8 +392,12 @@ _forgit_show() { opts=" $FORGIT_FZF_DEFAULT_OPTS +m -0 --bind=\"enter:execute($FORGIT show_enter {} $escaped_commit | $FORGIT pager enter)\" - --preview=\"$FORGIT show_view {} '$_forgit_preview_context' $escaped_commit\" + --preview=\"$FORGIT show_preview {} '$_forgit_preview_context' $escaped_commit\" + --preview-label=\" Diff \" --bind=\"alt-e:execute($FORGIT edit_diffed_file {})+refresh-preview\" + --bind=\"alt-t:transform:[[ ! \\\"\$FZF_PREVIEW_LABEL\\\" =~ 'Diff' ]] && + echo 'change-preview-label( Diff )+refresh-preview' || + echo 'change-preview-label( Commit Message )+refresh-preview'\" $FORGIT_DIFF_FZF_OPTS --prompt=\"${commit} > \" " @@ -1104,7 +1119,7 @@ private_commands=( "revert_preview" "reset_head_preview" "show_enter" - "show_view" + "show_preview" "stash_push_preview" "stash_show_preview" "yank_sha"