Files
dotfiles/lf/.config/lf/preview-kitty
Zastian Pretorius 3ac2ceb52e bit connect
2024-01-17 21:25:07 +00:00

40 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
file=$1
w=$2
h=$3
x=$4
y=$5
filetype="$( file -Lb --mime-type "$file")"
image() {
kitty +icat --silent --transfer-mode file --place "${w}x${h}@${x}x${y}" "$file"
}
case "$(file --dereference --brief --mime-type -- "$1")" in
image/*) image "$file" ;;
text/html) lynx -width="$4" -display_charset=utf-8 -dump "$1" ;;
text/troff) man ./ "$1" | col -b ;;
text/* | */xml | application/json) bat --terminal-width "$(($4-2))" -f "$1" ;;
application/zip) atool --list -- "$1" ;;
video/* | audio/*|application/octet-stream)
CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)"
[ ! -f "$CACHE" ] && ffmpegthumbnailer -i "$1" -o "$CACHE" -s 0
kitty +kitten icat --silent --transfer-mode file --place "${w}x${h}@${x}x${y}" "$CACHE"
[ ! -s "$CACHE" ] && mediainfo "$1" ;;
*/pdf)
CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)"
[ ! -f "$CACHE.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"
image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1"
;;
*/epub+zip|*/mobi*)
CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)"
[ ! -f "$CACHE.jpg" ] && gnome-epub-thumbnailer "$1" "$CACHE.jpg"
image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1"
;;
*opendocument*) odt2txt "$1" ;;
application/pgp-encrypted) gpg -d -- "$1" ;;
esac
pistol "$file"
exit 1