summaryrefslogtreecommitdiffstats
path: root/bin/fzf-preview.sh
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-10-26 00:22:28 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-10-26 00:49:16 +0900
commitd02b9442a56ec03dbb905d432762cf545603ef07 (patch)
treefdf5878111abb8693a559fff355e499c49378782 /bin/fzf-preview.sh
parentbac385b59ccef279400689d406bf270cfdee06f3 (diff)
(Experimental) Improve Sixel graphics support (#2544)
Progress: * Sixel image can now be displayed with other text, and is scrollable * If an image can't be displayed entirely due to the scroll offset, fzf will render a wireframe to indicate that an image should be displayed * Renamed $FZF_PREVIEW_{WIDTH,HEIGHT} to $FZF_PREVIEW_PIXEL_{WIDTH,HEIGHT} for clarity * Added bin/fzf-preview.sh script to demonstrate how to display an image using Kitty or Sixel protocol An example: ls *.jpg | fzf --preview='seq $((FZF_PREVIEW_LINES*9/10)); fzf-preview.sh {}; seq 100' A known issue: * If you reduce the size of the preview window, the image may extend beyond the preview window
Diffstat (limited to 'bin/fzf-preview.sh')
-rwxr-xr-xbin/fzf-preview.sh30
1 files changed, 30 insertions, 0 deletions
diff --git a/bin/fzf-preview.sh b/bin/fzf-preview.sh
new file mode 100755
index 00000000..82c0b25b
--- /dev/null
+++ b/bin/fzf-preview.sh
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+#
+# The purpose of this script is to demonstrate how to preview a file or an
+# image in the preview window of fzf.
+
+file=$1
+type=$(file --mime-type "$file")
+
+if [[ ! $type =~ image/ ]]; then
+ # Sometimes bat is installed as batcat.
+ if command -v batcat > /dev/null; then
+ batname="batcat"
+ elif command -v bat > /dev/null; then
+ batname="bat"
+ else
+ cat "$1"
+ exit
+ fi
+
+ ${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"
+elif [[ -n $FZF_PREVIEW_PIXEL_WIDTH ]]; then
+ convert "$file" -resize "${FZF_PREVIEW_PIXEL_WIDTH}x${FZF_PREVIEW_PIXEL_HEIGHT}>" -dither FloydSteinberg sixel:-
+else
+ file "$file"
+fi