summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornic <ra@afu.re>2025-04-14 11:14:28 -0400
committernic <ra@afu.re>2025-04-14 11:14:28 -0400
commitbea9c142d337163f963b7e000db6738510a52991 (patch)
treea2f7d695a0c7779c99a173c5d12386b10ab1459c
parentb821f65c4c63455dae6724d11a4d8bb8e4c3e5a2 (diff)
lf miscs
-rw-r--r--.config/lf/lfrc1
-rwxr-xr-x.local/bin/lfub28
2 files changed, 19 insertions, 10 deletions
diff --git a/.config/lf/lfrc b/.config/lf/lfrc
index 4b790a1..c064b79 100644
--- a/.config/lf/lfrc
+++ b/.config/lf/lfrc
@@ -7,7 +7,6 @@
# that creates the environment for ueberzug. This command can be be aliased
# in your shellrc (`alias lf="lfub") or if set to a binding, should be
# called directly instead of normal lf.
-# called directly instead of normal lf.
# Basic vars
set shellopts '-eu'
diff --git a/.local/bin/lfub b/.local/bin/lfub
index f9bb2df..45864e5 100755
--- a/.local/bin/lfub
+++ b/.local/bin/lfub
@@ -6,19 +6,29 @@
set -e
+UB_PID=0
+UB_SOCKET=""
+
+case "$(uname -a)" in
+ *Darwin*) UEBERZUG_TMP_DIR="$TMPDIR" ;;
+ *) UEBERZUG_TMP_DIR="/tmp" ;;
+esac
+
cleanup() {
exec 3>&-
- rm "$FIFO_UEBERZUG"
+ ueberzugpp cmd -s "$UB_SOCKET" -a exit
}
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
- lf "$@"
+ lf "$@"
else
- [ ! -d "$HOME/.cache/lf" ] && mkdir -p "$HOME/.cache/lf"
- export FIFO_UEBERZUG="$HOME/.cache/lf/ueberzug-$$"
- mkfifo "$FIFO_UEBERZUG"
- ueberzug layer -s <"$FIFO_UEBERZUG" -p json &
- exec 3>"$FIFO_UEBERZUG"
- trap cleanup HUP INT QUIT TERM PWR EXIT
- lf "$@" 3>&-
+ [ ! -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
+ lf "$@" 3>&-
fi