diff options
| author | pants <niklasjo2004@gmail.com> | 2026-09-21 14:18:06 -0700 |
|---|---|---|
| committer | pants <niklasjo2004@gmail.com> | 2026-09-21 14:18:06 -0700 |
| commit | 83d5ba42f8a98fc0df177efef4333f74a0481f61 (patch) | |
| tree | 6f1fcff64ec9adb2fc51a7cfcc451eb22a103fb3 /scripts/lf/lfub | |
Diffstat (limited to 'scripts/lf/lfub')
| -rwxr-xr-x | scripts/lf/lfub | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/lf/lfub b/scripts/lf/lfub new file mode 100755 index 0000000..45864e5 --- /dev/null +++ b/scripts/lf/lfub @@ -0,0 +1,34 @@ +#!/bin/sh + +# This is a wrapper script for lf that allows it to create image previews with +# ueberzug. This works in concert with the lf configuration file and the +# lf-cleaner script. + +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 + 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 + lf "$@" 3>&- +fi |
