aboutsummaryrefslogtreecommitdiff
path: root/.config/lf/previewer.sh
blob: 79959856346a0c1e4a7195921a855c85c0b7fc7b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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"
        exit 1
        ;;
  *.pdf)
	CACHE=$(mktemp)
	pdftoppm -png -f 1 -singlefile "$1" "$CACHE"
	chafa -f sixel -s "$2x$3" --animate false "$CACHE.png"
	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"
	rm "$CACHE"
	;;
  *)
	bat --color=always --style=plain --pager=never "$1"
        ;;
esac