blob: ffdc35625b8d56d132eeb3e94cc9cbdd7c0409c3 (
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
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/bin/sh
file="$1"
find_cache() {
local CACHE_DIR="${TMPDIR:-$HOME/.cache}/pv_cache"
[ ! -d "${CACHE_DIR}" ] && mkdir -p "${CACHE_DIR}"
local FILE_LOC="$(pwd)/${file}"
local TMP="$(head -c 1024 "$file" | cksum -a md5)"
#CACHE_F="${CACHE_DIR}/${TMP##* }"
echo "${CACHE_DIR}/${TMP##* }"
}
cache() {
exec "$@" "$file" > "${CACHE_F}"
}
case "$(file -Lb --mime-type "$file")" in
image/*)
chafa -f sixel -s "$2x$3" --animate off --polite on -t 1 --bg black "$file"
;;
text/*|application/javascript|application/json)
highlight -O ansi "$file"
;;
application/zstd|application/x-xz|application/gzip|application/x-bzip2|application/zlib)
CACHE_F="$(find_cache)"
[ ! -e "${CACHE_F}" ] && tar -tf "$file" > "${CACHE_F}"
echo "Contents:"
cat "${CACHE_F}"
;;
application/zip)
CACHE_F="$(find_cache)"
[ ! -e "${CACHE_F}" ] && unzip -l "$file" > "${CACHE_F}"
cat "${CACHE_F}"
;;
application/pdf)
CACHE_F="$(find_cache)"
[ ! -e "${CACHE_F}" ] && pdftoppm -png -singlefile "$file" > "${CACHE_F}"
chafa -f sixel -s "$2x$3" --animate off --polite on -t 1 --bg black "${CACHE_F}"
;;
video/*|audio/*)
CACHE_F="$(find_cache)"
[ ! -e "${CACHE_F}" ] && ffmpegthumbnailer -s0 -i "$file" -o "${CACHE_F}"
chafa -f sixel -s "$2x$3" --animate off --polite on -t 1 --bg black "${CACHE_F}"
;;
application/octet-stream)
case "$file" in
*.stl|*.STL)
CACHE_F="$(find_cache)"
[ ! -e "${CACHE_F}" ] && blender -b -P /home/tom/.local/bin/3d-render.py -i "$file" -o "${CACHE_F}" >/dev/null 2>&1
chafa -f sixel -s "$2x$3" --animate off --polite on -t 1 --bg black "${CACHE_F}"
;;
*)
file -b "$1"
;;
esac
;;
*)
file -b "$1"
esac
|