aboutsummaryrefslogtreecommitdiff
path: root/.config/lf/preview
blob: c90dba6d16ec9a8cf90c65606d9c48bf1b4c8086 (plain)
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
42
43
44
45
46
47
48
#!/bin/sh
# thank you brodie robertson for this

# Clear the last preview (if any)
$HOME/.config/lf/image clear

# Calculate where the image should be placed on the screen.
num=$(printf "%0.f\n" "`echo "$(tput cols) / 2" | bc`")
numb=$(printf "%0.f\n" "`echo "$(tput cols) - $num - 1" | bc`")
numc=$(printf "%0.f\n" "`echo "$(tput lines) - 2" | bc`")

case "$1" 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) unzip -l "$1";;
	*.rar) unrar l "$1";;
	*.7z) 7z l "$1";;
	*.[1-8]) man "$1" | col -b ;;
	*.o) nm "$1" | less ;;
	*.torrent) transmission-show "$1";;
	*.iso) iso-info --no-header -l "$1";;
	*odt,*.ods,*.odp,*.sxw) odt2txt "$1";;
	*.doc) catdoc "$1" ;;
	*.docx) docx2txt "$1" - ;;
	*.csv) cat "$1" | sed s/,/\\n/g ;;
	*.pdf)
		CACHE=$(mktemp /tmp/thumbcache.XXXXX)
		pdftoppm -png -f 1 -singlefile "$1" "$CACHE"
		$HOME/.config/lf/image draw "$CACHE.png" $num 1 $numb $numc
		;;
	*.epub)
		CACHE=$(mktemp /tmp/thumbcache.XXXXX)
		epub-thumbnailer "$1" "$CACHE" 1024
		$HOME/.config/lf/image draw "$CACHE" $num 1 $numb $numc
		;;
	*.bmp|*.jpg|*.jpeg|*.png|*.xpm)
		$HOME/.config/lf/image draw "$1" $num 1 $numb $numc
		;;
	*.wav|*.mp3|*.flac|*.m4a|*.wma|*.ape|*.ac3|*.og[agx]|*.spx|*.opus|*.as[fx]|*.flac) exiftool "$1";;
	*.avi|*.mp4|*.wmv|*.dat|*.3gp|*.ogv|*.mkv|*.mpg|*.mpeg|*.vob|*.fl[icv]|*.m2v|*.mov|*.webm|*.ts|*.mts|*.m4v|*.r[am]|*.qt|*.divx)
		CACHE=$(mktemp /tmp/thumbcache.XXXXX)
		ffmpegthumbnailer -i "$1" -o "$CACHE" -s 0
		$HOME/.config/lf/image draw "$CACHE" $num 1 $numb $numc
		;;
	*) highlight --out-format ansi "$1" || cat "$1";;
esac