summaryrefslogtreecommitdiff
path: root/.config/lf/preview
diff options
context:
space:
mode:
Diffstat (limited to '.config/lf/preview')
-rwxr-xr-x.config/lf/preview68
1 files changed, 68 insertions, 0 deletions
diff --git a/.config/lf/preview b/.config/lf/preview
new file mode 100755
index 0000000..635edc9
--- /dev/null
+++ b/.config/lf/preview
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+set -C -f
+IFS="$(printf '%b_' '\n')"
+IFS="${IFS%_}"
+
+# Called by lf to generate the preview.
+# $1 file path
+# $4 x offset in cell coordinates
+# $5 y offset in cell coordinates
+# $2 width of the display area in cell coordinates
+# $3 height of the display area in cell coordinates
+THUMBNAIL_FPATH="$LF_KITTY_TEMPDIR/thumbnail.png"
+
+# case "$(basename -- "$1" | tr '[:upper:]' '[:lower:]')" in
+case "$(file --dereference --brief --mime-type -- "$1")" in
+text/html)
+ lynx -width="$4" -display_charset=utf-8 -dump "$1"
+ ;;
+text/troff)
+ w=`expr "$2" - 2`
+ MANWIDTH="$w" man ./ "$1"
+ ;;
+text/* | */xml)
+ [ "${1##*.}" = "md" ] && glow -s dark -w "$2" "$1" && exit 0
+ bat --terminal-width "$(($4 - 2))" -f "$1"
+ ;;
+application/json | application/x-ndjson)
+ jq -C < "$1" ;;
+audio/* | application/octet-stream)
+ mediainfo "$1" || exit 1
+ ;;
+image/png)
+ $XDG_CONFIG_HOME/lf/kitty.sh show "$1" $LF_KITTY_IMAGE_ID 1 $4 $5 $2 $3
+ ;;
+image/gif)
+ magick convert "${1}[0]" "$THUMBNAIL_FPATH"
+ $XDG_CONFIG_HOME/lf/kitty.sh show "$THUMBNAIL_FPATH" $LF_KITTY_IMAGE_ID 1 $4 $5 $2 $3
+ ;;
+image/*)
+ magick convert "$1" "$THUMBNAIL_FPATH"
+ $XDG_CONFIG_HOME/lf/kitty.sh show "$THUMBNAIL_FPATH" $LF_KITTY_IMAGE_ID 1 $4 $5 $2 $3
+ ;;
+application/pdf)
+ gs -o "$THUMBNAIL_FPATH" -sDEVICE=pngalpha -dLastPage=1 "$1" >/dev/null
+ $XDG_CONFIG_HOME/lf/kitty.sh show "$THUMBNAIL_FPATH" $LF_KITTY_IMAGE_ID 1 $4 $5 $2 $3
+ ;;
+font/* | application/vnd.ms-opentype)
+ FONT_NAME=$(fc-query --format "%{family}\n" "$1" | head -n 1)
+
+ PREVIEW_TEXT="${FONT_NAME}\nABCDEFGHIJKLMNOPQRSTUBWXYZ\n""\
+abcdefghijklmnopqrstuvwxyz\n""\
+1234567890\n""\
+!@#$\%(){}[]-+=_\`~"
+
+ magick convert -size "1920x1080" xc:'#ffffff' \
+ -gravity center -pointsize 76 \
+ -font "$1" \
+ -fill '#000000' \
+ -annotate +0+0 "$PREVIEW_TEXT" \
+ "$THUMBNAIL_FPATH"
+ $XDG_CONFIG_HOME/lf/kitty.sh show "$THUMBNAIL_FPATH" $LF_KITTY_IMAGE_ID 1 $4 $5 $2 $3
+ ;;
+*)
+ cat "$1"
+ ;;
+esac
+exit 127