diff options
author | Justine Smithies <justine@smithies.me.uk> | 2024-11-08 20:48:58 +0000 |
---|---|---|
committer | Justine Smithies <justine@smithies.me.uk> | 2024-11-08 20:48:58 +0000 |
commit | c2fbc4d1717864a0055592e0b73d71c010e8686c (patch) | |
tree | 76e5bf50cc0f9c1b83f474740a8015d7f4e0ef26 /.config/lf/previewer.sh | |
parent | b9d24b3b6bdaed04fab07d9150c51d4f0f7a5c7d (diff) |
Initial commit
Diffstat (limited to '.config/lf/previewer.sh')
-rwxr-xr-x | .config/lf/previewer.sh | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/.config/lf/previewer.sh b/.config/lf/previewer.sh new file mode 100755 index 0000000..764758b --- /dev/null +++ b/.config/lf/previewer.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +if command -v bat >/dev/null 2>&1; then + pagercmd="bat --color=always --style=plain --pager=never" +else + pagercmd="less -FRiX" +fi + +case "$(printf "%s\n" "$(readlink -f "$1")" | awk '{print tolower($0)}')" in + *.tgz|*.tar.gz) tar tzf "$1";; + *.tar.bz2|*.tbz2) tar tjf "$1";; + *.tar.txz|*.txz) xz --list "$1";; + *.tar) tar tf "$1";; + *.zip|*.jar|*.war|*.ear|*.oxt|*.apkg|*.apk) unzip -l "$1";; + *.rar) unrar l "$1";; + *.7z) 7z l "$1";; + *.[1-8]) man "$1" | col -b ;; + *.epub|*.rtf|*.doc|*.docx|*.odt|*.ods|*.odp|*.sxw) + pandoc -s -t markdown -- "$1" | $pagercmd + exit 1 + ;; + *.jpg|*.jpeg|*.png|*.bmp|*.xpm|*.gif) + chafa -f sixel -s "$2x$3" --animate false "$1" --polite on + exit 1 + ;; + *.pdf) + CACHE=$(mktemp) + pdftoppm -png -f 1 -singlefile "$1" "$CACHE" + chafa -f sixel -s "$2x$3" --animate false "$CACHE.png" --polite on + rm "$CACHE" + ;; + *.avi|*.mp4|*.wmv|*.dat|*.3gp|*.ogv|*.mkv|*.mpg|*.mpeg|*.vob|*.fl[icv]|*.m2v|*.mov|*.webm|*.ts|*.mts|*.m4v|*.r[am]|*.qt|*.divx) + CACHE=$(mktemp) + ffmpegthumbnailer -i "$1" -o "$CACHE" -s 0 + chafa -f sixel -s "$2x$3" --animate false "$CACHE" --polite on + rm "$CACHE" + ;; + *) + bat --color=always --style=plain --pager=never "$1" + ;; +esac |