From b1d5779c3bf67ae84420a3d3f70dbe0e794fb34b Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Tue, 23 Jan 2024 22:53:10 +0100 Subject: [PATCH] improve mimetype detection in lf previews --- .config/lf/preview | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.config/lf/preview b/.config/lf/preview index 4b15961a2..cf62f0fcf 100755 --- a/.config/lf/preview +++ b/.config/lf/preview @@ -40,7 +40,8 @@ batorcat() { } run() { - if ! command -v $1 >/dev/null 2>&1; then + #shellcheck disable=SC2068 + if ! command -v "$1" >/dev/null 2>&1; then printf "%b" "${RED}Cannot execute $1${RESET}" exit 1 elif $@; then @@ -53,7 +54,8 @@ run() { CACHE="$HOME/.cache/lf/thumbnail-$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')" -case "$(xdg-mime query filetype "$1")" in +# We set the desktop to gnome to force usage of `gio` over `file` for better detection +case "$(env XDG_CURRENT_DESKTOP=GNOME xdg-mime query filetype "$1")" in */x-bzip-compressed-tar | */x-compressed-tar | */x-xz-compressed-tar) run als -- "$1" ;; */x-7z-compressed | */vnd.rar | */x-tar | */zip | */x-java-archive | */x-xz) run 7z l "$1" | sed 1,11d ;; */x-cd-image) run iso-info --no-header -l "$1" ;; @@ -85,10 +87,6 @@ text/* | */json | */schema+json | */xml | */javascript) batorcat "$1" "$2" ;; ;; esac -case "$(file -bL --mime-type "$1")" in -text/*) batorcat "$1" "$2" ;; -esac - xdg-mime query filetype "$1" mediainfo "$1"