From 21ab64e96213ec99cf3f6f207690ffe710713fcc Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 2 Nov 2023 01:35:36 +0900 Subject: sixel: Export $FZF_PREVIEW_TOP to the preview command (#2544) So that it can determine if it should subtract 1 from $FZF_PREVIEW_LINES to avoid scrolling issue of Sixel image that touches the bottom of the screen. --- bin/fzf-preview.sh | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'bin/fzf-preview.sh') diff --git a/bin/fzf-preview.sh b/bin/fzf-preview.sh index ae4c6521..d72cd2d4 100755 --- a/bin/fzf-preview.sh +++ b/bin/fzf-preview.sh @@ -13,14 +13,14 @@ if [[ $# -ne 1 ]]; then fi file=${1/#\~\//$HOME/} -type=$(file --mime-type "$file") - -dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES} -if [[ $dim = x ]]; then - dim=$(stty size | awk '{print $2 "x" $1}') -fi +type=$(file --dereference --mime -- "$file") if [[ ! $type =~ image/ ]]; then + if [[ $type =~ =binary ]]; then + file "$1" + exit + fi + # Sometimes bat is installed as batcat. if command -v batcat > /dev/null; then batname="batcat" @@ -32,7 +32,19 @@ if [[ ! $type =~ image/ ]]; then fi ${batname} --style="${BAT_STYLE:-numbers}" --color=always --pager=never -- "$file" -elif [[ $KITTY_WINDOW_ID ]]; then + exit +fi + +dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES} +if [[ $dim = x ]]; then + dim=$(stty size < /dev/tty | awk '{print $2 "x" $1}') +elif ! [[ $KITTY_WINDOW_ID ]] && (( FZF_PREVIEW_TOP + FZF_PREVIEW_LINES == $(stty size < /dev/tty | awk '{print $1}') )); then + # Avoid scrolling issue when the Sixel image touches the bottom of the screen + # * https://github.com/junegunn/fzf/issues/2544 + dim=${FZF_PREVIEW_COLUMNS}x$((FZF_PREVIEW_LINES - 1)) +fi + +if [[ $KITTY_WINDOW_ID ]]; then # 1. 'memory' is the fastest option but if you want the image to be scrollable, # you have to use 'stream'. # @@ -42,6 +54,7 @@ elif [[ $KITTY_WINDOW_ID ]]; then kitty icat --clear --transfer-mode=memory --stdin=no --place="$dim@0x0" "$file" | sed '$d' | sed $'$s/$/\e[m/' elif command -v chafa > /dev/null; then chafa -f sixel -s "$dim" "$file" + # Add a new line character so that fzf can display multiple images in the preview window echo else file "$file" -- cgit v1.2.3