From 5c366c70644394de15f2866f1d8d1cb34b8f09d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berke=20Kocao=C4=9Flu?= Date: Fri, 10 Nov 2023 22:51:28 +0300 Subject: [PATCH] lf-run: add explicit support for ueberzugpp --- src/sh/integration/lf/lf-run | 53 ++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/src/sh/integration/lf/lf-run b/src/sh/integration/lf/lf-run index 4e87b48f..381d70e1 100755 --- a/src/sh/integration/lf/lf-run +++ b/src/sh/integration/lf/lf-run @@ -4,23 +4,48 @@ set -e -cleanup() { - exec 3>&- - rm -- "$UEBERZUG_FIFO" -} - [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] && exec lf "$@" -fifodir="${XDG_CACHE_HOME:-"$HOME/.cache"}/lf/fifos" -mkdir -p -- "$fifodir" 2> /dev/null || [ -d "$fifodir" ] +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-$$" -UEBERZUG_FIFO="$fifodir/ueberzug-$$" + mkfifo -- "$UEBERZUG_FIFO" + trap 'cleanup' EXIT INT TERM HUP QUIT -mkfifo -- "$UEBERZUG_FIFO" -trap 'cleanup' EXIT INT TERM HUP QUIT + ueberzug -s layer < "$UEBERZUG_FIFO" & + exec 3> "$UEBERZUG_FIFO" -ueberzug -s layer < "$UEBERZUG_FIFO" & -exec 3> "$UEBERZUG_FIFO" + export UEBERZUG_FIFO -export UEBERZUG_FIFO -lf "$@" 3>&- + lf "$@" 3>&- +fi