1
0
Fork 0

lf: optimize previews

This commit is contained in:
Luca Bilke 2024-06-18 08:13:06 +02:00
parent 276920a5c3
commit 58681c13e0
No known key found for this signature in database
GPG Key ID: C9E851809C1A5BDE
1 changed files with 22 additions and 13 deletions

View File

@ -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,15 +23,24 @@ video() {
}
text() {
bat \
--color=always \
--italic-text=always \
--style=plain \
--pager=never \
--tabs=4 \
--theme=base16 \
--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() {
@ -101,13 +110,13 @@ CACHE="${XDG_CACHE_HOME}/lf/$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readl
# Special cases
[ "$(dirname "$(realpath "$f")" | rev | cut -d/ -f1 | rev)" = "factscache" ] &&
[ -f "$(dirname "$(dirname "$(realpath "$f")")")/ansible.cfg" ] &&
jq -C <"$f" && exit 1
jq -C <"$f" && exit
giorun="$(gio info "$f" 2>/dev/null | grep standard::content-type | cut -d' ' -f4)"
mimetest "$giorun" && exit 1
mimetest "$giorun" && exit
filerun="$(file --brief --dereference --mime-type "$f")"
mimetest "$filerun" && exit 1
mimetest "$filerun" && exit
printf "%b" "\$(file --mime-type)\t\t\t : $filerun\n"
[ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n"