From ab95fa9dc42ac2f4c9f92aa075d21388612a2913 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Sun, 13 Oct 2024 19:49:29 +0200 Subject: [PATCH] lf: streamline previews, fix new_lf_term function --- common/.config/lf/lfrc | 6 +- common/.config/lf/preview/clean | 5 -- common/.config/lf/preview/preview | 119 ----------------------------- common/.config/lf/preview/vidthumb | 36 --------- 4 files changed, 2 insertions(+), 164 deletions(-) delete mode 100755 common/.config/lf/preview/clean delete mode 100755 common/.config/lf/preview/preview delete mode 100755 common/.config/lf/preview/vidthumb diff --git a/common/.config/lf/lfrc b/common/.config/lf/lfrc index fb9ec1add..fef9c6286 100644 --- a/common/.config/lf/lfrc +++ b/common/.config/lf/lfrc @@ -193,9 +193,8 @@ cmd extract ${{ done }} -# HACK: This is a dirty hack to have an lf terminal that I can "exit" out of into a shell cmd new_lf_term &{{ - mapcmd='map q $sh -c "tmux; kill $id"' + mapcmd='map q $sh -c "$SHELL; kill $id"' $TERMINAL -e lfX -command "$mapcmd" }} @@ -219,8 +218,7 @@ set period 1 set cursorpreviewfmt "\033[7;90m" set promptfmt # this is set in a function later set sixel -set previewer ~/.config/lf/preview/preview -set cleaner ~/.config/lf/preview/clean +set previewer ~/.config/lf/preview # Bindings clearmaps diff --git a/common/.config/lf/preview/clean b/common/.config/lf/preview/clean deleted file mode 100755 index acab52f2c..000000000 --- a/common/.config/lf/preview/clean +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -if [ -n "$FIFO_UEBERZUG" ]; then - printf '{"action": "remove", "identifier": "PREVIEW"}\n' > "$FIFO_UEBERZUG" -fi diff --git a/common/.config/lf/preview/preview b/common/.config/lf/preview/preview deleted file mode 100755 index 0d2662662..000000000 --- a/common/.config/lf/preview/preview +++ /dev/null @@ -1,119 +0,0 @@ -#!/bin/sh - -RED="\033[31m" -RESET="\033[0m" - -set -C -f - -f="$(realpath "$1")" w=$2 h=$3 # x=$4 y=$5 - -image() { - file=${1:-$f} - # shellcheck disable=2086 - chafa -f sixel -s "${w}x${h}" --polite on --animate false "$file" - exit -} - -video() { - thumb="$("$HOME/.config/lf/preview/vidthumb" "$f")" || { - printf "%b" "${RED}vidthumb failed to execute${RESET}" - return 1 - } - image "$thumb" -} - -text() { - for cmd in bat batcat; do - command -v $cmd >/dev/null 2>&1 && break - done - $cmd \ - --style=full \ - --color=always \ - --italic-text=always \ - --pager=never \ - --tabs=4 \ - --theme=base16 \ - --line-range=":$h" \ - --terminal-width="$((w - 2))" \ - "$@" -} - -run() { - #shellcheck disable=SC2068 - if ! command -v "$1" >/dev/null 2>&1; then - printf "%b" "${RED}Cannot execute ${1}${RESET}" - elif "$@"; then - : - else - printf "%b" "${RED}Failed to run command: ${RESET}" - for l in "$@"; do - printf "%b" "\n${RED} ${l}${RESET}" - done - fi - exit 1 -} - -mimetest() { - case "$1" in - */x-bzip-compressed-tar | */x-compressed-tar | */x-xz-compressed-tar) run als -- "$f" ;; - */x-7z-compressed | */vnd.rar | */x-tar | */zip | */x-java-archive | */x-xz | */gzip) run 7z l "$f" | sed 1,11d ;; - */x-cd-image) run iso-info --no-header -l "$f" ;; - */x-bittorrent) run transmission-show "$f" ;; - */vnd.sun.xml.writer) run odt2txt "$f" ;; - */msword) run catdoc "$f" ;; - */vnd.openxmlformats-officedocument.wordprocessingml.document) run docx2txt <"$f" ;; - */vnd.ms-excel) run ssconvert --export-type=Gnumeric_stf:stf_csv "$f" "fd://1" | text --language=csv "$f" ;; - */vnd.openxmlformats-officedocument.spreadsheetml.sheet) run ssconvert --export-type=Gnumeric_stf:stf_csv "$f" "fd://1" | text --language=csv "$f" ;; - # */pgp-encrypted) run gpg -d -- "$f" ;; - */pkix-cert) run openssl x509 -text -noout -in "$f" ;; - *opendocument*) run odt2txt "$f" ;; - */markdown) - [ ! -f "${CACHE}.txt" ] && run mdless "$f" >"${CACHE}.txt" - text "${CACHE}.txt" - ;; - */html) run lynx -dump "$f" ;; - */*json) - [ ! -f "${CACHE}.txt" ] && run jq -C <"$f" >"${CACHE}.txt" - text "${CACHE}.txt" - ;; - */*yaml) - # [ ! -f "${CACHE}.txt" ] && run yq -C <"$f" >"${CACHE}.txt" - # text "${CACHE}.txt" - text --language=yaml "$f" - ;; - */*lua) text "$f" ;; - */epub+zip) - [ ! -f "$CACHE" ] && run epub-thumbnailer "$f" "$CACHE" 1024 - image "$CACHE" - ;; - image/svg+xml) - [ ! -f "${CACHE}.png" ] && run inkscape --convert-dpi-method=none -o "${CACHE}.png" --export-overwrite -D --export-png-color-mode=RGBA_16 "$f" - image "${CACHE}.png" - ;; - */pdf) - [ ! -f "${CACHE}.jpg" ] && run pdftoppm -jpeg -f 1 -singlefile "$f" "$CACHE" - image "${CACHE}.jpg" - ;; - video/*) video ;; - image/*) image ;; - *text*) text "$f" ;; - *) return 1 ;; - esac -} - -CACHE="${XDG_CACHE_HOME}/lf/$(stat --printf "%n\0%i\0%F\0%s\0%W\0%Y" -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')" - -# Special cases -[ "$(dirname "$(realpath "$f")" | rev | cut -d/ -f1 | rev)" = "factscache" ] && - [ -f "$(dirname "$(dirname "$(realpath "$f")")")/ansible.cfg" ] && - jq -C <"$f" && exit - -giorun="$(gio info "$f" 2>/dev/null | grep standard::content-type | cut -d' ' -f4)" -mimetest "$giorun" && exit - -filerun="$(file --brief --dereference --mime-type "$f")" -mimetest "$filerun" && exit - -printf "%b" "\$(file --mime-type)\t\t\t : $filerun\n" -[ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n" -mediainfo "$1" | head -n -2 | grep -v -e "Complete name" -e "General" diff --git a/common/.config/lf/preview/vidthumb b/common/.config/lf/preview/vidthumb deleted file mode 100755 index 105622186..000000000 --- a/common/.config/lf/preview/vidthumb +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh - -if ! [ -f "$1" ]; then - exit 1 -fi - -cache="$XDG_CACHE_HOME/lf" -index="$cache/index.json" -file="$(realpath "$1")" - -mkdir -p "$cache" - -if [ -f "$index" ]; then - thumbnail="$(jq -r ". \"$file\"" <"$index")" - if [ "$thumbnail" != "null" ]; then - if [ ! -f "$cache/$thumbnail" ]; then - exit 1 - fi - echo "$cache/$thumbnail" - exit 0 - fi -fi - -thumbnail="$(uuidgen).jpg" - -if ! ffmpegthumbnailer -i "$file" -o "$cache/$thumbnail" -s 0 2>/dev/null; then - exit 1 -fi - -if [ ! -f "$index" ]; then - echo "{\"$file\": \"$thumbnail\"}" >"$index" -fi -json="$(jq -r --arg "$file" "$thumbnail" ". + {\"$file\": \"$thumbnail\"}" <"$index")" -echo "$json" >"$index" - -echo "$cache/$thumbnail"