lf: update preview script
This commit is contained in:
parent
da9bc59e2d
commit
0c7182adf4
|
@ -11,7 +11,7 @@ image() {
|
|||
file=${1:-$f}
|
||||
# shellcheck disable=2086
|
||||
chafa -f sixel -s "${w}x${h}" --polite on --animate false "$file"
|
||||
exit 0
|
||||
exit
|
||||
}
|
||||
|
||||
video() {
|
||||
|
@ -23,8 +23,24 @@ video() {
|
|||
}
|
||||
|
||||
text() {
|
||||
bat --color=always --style=plain --pager=never --terminal-width "$((w - 2))" "$@" "$f"
|
||||
exit 1
|
||||
for cmd in bat batcat cat; do
|
||||
command -v $cmd >/dev/null 2>&1 && break
|
||||
done
|
||||
case $cmd in
|
||||
bat*)
|
||||
$cmd \
|
||||
--color=always \
|
||||
--italic-text=always \
|
||||
--style=plain \
|
||||
--pager=never \
|
||||
--tabs=4 \
|
||||
--theme=base16 \
|
||||
--terminal-width="$((w - 2))" "$@" "$f"
|
||||
;;
|
||||
cat)
|
||||
$cmd "$f"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
run() {
|
||||
|
@ -43,95 +59,65 @@ run() {
|
|||
|
||||
mimetest() {
|
||||
case "$1" in
|
||||
*/pdf)
|
||||
[ ! -f "${CACHE}.jpg" ] && run pdftoppm -jpeg -f 1 -singlefile "$f" "$CACHE"
|
||||
image "${CACHE}.jpg"
|
||||
*/x-bzip-compressed-tar | */x-compressed-tar | */x-xz-compressed-tar) run als -- "$f" ;;
|
||||
*/x-7z-compressed | */vnd.rar | */x-tar | */zip | */x-java-archive | */x-xz | */gzip) run 7z l "$f" | sed 1,11d ;;
|
||||
*/x-cd-image) run iso-info --no-header -l "$f" ;;
|
||||
*/x-bittorrent) run transmission-show "$f" ;;
|
||||
*/vnd.sun.xml.writer) run odt2txt "$f" ;;
|
||||
*/msword) run catdoc "$f" ;;
|
||||
*/vnd.openxmlformats-officedocument.wordprocessingml.document) run docx2txt <"$f" ;;
|
||||
*/vnd.ms-excel) run ssconvert --export-type=Gnumeric_stf:stf_csv "$f" "fd://1" | text --language=csv ;;
|
||||
*/vnd.openxmlformats-officedocument.spreadsheetml.sheet) run ssconvert --export-type=Gnumeric_stf:stf_csv "$f" "fd://1" | text --language=csv ;;
|
||||
*/pgp-encrypted) run gpg -d -- "$f" ;;
|
||||
*/pkix-cert) run openssl x509 -text -noout -in "$f" ;;
|
||||
*opendocument*) run odt2txt "$f" ;;
|
||||
*/markdown)
|
||||
[ ! -f "${CACHE}.txt" ] && run glow -s "$XDG_CONFIG_HOME/glow/style.json" "$f" --width "$w" >"${CACHE}.txt"
|
||||
text "${CACHE}.txt"
|
||||
;;
|
||||
*/x-bzip-compressed-tar | */x-compressed-tar | */x-xz-compressed-tar)
|
||||
run als -- "$f"
|
||||
exit 1
|
||||
*/html) run lynx -dump "$f" ;;
|
||||
*/*json)
|
||||
[ ! -f "${CACHE}.txt" ] && run jq -C <"$f" >"${CACHE}.txt"
|
||||
text "${CACHE}.txt"
|
||||
;;
|
||||
*/x-7z-compressed | */vnd.rar | */x-tar | */zip | */x-java-archive | */x-xz | */gzip)
|
||||
run 7z l "$f" | sed 1,11d
|
||||
exit 1
|
||||
;;
|
||||
*/x-cd-image)
|
||||
run iso-info --no-header -l "$f"
|
||||
exit 1
|
||||
;;
|
||||
*/x-bittorrent)
|
||||
run transmission-show "$f"
|
||||
exit 1
|
||||
;;
|
||||
*/vnd.sun.xml.writer)
|
||||
run odt2txt "$f"
|
||||
exit 1
|
||||
;;
|
||||
*/msword)
|
||||
run catdoc "$f"
|
||||
exit 1
|
||||
;;
|
||||
*/vnd.openxmlformats-officedocument.wordprocessingml.document)
|
||||
run docx2txt <"$f"
|
||||
exit 1
|
||||
;;
|
||||
*/vnd.ms-excel)
|
||||
run ssconvert --export-type=Gnumeric_stf:stf_csv "$f" "fd://1" | text --language=csv
|
||||
exit 1
|
||||
;;
|
||||
*/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
|
||||
run ssconvert --export-type=Gnumeric_stf:stf_csv "$f" "fd://1" | text --language=csv
|
||||
exit 1
|
||||
*/*yaml)
|
||||
# [ ! -f "${CACHE}.txt" ] && run yq -C <"$f" >"${CACHE}.txt"
|
||||
# text "${CACHE}.txt"
|
||||
text --language=yaml
|
||||
;;
|
||||
*/*lua) text ;;
|
||||
*/epub+zip)
|
||||
[ ! -f "$CACHE" ] && run epub-thumbnailer "$f" "$CACHE" 1024
|
||||
image "$CACHE"
|
||||
;;
|
||||
*/pgp-encrypted)
|
||||
run gpg -d -- "$f"
|
||||
exit 1
|
||||
;;
|
||||
*/pkix-cert)
|
||||
run openssl x509 -text -noout -in "$f"
|
||||
exit 1
|
||||
;;
|
||||
image/svg+xml)
|
||||
[ ! -f "${CACHE}.png" ] && run inkscape --convert-dpi-method=none -o "${CACHE}.png" --export-overwrite -D --export-png-color-mode=RGBA_16 "$f"
|
||||
image "${CACHE}.png"
|
||||
;;
|
||||
image/*) image ;;
|
||||
*/pdf)
|
||||
[ ! -f "${CACHE}.jpg" ] && run pdftoppm -jpeg -f 1 -singlefile "$f" "$CACHE"
|
||||
image "${CACHE}.jpg"
|
||||
;;
|
||||
video/*) video ;;
|
||||
*opendocument*)
|
||||
run odt2txt "$f"
|
||||
exit 1
|
||||
;;
|
||||
*/markdown)
|
||||
run glow -s "$XDG_CONFIG_HOME/glow/style.json" "$f" --width "$w"
|
||||
exit 1
|
||||
;;
|
||||
*/html)
|
||||
run lynx -dump "$f"
|
||||
exit 1
|
||||
;;
|
||||
image/*) image ;;
|
||||
*text*) text ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
CACHE="${XDG_CACHE_HOME}/lf/thumbnail-$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
|
||||
CACHE="${XDG_CACHE_HOME}/lf/$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
|
||||
|
||||
# Special cases
|
||||
[ "$(dirname "$(realpath "$f")" | rev | cut -d/ -f1 | rev)" = "factscache" ] &&
|
||||
[ -f "$(dirname "$(dirname "$(realpath "$f")")")/ansible.cfg" ] &&
|
||||
jq -C <"$f" && exit
|
||||
|
||||
giorun="$(gio info "$f" 2>/dev/null | grep standard::content-type | cut -d' ' -f4)"
|
||||
mimetest "$giorun" && exit
|
||||
|
||||
filerun="$(file --brief --dereference --mime-type "$f")"
|
||||
mimetest "$filerun" && exit 1
|
||||
mimetest "$filerun" && exit
|
||||
|
||||
if command -v gio 1>/dev/null 2>&1; then
|
||||
giorun="$(gio info "$f" 2>/dev/null | grep standard::content-type | cut -d' ' -f4)"
|
||||
mimetest "$giorun" && exit 1
|
||||
fi
|
||||
|
||||
case "$(file -b "$f")" in
|
||||
*text*) text ;;
|
||||
*)
|
||||
printf "%b" "\$(file --mime-type)\t\t\t : $filerun\n"
|
||||
[ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n"
|
||||
mediainfo "$1" | head -n -2 | grep -v -e "Complete name" -e "General"
|
||||
;;
|
||||
esac
|
||||
printf "%b" "\$(file --mime-type)\t\t\t : $filerun\n"
|
||||
[ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n"
|
||||
mediainfo "$1" | head -n -2 | grep -v -e "Complete name" -e "General"
|
||||
|
|
Loading…
Reference in New Issue