From 00d28845a34ed088021acf6b09be57ce45992d05 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Fri, 23 May 2025 18:04:55 +0200 Subject: [PATCH] zsh:glog: Fix preview with files that were renamed Previously when calling `glog -- file` with a file that was renamed sometime in the history, the preview would just be empty for all commits before the rename, since it's path didn't exist. Fix this by checking for empty output and falling back to the full patch in that case. This also heavily refactors the code around `$fzf_preview` to make it more readable. TODO: It would be nice if git-show would fail in this case instead of just printing nothing and returning zero --- .config/zsh/autoload/git/glog | 50 +++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/.config/zsh/autoload/git/glog b/.config/zsh/autoload/git/glog index 8b38ed7..e457b83 100755 --- a/.config/zsh/autoload/git/glog +++ b/.config/zsh/autoload/git/glog @@ -49,39 +49,49 @@ local commit_hash='s/^[^a-f0-9]*([a-f0-9]*).*$/\1/' local dateshort='--date=format:%F' # year local date="$dateshort %T %z" # year time timezone -local -A fzf_preview -read -r -d '' <` for 'patch' command with `-- ` argument, so that # the passed file is ontop although the full patch is shown # TODO: Support -L flag as well (add `-s` for list and `-- ` & maybe `-W` # for preview) -fzf_preview[files_only]="$fzf_preview[patch] ${(@)${@:${@[(ei)--]}}/(#m)*/'$MATCH'}" - -# Use git's pager in the preview window (and with it any special highlighting -# tool, such as diff-so-fancy) -local pager -pager="$(git config --get --default="" core.pager)" -fzf_preview[patch]+="${pager:+ | }$pager; }" -fzf_preview[files_only]+="${pager:+ | }$pager; }" - -read -r -d '' <