From d8154a98dd82346a5e90d276abe81e43a1678d41 Mon Sep 17 00:00:00 2001 From: themamiza <131671116+themamiza@users.noreply.github.com> Date: Mon, 1 Jun 2026 02:01:54 +0330 Subject: lf improvements (#1477) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove and merge duplicate entries The 'case' statement had two identical commands for opening files using `zathura`. Removed the extra match patterns and merged into one. * Fix file checks * Fix indentation and use the same syntax style All the indentation are fixed. All syntax styles have been set to match the first occurrence. * Slightly faster filename generation for thumbnails Use `md5sum` instead of `sha256sum` since the hash is only used as a cache identifier (no security/integrity requirement). Remove the trailing “ -” that `md5sum` prints for stdin by trimming everything after the first space using POSIX parameter expansion (${var%% *}), avoiding extra processes like `cut` or `awk`. --- .config/lf/lfrc | 3 +-- .config/lf/scope | 41 ++++++++++++++++++----------------------- 2 files changed, 19 insertions(+), 25 deletions(-) (limited to '.config') diff --git a/.config/lf/lfrc b/.config/lf/lfrc index d877ab6..d38f16a 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -30,7 +30,7 @@ set autoquit true cmd open ${{ case $(file --mime-type "$(readlink -f $f)" -b) in application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) localc $fx ;; - image/vnd.djvu|application/pdf|application/postscript) setsid -f zathura $fx >/dev/null 2>&1 ;; + image/vnd.djvu|application/vnd.djvu|application/pdf|application/postscript|application/epub*) setsid -f zathura $fx >/dev/null 2>&1 ;; text/*|application/json|inode/x-empty|application/x-subrip) $EDITOR $fx;; image/x-xcf) setsid -f gimp $f >/dev/null 2>&1 ;; image/svg+xml) display -- $f ;; @@ -43,7 +43,6 @@ cmd open ${{ ;; audio/*|video/x-ms-asf) mpv --audio-display=no $f ;; video/*) setsid -f mpv $f -quiet >/dev/null 2>&1 ;; - application/pdf|application/vnd.djvu|application/epub*) setsid -f zathura $fx >/dev/null 2>&1 ;; application/pgp-encrypted) $EDITOR $fx ;; application/vnd.openxmlformats-officedocument.wordprocessingml.document|application/vnd.oasis.opendocument.text|application/vnd.openxmlformats-officedocument.spreadsheetml.sheet|application/vnd.oasis.opendocument.spreadsheet|application/vnd.oasis.opendocument.spreadsheet-template|application/vnd.openxmlformats-officedocument.presentationml.presentation|application/vnd.oasis.opendocument.presentation-template|application/vnd.oasis.opendocument.presentation|application/vnd.ms-powerpoint|application/vnd.oasis.opendocument.graphics|application/vnd.oasis.opendocument.graphics-template|application/vnd.oasis.opendocument.formula|application/vnd.oasis.opendocument.database) setsid -f libreoffice $fx >/dev/null 2>&1 ;; application/octet-stream) case ${f##*.} in diff --git a/.config/lf/scope b/.config/lf/scope index 332b07e..b55962f 100755 --- a/.config/lf/scope +++ b/.config/lf/scope @@ -18,43 +18,38 @@ image() { # be regenerated once seen. case "$(file --dereference --brief --mime-type -- "$1")" in - image/avif) CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)" - [ ! -f "$CACHE" ] && magick "$1" "$CACHE.jpg" + image/avif) CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" + [ ! -f "$CACHE.jpg" ] && magick "$1" "$CACHE.jpg" image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" ;; image/vnd.djvu) - CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)" - [ ! -f "$CACHE" ] && djvused "$1" -e 'select 1; save-page-with /dev/stdout' | magick -density 200 - "$CACHE.jpg" > /dev/null 2>&1 + CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" + [ ! -f "$CACHE.jpg" ] && djvused "$1" -e 'select 1; save-page-with /dev/stdout' | magick -density 200 - "$CACHE.jpg" > /dev/null 2>&1 + image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" ;; + image/svg+xml) + CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" + [ ! -f "$CACHE.png" ] && inkscape --convert-dpi-method=none -o "$CACHE.png" --export-overwrite -D --export-png-color-mode=RGBA_16 "$1" + image "$CACHE.png" "$2" "$3" "$4" "$5" "$1" ;; + image/x-xcf) + CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" + [ ! -f "$CACHE.jpg" ] && magick "$1[0]" "$CACHE.jpg" image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" ;; -image/svg+xml) - CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)" - [ ! -f "$CACHE" ] && inkscape --convert-dpi-method=none -o "$CACHE.png" --export-overwrite -D --export-png-color-mode=RGBA_16 "$1" - image "$CACHE.png" "$2" "$3" "$4" "$5" "$1" - ;; - image/x-xcf) - CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')" - [ ! -f "$CACHE.jpg" ] && magick "$1[0]" "$CACHE.jpg" - image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" - ;; image/*) image "$1" "$2" "$3" "$4" "$5" "$1" ;; text/html) lynx -width="$4" -display_charset=utf-8 -dump "$1" ;; text/troff) man ./ "$1" | col -b ;; text/* | */xml | application/json | application/x-ndjson) bat -p --theme ansi --terminal-width "$(($4-2))" -f "$1" ;; audio/* | application/octet-stream) mediainfo "$1" || exit 1 ;; video/* ) - CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)" + CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" [ ! -f "$CACHE" ] && ffmpegthumbnailer -i "$1" -o "$CACHE" -s 0 - image "$CACHE" "$2" "$3" "$4" "$5" "$1" - ;; + image "$CACHE" "$2" "$3" "$4" "$5" "$1" ;; */pdf) - CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)" + CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" [ ! -f "$CACHE.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE" - image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" - ;; + image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" ;; */epub+zip|*/mobi*) - CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)" + CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" [ ! -f "$CACHE.jpg" ] && gnome-epub-thumbnailer "$1" "$CACHE.jpg" - image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" - ;; + image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" ;; application/*zip) atool --list -- "$1" ;; *opendocument*) odt2txt "$1" ;; application/pgp-encrypted) gpg -d -- "$1" ;; -- cgit v1.3.1