summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-10-26 22:26:47 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-10-26 22:28:44 +0900
commitd3a9a0615b3dacd2169460a515cfa0bcd1683cbe (patch)
treee57dcb90207ce800339d361d4b76b2730da02501 /bin
parent3277e8c89c2eaf18a1eb99898cdab79eb0be23d7 (diff)
Fix kitty icat handling
Diffstat (limited to 'bin')
-rwxr-xr-xbin/fzf-preview.sh11
1 files changed, 7 insertions, 4 deletions
diff --git a/bin/fzf-preview.sh b/bin/fzf-preview.sh
index fe405ef1..bd12e3bc 100755
--- a/bin/fzf-preview.sh
+++ b/bin/fzf-preview.sh
@@ -23,10 +23,13 @@ if [[ ! $type =~ image/ ]]; then
${batname} --style="${BAT_STYLE:-numbers}" --color=always --pager=never -- "$file"
elif [[ $KITTY_WINDOW_ID ]]; then
- # 'memory' is the fastest option but if you want the image to be scrollable,
- # you have to use 'stream'
- kitty icat --clear --transfer-mode=memory --stdin=no --place="${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}@0x0" "$file" | sed \$d
- echo -en "\e[m"
+ # 1. 'memory' is the fastest option but if you want the image to be scrollable,
+ # you have to use 'stream'.
+ #
+ # 2. The last line of the output is the ANSI reset code without newline.
+ # This confuses fzf and makes it render scroll offset indicator.
+ # So we remove the last line and append the reset code to its previous line.
+ kitty icat --clear --transfer-mode=memory --stdin=no --place="${FZF_PREVIEW_COLUMNS}x$((FZF_PREVIEW_LINES))@0x0" "$file" | sed '$d' | sed $'$s/$/\e[m/'
elif command -v chafa > /dev/null; then
chafa -f sixel -s "${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}" "$file"
else