diff --git a/.config/lf/cleaner b/.config/lf/cleaner index abe2208..be1490c 100755 --- a/.config/lf/cleaner +++ b/.config/lf/cleaner @@ -1,5 +1,4 @@ #!/bin/sh -if [ -n "$FIFO_UEBERZUG" ]; then - printf '{"action": "remove", "identifier": "PREVIEW"}\n' > "$FIFO_UEBERZUG" -fi + +ueberzugpp cmd -s $UB_SOCKET -a remove -i PREVIEW diff --git a/.config/lf/previewer b/.config/lf/previewer index 0b66865..458cee8 100755 --- a/.config/lf/previewer +++ b/.config/lf/previewer @@ -1,28 +1,27 @@ #!/bin/sh -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}'))" image() { - # if [ -n "$DISPLAY" ]; then - # printf '{"action": "add", "identifier": "PREVIEW", "x": "%s", "y":"%s", "width": "%s", "height": "%s", "scaler": "contain", "path": "%s"}\n' \ - # "$4" "$5" "$(($2-1))" "$(($3-1))" "$1" > "$FIFO_UEBERZUG" - # exit 1 - # else - chafa "$1" -s "$4x" - # fi + FILE_PATH="$1" + X=$4 + Y=$5 + MW=$(($2 - 1)) + MH=$3 + ueberzugpp cmd -s "$UB_SOCKET" -a add -i PREVIEW -x "$X" -y "$Y" --max-width "$MW" --max-height "$MH" -f "$FILE_PATH" + exit 1 } batorcat() { - file="$1" - shift - if command -v bat > /dev/null 2>&1 - then - bat --color=always --style=plain --pager=never "$file" "$@" - else - cat "$file" - fi + file="$1" + shift + if command -v bat >/dev/null 2>&1; then + bat --color=always --style=plain --pager=never "$file" "$@" + else + cat "$file" + fi } +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 "$(file --dereference --brief --mime-type -- "$1")" in image/*) image "$1" "$2" "$3" "$4" "$5" "$1" diff --git a/.local/bin/lf b/.local/bin/lf new file mode 100755 index 0000000..17d4833 --- /dev/null +++ b/.local/bin/lf @@ -0,0 +1,32 @@ +#!/bin/sh +# Ueberzugpp script for lf file explorer + +set -e + +UB_PID=0 +UB_SOCKET="" + +case "$(uname -a)" in + *Darwin*) UEBERZUG_TMP_DIR="$TMPDIR" ;; + *) UEBERZUG_TMP_DIR="/tmp" ;; +esac + +cleanup() { + exec 3>&- + ueberzugpp cmd -s "$UB_SOCKET" -a exit +} + +if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then + /usr/bin/lf "$@" +else + [ ! -d "$HOME/.cache/lf" ] && mkdir -p "$HOME/.cache/lf" + UB_PID_FILE="$UEBERZUG_TMP_DIR/.$(uuidgen)" + ueberzugpp layer --silent --no-stdin --use-escape-codes --pid-file "$UB_PID_FILE" + UB_PID=$(cat "$UB_PID_FILE") + rm "$UB_PID_FILE" + UB_SOCKET="$UEBERZUG_TMP_DIR/ueberzugpp-${UB_PID}.socket" + export UB_PID UB_SOCKET + trap cleanup HUP INT QUIT TERM EXIT + /usr/bin/lf "$@" 3>&- +fi + diff --git a/.local/bin/lfub b/.local/bin/lfub deleted file mode 100755 index 92c5f56..0000000 --- a/.local/bin/lfub +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -set -e - -cleanup() { - exec 3>&- - rm "$FIFO_UEBERZUG" -} - -if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then - lf "$@" -else - [ ! -d "$HOME/.cache/lf" ] && mkdir -p "$HOME/.cache/lf" - export FIFO_UEBERZUG="$HOME/.cache/lf/ueberzug-$$" - mkfifo "$FIFO_UEBERZUG" - ueberzug layer -s --output x11 <"$FIFO_UEBERZUG" -p json & - exec 3>"$FIFO_UEBERZUG" - trap cleanup HUP INT QUIT TERM PWR EXIT - lf "$@" 3>&- -fi -