35 lines
827 B
Bash
Executable file
35 lines
827 B
Bash
Executable file
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
UB_PID=0
|
|
UB_SOCKET=""
|
|
LF_DIRFILE="/tmp/lfdir.$(uuidgen)"
|
|
UB_PIDFILE="/tmp/ubpid.$(uuidgen)"
|
|
|
|
clean () {
|
|
exec 3>&-
|
|
ueberzugpp cmd -s "$UB_SOCKET" -a exit
|
|
}
|
|
|
|
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
|
command lf -last-dir-path="$LF_DIRFILE" "$@"
|
|
else
|
|
[ ! -d "$XDG_CACHE_HOME/lf" ] && mkdir --parents "$XDG_CACHE_HOME/lf"
|
|
ueberzugpp layer --silent --no-stdin --use-escape-codes --pid-file "$UB_PIDFILE"
|
|
UB_PID=$(cat "$UB_PIDFILE")
|
|
UB_SOCKET="/tmp/ueberzugpp-${UB_PID}.socket"
|
|
rm "$UB_PIDFILE"
|
|
export UB_PID UB_SOCKET
|
|
trap clean HUP INT QUIT TERM PWR EXIT
|
|
command lf -last-dir-path="$LF_DIRFILE" "$@" 3>&-
|
|
fi
|
|
|
|
dir="$(cat "$LF_DIRFILE")"
|
|
rm "$LF_DIRFILE"
|
|
if [ -d "$dir" ]; then
|
|
if [ "$dir" != "$(pwd)" ]; then
|
|
cd "$dir"
|
|
fi
|
|
fi
|
|
tput cuu1;tput el
|