-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlf-previewer
executable file
·40 lines (37 loc) · 916 Bytes
/
lf-previewer
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
#!/usr/bin/env sh
preview() {
cat <<-EOF | paste -sd '' >"$LF_FIFO_UEBERZUG"
{
"action": "add", "identifier": "lf-preview",
"path": "$1", "x": $4, "y": $5, "width": $2, "height": $3,
"scaler": "contain"
}
EOF
}
lf-cleaner # clean active preview
file="$1"; shift
case "$file" in
*.tar*) tar tf "$file" ;;
*.zip) unzip -l "$file" ;;
*.rar) unrar l "$file" ;;
*.7z) 7z l "$file" ;;
*.avi|*.mp4|*.mkv)
thumbnail="$LF_TEMPDIR/thumbnail.png"
ffmpeg -y -i "$file" -vframes 1 "$thumbnail"
preview "$thumbnail" "$@"
;;
*.pdf)
thumbnail="$LF_TEMPDIR/thumbnail.png"
gs -o "$thumbnail" -sDEVICE=pngalpha -dLastPage=1 "$file" >/dev/null
preview "$thumbnail" "$@"
;;
*.jpg|*.jpeg|*.png|*.bmp)
preview "$file" "$@" ;;
*.svg)
thumbnail="$LF_TEMPDIR/thumbnail.png"
convert "$file" "$thumbnail"
preview "$thumbnail" "$@"
;;
*) cat "$file" ;;
esac
return 127 # nonzero retcode required for lf previews to reload