Skip to content

Commit

Permalink
lf-{cleaner,preview,run}: use previewimage
Browse files Browse the repository at this point in the history
  • Loading branch information
XPhyro committed Jan 9, 2024
1 parent 45a4f36 commit 7558bc9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 116 deletions.
19 changes: 2 additions & 17 deletions src/sh/integration/lf/lf-cleaner
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,5 @@

. shellverbose.sh

if [ -n "$KITTY_PID" ]; then
kitty +kitten icat --stdin no clear < /dev/null > /dev/tty
elif [ -n "$UEBERZUG_FIFO" ]; then
jq -cn \
--arg action remove \
--arg identifier PREVIEW \
'{
action: $action,
identifier: $identifier,
}' > "$UEBERZUG_FIFO"
elif [ -n "$UEBERZUGPP_SOCKET" ]; then
ueberzugpp \
cmd \
-s $UEBERZUGPP_SOCKET \
-a remove \
-i PREVIEW
fi
[ "$#" -eq 0 ] && exit 1
previewimage remove "${id:-"$PPID"}"
52 changes: 2 additions & 50 deletions src/sh/integration/lf/lf-preview
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,8 @@

exec_preview_image() {
if [ -n "$DISPLAY" ]; then
if [ -n "$KITTY_PID" ]; then
kitty +kitten icat \
--transfer-mode file \
--stdin no \
--scale-up \
--clear \
--place ${2}x${3}@${4}x${5} ${1} < /dev/null > /dev/tty
exit 1
elif [ -n "$LF_PREVIEW_USE_SIXEL" ] && [ "$LF_PREVIEW_USE_SIXEL" -ne 0 ]; then
chafa -f sixel -s "$(($2 - 2))x$3" -- "$1"
exit 0
elif { [ -z "$LF_PREVIEW_USE_UEBERZUG" ] || [ "$LF_PREVIEW_USE_UEBERZUG" -ne 0 ]; } \
&& command -v ueberzug > /dev/null 2>&1; then
jq -cn \
--arg action add \
--arg identifier PREVIEW \
--arg x "$4" \
--arg y "$5" \
--arg width "$(($2 - 1))" \
--arg height "$(($3 - 1))" \
--arg scaler fit_contain \
--arg path "$1" \
'{
action: $action,
identifier: $identifier,
x: $x,
y: $y,
width: $width,
height: $height,
scaler: $scaler,
path: $path,
}' > "$UEBERZUG_FIFO"
exit 1
elif { [ -z "$LF_PREVIEW_USE_UEBERZUGPP" ] || [ "$LF_PREVIEW_USE_UEBERZUGPP" -ne 0 ]; } \
&& command -v ueberzugpp > /dev/null 2>&1; then
ueberzugpp \
cmd \
-s "$UEBERZUGPP_SOCKET" \
-a add \
-i PREVIEW \
-x "$4" \
-y "$5" \
--max-width "$(($2 - 1))" \
--max-height "$(($3 - 1))" \
-f "$1"
exit 1
else
chafa -s "$(($2 - 2))x$3" -- "$1"
exit 0
fi
previewimage add "${id:-"$PPID"}" "$1" "$(($2 - 1))" "$(($3 - 1))" "$4" "$5"
exit 1
else
chafa -s "$(($2 - 2))x$3" -- "$1"
exit 0
Expand Down
50 changes: 1 addition & 49 deletions src/sh/integration/lf/lf-run
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,4 @@

set -e

[ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] \
|| [ -n "$LF_NO_IMAGE_PREVIEW" ] \
&& exec lf "$@"

if command -v -- ueberzugpp > /dev/null 2>&1; then
cleanup() {
exec 3>&-
ueberzugpp cmd -s "$UEBERZUGPP_SOCKET" -a exit
}

cachedir="${XDG_CACHE_HOME:-"$HOME/.cache"}/lf"
mkdir -p -- "$cachedir" 2> /dev/null || [ -d "$cachedir" ]

UEBERZUGPP_PID_FILE="$UEBERZUG_TMP_DIR/.$(uuidgen)"
ueberzugpp layer --silent --no-stdin --use-escape-codes --pid-file "$UEBERZUGPP_PID_FILE"

UEBERZUGPP_PID=$(cat "$UEBERZUGPP_PID_FILE")
rm -- "$UEBERZUGPP_PID_FILE"

UEBERZUGPP_SOCKET="$UEBERZUG_TMP_DIR/ueberzugpp-${UEBERZUGPP_PID}.socket"

export UEBERZUGPP_PID
export UEBERZUGPP_SOCKET

trap cleanup HUP INT QUIT TERM EXIT

lf "$@" 3>&-
elif command -v -- ueberzug > /dev/null 2>&1; then
cleanup() {
exec 3>&-
rm -- "$UEBERZUG_FIFO"
}

fifodir="${XDG_CACHE_HOME:-"$HOME/.cache"}/lf/fifos"
mkdir -p -- "$fifodir" 2> /dev/null || [ -d "$fifodir" ]
UEBERZUG_FIFO="$fifodir/ueberzug-$$"

mkfifo -- "$UEBERZUG_FIFO"
trap 'cleanup' EXIT INT TERM HUP QUIT

ueberzug -s layer < "$UEBERZUG_FIFO" &
exec 3> "$UEBERZUG_FIFO"

export UEBERZUG_FIFO

lf "$@" 3>&-
else
lf "$@"
fi
exec lf "$@"

0 comments on commit 7558bc9

Please sign in to comment.