summaryrefslogtreecommitdiffstats
path: root/bin/fzf-preview.sh
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-11-02 01:35:36 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-11-02 01:35:36 +0900
commit21ab64e96213ec99cf3f6f207690ffe710713fcc (patch)
tree3d1ebb4ea016827751987abff3f6890d137682f9 /bin/fzf-preview.sh
parenta0145cebf284898fce182d78a1edae7270d16f57 (diff)
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.
Diffstat (limited to 'bin/fzf-preview.sh')
-rwxr-xr-xbin/fzf-preview.sh27
1 files changed, 20 insertions, 7 deletions
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"