summaryrefslogtreecommitdiff
path: root/zscripts/.lfub.zsh
diff options
context:
space:
mode:
authorTim Keller <tjk@tjkeller.xyz>2024-10-18 21:52:28 -0500
committerTim Keller <tjk@tjkeller.xyz>2024-10-18 21:52:28 -0500
commit2dc486fb891e65658dff83ab34ca8878756a6a90 (patch)
tree03b39eb93f38534ab0972beadb770fecbd2243b8 /zscripts/.lfub.zsh
downloadzsh-2dc486fb891e65658dff83ab34ca8878756a6a90.tar.xz
zsh-2dc486fb891e65658dff83ab34ca8878756a6a90.zip
initial commit
Diffstat (limited to 'zscripts/.lfub.zsh')
-rwxr-xr-xzscripts/.lfub.zsh27
1 files changed, 27 insertions, 0 deletions
diff --git a/zscripts/.lfub.zsh b/zscripts/.lfub.zsh
new file mode 100755
index 0000000..2e1f7f4
--- /dev/null
+++ b/zscripts/.lfub.zsh
@@ -0,0 +1,27 @@
+#!/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.
+
+cleanuplf() {
+ exec 3>&-
+ \rm "$FIFO_UEBERZUG"
+}
+
+lfub() {
+ dircache=/tmp/$USER-lflastdir
+ lfopt="--last-dir-path=$dircache"
+ if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
+ lf "$lfopt" "$@"
+ else
+ export FIFO_UEBERZUG="/tmp/ueberzug-$$"
+ mkfifo "$FIFO_UEBERZUG"
+ ueberzug layer -s <"$FIFO_UEBERZUG" -p json &
+ exec 3>"$FIFO_UEBERZUG"
+ trap cleanuplf HUP INT QUIT TERM PWR EXIT
+ lf "$lfopt" "$@" 3>&-
+ fi
+ [ -f "$dircache" ] && dir="$(cat "$dircache")" && [ -d "$dir" ] && cd "$dir"
+}
+
+alias lf="lfub"