-
Notifications
You must be signed in to change notification settings - Fork 1
/
vifm-sixel
executable file
·68 lines (61 loc) · 1.6 KB
/
vifm-sixel
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
[ -d "$HOME/.cache/vifm" ] || mkdir -p "$HOME/.cache/vifm"
# $1 action
action="$1"
# $2 panel width
# $3 panel height
panel_width=$2
panel_height=$3
cell_width=6
cell_height=14
width=$((panel_width*cell_width))
height=$((panel_height*cell_height))
# $4 image path
image_file="$4"
background=black
PCACHE="$HOME/.cache/vifm/thumbnail.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$PWD/$image_file")" | sha256sum | awk '{print $1}')"
cleanup() {
printf '\33[s\33[5A\33[2K\33[u'
clear
exit 0
}
# recieves image with height
image() {
montage "$1" -background "$background" -geometry "${2}x${3}" sixel:-
}
case "$action" in
"clear")
cleanup
;;
"draw")
[ ! -f "${PCACHE}.jpg" ] && convert "$image_file"'[0]' "${PCACHE}.jpg"
# FILE="$PWD/$image_file"
image "${PCACHE}.jpg" "$width" "$height"
;;
"video")
[ ! -f "${PCACHE}.jpg" ] && \
ffmpegthumbnailer -i "$4" -o "${PCACHE}.jpg" -s 0 -q 5
image "${PCACHE}.jpg" "$width" "$height"
;;
"epub")
[ ! -f "${PCACHE}.jpg" ] && \
epub-thumbnailer "$image_file" "$PCACHE" 1024
image "${PCACHE}.jpg" "$width" "$height"
;;
"pdf")
[ ! -f "${PCACHE}.jpg" ] && \
pdftoppm -jpeg -f 1 -singlefile "$image_file" "$PCACHE"
image "${PCACHE}.jpg" "$width" "$height"
;;
"audio")
[ ! -f "${PCACHE}.jpg" ] && \
ffmpeg -i "$image_file" "${PCACHE}.jpg" -y >/dev/null
image "${PCACHE}.jpg" "$width" "$height"
;;
"font")
[ ! -f "${PCACHE}.jpg" ] && \
fontpreview -i "$image_file" -o "${PCACHE}.jpg"
image "${PCACHE}.jpg" "$width" "$height"
;;
*)
esac