From bd35665c2106ad647d31cdf9a093c505f1775753 Mon Sep 17 00:00:00 2001 From: Hoang Nguyen Date: Mon, 25 Mar 2024 00:00:00 +0700 Subject: [PATCH] Improve preview script (again) Convert the image file to JPG and cache it if chafa cannot print the original file to the terminal. Also remove fallback previewer, as it will mangle vifm's preview pane with passthrough flag %N enabled. --- roles/scripts/templates/preview.j2 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/roles/scripts/templates/preview.j2 b/roles/scripts/templates/preview.j2 index d3b00a4..b7b4883 100644 --- a/roles/scripts/templates/preview.j2 +++ b/roles/scripts/templates/preview.j2 @@ -7,6 +7,9 @@ _cache_thumbnail() { tmpfile="${thumbnail_dir}/$(stat -c '%n%i%F%s%Y' -- "$(readlink -f "$2")" | sha256sum | awk '{print $1}').jpg" if [ ! -f "$tmpfile" ]; then case "$1" in + image) + convert -- "$2"'[0]' "$tmpfile" + ;; video) ffmpegthumbnailer -i "$2" -o "$tmpfile" -s 0 ;; @@ -41,15 +44,15 @@ _preview_markdown() { } _preview_image() { - chafa --animate=off --polite=on --size="$2"x"$3" "$1" || exiftool "$1" + chafa --animate=off --polite=on --size="$2"x"$3" "$1" || chafa --animate=off --polite=on --size="$2"x"$3" "$(_cache_thumbnail image "$1")" } _preview_video() { - _preview_image "$(_cache_thumbnail video "$1")" "$2" "$3" || fprobe -hide_banner -pretty "$1" || exiftool "$1" + _preview_image "$(_cache_thumbnail video "$1")" "$2" "$3" } _preview_font() { - _preview_image "$(_cache_thumbnail font "$1")" "$2" "$3" || exiftool "$1" + _preview_image "$(_cache_thumbnail font "$1")" "$2" "$3" } # Take 2 additional arguments as width and height (rows/cols)