Fix kitty icat handling

This commit is contained in:
Junegunn Choi 2023-10-26 22:26:47 +09:00
parent 3277e8c89c
commit d3a9a0615b
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
1 changed files with 7 additions and 4 deletions

View File

@ -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