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} file=${1:-$f}
# shellcheck disable=2086 # shellcheck disable=2086
chafa -f sixel -s "${w}x${h}" --polite on --animate false "$file" chafa -f sixel -s "${w}x${h}" --polite on --animate false "$file"
exit 0 exit
} }
video() { video() {
@ -23,15 +23,24 @@ video() {
} }
text() { text() {
bat \ for cmd in bat batcat cat; do
--color=always \ command -v $cmd >/dev/null 2>&1 && break
--italic-text=always \ done
--style=plain \ case $cmd in
--pager=never \ bat*)
--tabs=4 \ $cmd \
--theme=base16 \ --color=always \
--terminal-width="$((w - 2))" "$@" "$f" --italic-text=always \
exit 1 --style=plain \
--pager=never \
--tabs=4 \
--theme=base16 \
--terminal-width="$((w - 2))" "$@" "$f"
;;
cat)
$cmd "$f"
;;
esac
} }
run() { 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 # Special cases
[ "$(dirname "$(realpath "$f")" | rev | cut -d/ -f1 | rev)" = "factscache" ] && [ "$(dirname "$(realpath "$f")" | rev | cut -d/ -f1 | rev)" = "factscache" ] &&
[ -f "$(dirname "$(dirname "$(realpath "$f")")")/ansible.cfg" ] && [ -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)" 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")" filerun="$(file --brief --dereference --mime-type "$f")"
mimetest "$filerun" && exit 1 mimetest "$filerun" && exit
printf "%b" "\$(file --mime-type)\t\t\t : $filerun\n" printf "%b" "\$(file --mime-type)\t\t\t : $filerun\n"
[ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n" [ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n"