lf config

This commit is contained in:
Tristan 2024-01-06 00:16:18 +00:00
parent f3685dcbf5
commit 026035fe52
2 changed files with 41 additions and 38 deletions

View file

@ -1,6 +1,9 @@
#!/bin/sh
HASH=$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum $1 | cut -f 1 -d " ")
file=${1}
HASH=$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$file")" \
| md5sum | cut -f 1 -d " ")-${2}x${3}
CACHEDIR=/tmp/lf/thumbnail/
mkdir -p $CACHEDIR
@ -10,20 +13,23 @@ image () {
[ ! -f "$CACHE" ] && \
chafa -f sixel -s "$2x$3" --animate off --polite on "$1" > "$CACHE"
cat "$CACHE"
exit 1
}
case "$(file -Lb --mime-type -- "$1")" in
case "$(file -Lb --mime-type -- "$file")" in
image/*)
image $@
exit 1
;;
application/json)
jq '.' "$1" | bat --color always -l json --file-name $file
;;
text/*)
bat "$1"
bat --color always "$file"
;;
application/pdf)
[ ! -f "$CACHE.jpeg" ] && \
pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE.jpeg"
image "$CACHE.jpeg" "$2" "$3" "$4" "$5"
[ ! -f "$CACHE.jpg" ] && \
pdftoppm -jpeg -f 1 -singlefile "$file" "$CACHE"
image "$CACHE.jpg" "$2" "$3" "$4" "$5"
;;
*)
exiftool "$1"
@ -47,18 +53,9 @@ case "$(printf "%s\n" "$(readlink -f "$1")" | awk '{print tolower($0)}')" in
*.odt|*.ods|*.odp|*.sxw) odt2txt "$1" ;;
*.doc) catdoc "$1" ;;
*.docx) docx2txt "$1" - ;;
*.xml|*.html) w3m -dump "$1";;
*.xls|*.xlsx)
ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1"
;;
*.wav|*.mp3|*.flac|*.m4a|*.wma|*.ape|*.ac3|*.og[agx]|*.spx|*.opus|*.as[fx]|*.mka)
exiftool "$1"
;;
*.pdf)
[ ! -f "$CACHE.jpg" ] && \
pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"
image "$CACHE.jpg" "$2" "$3" "$4" "$5"
;;
*.epub)
[ ! -f "$CACHE" ] && \
epub-thumbnailer "$1" "$CACHE" 1024
@ -69,9 +66,6 @@ case "$(printf "%s\n" "$(readlink -f "$1")" | awk '{print tolower($0)}')" in
ffmpegthumbnailer -i "$1" -o "$CACHE.jpg" -s 0 -q 5
image "$CACHE.jpg" "$2" "$3" "$4" "$5"
;;
*.bmp|*.jpg|*.jpeg|*.png|*.xpm|*.webp|*.jfif)
image "$1" "$2" "$3" "$4" "$5"
;;
*.svg)
[ ! -f "$CACHE.jpg" ] && \
convert "$1" "$CACHE.jpg"