diff options
| author | themamiza <131671116+themamiza@users.noreply.github.com> | 2026-06-01 02:01:54 +0330 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-31 18:31:54 -0400 |
| commit | d8154a98dd82346a5e90d276abe81e43a1678d41 (patch) | |
| tree | 8980cf9eeb5faa68cb95bd4c94935954bfd08105 /.config/lf/scope | |
| parent | 4a3ad91070328668cd3c8c375e38843f21506e7a (diff) | |
| download | eibhear-d8154a98dd82346a5e90d276abe81e43a1678d41.tar.gz eibhear-d8154a98dd82346a5e90d276abe81e43a1678d41.tar.zst eibhear-d8154a98dd82346a5e90d276abe81e43a1678d41.zip | |
lf improvements (#1477)
* 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`.
Diffstat (limited to '.config/lf/scope')
| -rwxr-xr-x | .config/lf/scope | 41 |
1 files changed, 18 insertions, 23 deletions
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" ;; |
