separate lf wrapper from zsh config
This commit is contained in:
parent
947d24ac73
commit
3f8af175cb
3 changed files with 38 additions and 38 deletions
|
@ -9,7 +9,7 @@ bindkey -M menuselect 'l' vi-forward-char
|
||||||
bindkey -M menuselect 'j' vi-down-line-or-history
|
bindkey -M menuselect 'j' vi-down-line-or-history
|
||||||
|
|
||||||
# Widgets
|
# Widgets
|
||||||
bindkey '^e' _lf
|
bindkey '^e' _lfwrap
|
||||||
bindkey '^g' lg
|
bindkey '^g' lg
|
||||||
bindkey -M vicmd v edit-command-line
|
bindkey -M vicmd v edit-command-line
|
||||||
|
|
||||||
|
|
|
@ -1,45 +1,10 @@
|
||||||
# vim:set ft=zsh
|
# vim:set ft=zsh
|
||||||
|
|
||||||
function lfclean () {
|
function _lfwrap () {
|
||||||
exec 3>&-
|
|
||||||
ueberzugpp cmd -s $UB_SOCKET -a exit
|
|
||||||
dir="$(cat "$lftmp")"
|
|
||||||
rm "$lftmp"
|
|
||||||
if [ -d "$dir" ]; then
|
|
||||||
if [ "$dir" != "$(pwd)" ]; then
|
|
||||||
cd "$dir"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# LF wrapper to allow for ueberzug previews
|
|
||||||
function lfwrap () {
|
|
||||||
UB_PID=0
|
|
||||||
UB_SOCKET=""
|
|
||||||
lftmp="/tmp/lfdir.$(uuidgen)"
|
|
||||||
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
|
||||||
command lf -last-dir-path="$lftmp" "$@"
|
|
||||||
else
|
|
||||||
[ ! -d "$XDG_CACHE_HOME/lf" ] && mkdir --parents "$XDG_CACHE_HOME/lf"
|
|
||||||
ubtmp="/tmp/ubpid.$(uuidgen)"
|
|
||||||
{
|
|
||||||
ueberzugpp layer --silent --no-stdin --use-escape-codes --pid-file "$ubtmp"
|
|
||||||
UB_PID=$(cat "$ubtmp")
|
|
||||||
rm "$ubtmp"
|
|
||||||
UB_SOCKET="/tmp/ueberzugpp-${UB_PID}.socket"
|
|
||||||
export UB_PID UB_SOCKET
|
|
||||||
}
|
|
||||||
trap lfclean HUP INT QUIT TERM PWR EXIT
|
|
||||||
command lf -last-dir-path="$lftmp" "$@" 3>&-
|
|
||||||
fi
|
|
||||||
tput cuu1;tput el
|
|
||||||
}
|
|
||||||
|
|
||||||
function _lf () {
|
|
||||||
BUFFER="lfwrap"
|
BUFFER="lfwrap"
|
||||||
zle accept-line
|
zle accept-line
|
||||||
}
|
}
|
||||||
zle -N _lf
|
zle -N _lfwrap
|
||||||
|
|
||||||
# Cursor Shape
|
# Cursor Shape
|
||||||
function zle-keymap-select () {
|
function zle-keymap-select () {
|
||||||
|
|
35
.local/bin/lfwrap
Executable file
35
.local/bin/lfwrap
Executable file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/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
|
Loading…
Add table
Add a link
Reference in a new issue