-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvifmimg
executable file
·86 lines (80 loc) · 3.52 KB
/
vifmimg
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
PLAY_GIF="yes"
# By enabling this option the GIF will be animated, else it would show an image
# (one frame).
#PDF_PNG=1
# Uncomment to use png. Default behaviour is to use jpg (faster).
cachedir="${XDG_CACHE_HOME:-$HOME/.cache/}"/vifmimg
[ ! -d "$cachedir" ] && mkdir -p "$cachedir"
# Checks if the file has any modifications before preview
#pwd_sum="$cachedir"/"$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$PWD"/"$6")" | sha256sum | awk '{print $1}')"
img_sum="$cachedir"/"$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$PWD"/"$6")" | sha256sum | awk '{print $1}')"
image() {
{ printf '{ "action": "add", "identifier": "vifm-preview",'
printf '"x": %d, "y": %d, "width": %d, "height": %d,' "$2" "$3" "$4" "$5"
printf '"scaler": "fit_contain", "path": "%s" }\n' "$6"
} > "$FIFO_UEBERZUG"
#printf '"scaler": "forced_cover", "path": "%s" }\n' "$6"
}
# if the file doesn't exist and doesn't have a size more than 0, also sets "$1"
# to be clear so it doesn't try to make the preview
[ -n "$6" ] && [ ! -s "$6" ] && echo "The file doesn't exist or it's size is not greater than zero, exiting..." && set -- "clear"
case "$1" in
"pid") # sometimes you killed the windows in any other way and the
# named pipes stay
#find /tmp -name "^vifm-*" -type p
find /tmp -maxdepth 1 -name 'vifm-*' -type p -delete #&& \
echo 'Cleaning vifm named pipes...'
;;
"remove")
[ -d "$cachedir" ] && rm -rf "${cachedir:?}" ;;
"clear")
echo '{"action": "remove", "identifier": "vifm-preview"}' > "$FIFO_UEBERZUG" ;;
"draw")
image "$1" "$2" "$3" "$4" "$5" "$PWD"/"$6" ;;
"videopreview")
# ffmpegthumbnailer uses by default the extension of the name (-o) jpg/png
[ ! -f "$img_sum".jpg ] && \
ffmpegthumbnailer -i "$6" -o "$img_sum".jpg -s 0 -q 10 2>/dev/null
image "$1" "$2" "$3" "$4" "$5" "$img_sum".jpg ;;
"epubpreview")
[ ! -f "$img_sum".png ] && epub-thumbnailer "$6" "$img_sum".png 1024
image "$1" "$2" "$3" "$4" "$5" "$img_sum".png ;;
"gifpreview")
{ [ ! -d "$img_sum"/ ] && mkdir -p "$img_sum"/ ;} \
&& convert -coalesce "$6" "$img_sum"/"$6".png
[ -z "$PLAY_GIF" ] && image "$1" "$2" "$3" "$4" "$5" "$img_sum"/"$6"-0.png
[ -n "$PLAY_GIF" ] && \
for frame in $(find "$img_sum" -maxdepth 1 -name '*.png' | sort -V); do
image "$1" "$2" "$3" "$4" "$5" "$frame"
# Sleep between frames to make the animation smooth.
# Make it infinite loop on gif or exit on user input(?)
sleep .07
done ;;
"pdfpreview")
if [ "$PDF_PNG" ]; then
[ ! -f "$img_sum".png ] && \
pdftoppm -f 1 -scale-to-y -1 -singlefile -png "$6" "$img_sum"
image "$1" "$2" "$3" "$4" "$5" "$img_sum".png
else
[ ! -f "$img_sum".jpg ] && \
pdftoppm -f 1 -scale-to-y -1 -singlefile -jpeg -tiffcompression jpeg "$6" "$img_sum"
image "$1" "$2" "$3" "$4" "$5" "$img_sum".jpg
fi ;;
"docxpreview")
[ ! -f "$img_sum".jpg ] && \
soffice --headless --convert-to pdf "$PWD"/"$6" --outdir "$cachedir" >/dev/null 2>&1 && \
pdftoppm -f 1 -scale-to-y -1 -singlefile -jpeg -tiffcompression jpeg "$cachedir"/"$(noextname "$6")".pdf "$img_sum" && \
rm "$cachedir"/"$(noextname "$6")".pdf &
image "$1" "$2" "$3" "$4" "$5" "$img_sum".jpg ;;
"audiopreview")
[ ! -f "$img_sum".png ] && \
ffmpeg -i "$6" "$img_sum".png -y >/dev/null 2>&1
image "$1" "$2" "$3" "$4" "$5" "$img_sum".jpg ;;
"fontpreview")
[ ! -f "$img_sum".png ] && \
fontpreview -i "$6" -o "$img_sum".png
image "$1" "$2" "$3" "$4" "$5" "$img_sum".png ;;
*)
echo 'Unknown command:' "$1"
esac