diff options
Diffstat (limited to 'dot_config/lf/executable_previewer3')
| -rw-r--r-- | dot_config/lf/executable_previewer3 | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/dot_config/lf/executable_previewer3 b/dot_config/lf/executable_previewer3 new file mode 100644 index 0000000..ffdc356 --- /dev/null +++ b/dot_config/lf/executable_previewer3 @@ -0,0 +1,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 |