From 3f8af175cb3c8e41d0646f94d9bc36994249a920 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Tue, 13 Jun 2023 16:09:53 +0200 Subject: [PATCH] separate lf wrapper from zsh config --- .config/zsh/configs/bindings | 2 +- .config/zsh/configs/widgets | 39 ++---------------------------------- .local/bin/lfwrap | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 38 deletions(-) create mode 100755 .local/bin/lfwrap diff --git a/.config/zsh/configs/bindings b/.config/zsh/configs/bindings index b5e475801..7ee32868b 100644 --- a/.config/zsh/configs/bindings +++ b/.config/zsh/configs/bindings @@ -9,7 +9,7 @@ bindkey -M menuselect 'l' vi-forward-char bindkey -M menuselect 'j' vi-down-line-or-history # Widgets -bindkey '^e' _lf +bindkey '^e' _lfwrap bindkey '^g' lg bindkey -M vicmd v edit-command-line diff --git a/.config/zsh/configs/widgets b/.config/zsh/configs/widgets index 4c0ddb9b5..810a3b325 100644 --- a/.config/zsh/configs/widgets +++ b/.config/zsh/configs/widgets @@ -1,45 +1,10 @@ # vim:set ft=zsh -function lfclean () { - 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 () { +function _lfwrap () { BUFFER="lfwrap" zle accept-line } -zle -N _lf +zle -N _lfwrap # Cursor Shape function zle-keymap-select () { diff --git a/.local/bin/lfwrap b/.local/bin/lfwrap new file mode 100755 index 000000000..e70ad48c0 --- /dev/null +++ b/.local/bin/lfwrap @@ -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