new lf preview to reduce dependency on kitty
This commit is contained in:
parent
b583cccc89
commit
947d24ac73
|
@ -1,2 +1,3 @@
|
|||
#!/bin/sh
|
||||
kitty +kitten icat --clear --silent --stdin no --transfer-mode memory >/dev/tty
|
||||
# kitty +kitten icat --clear --silent --stdin no --transfer-mode memory >/dev/tty
|
||||
ueberzugpp cmd -s "$UB_SOCKET" -a remove -i PREVIEW
|
||||
|
|
|
@ -5,10 +5,11 @@ image() {
|
|||
h=$3
|
||||
x=$4
|
||||
y=$5
|
||||
kitty +kitten icat --clear --stdin no --silent --transfer-mode memory --place "${w}x${h}@${x}x${y}" "$f" >/dev/tty && exit 1
|
||||
chafa "$f" -f symbols -s "$((w-2))x$h" && exit 1
|
||||
printf "%b" "\033[31mImage previewer failed\033[0m"
|
||||
return 1
|
||||
# kitty +kitten icat --clear --stdin no --silent --transfer-mode memory --place "${w}x${h}@${x}x${y}" "$f" >/dev/tty && exit 1
|
||||
# chafa "$f" -f symbols -s "$((w-2))x$h" && exit 1
|
||||
ueberzugpp cmd -s "$UB_SOCKET" -a add -i PREVIEW -x "$x" -y "$y" --max-width $(($2-1)) --max-height "$h" -f "$f" && exit 1
|
||||
printf "%b" "\033[31mImage previewer failed\033[0m\n"
|
||||
exit 1
|
||||
}
|
||||
|
||||
video() {
|
||||
|
|
|
@ -9,7 +9,7 @@ bindkey -M menuselect 'l' vi-forward-char
|
|||
bindkey -M menuselect 'j' vi-down-line-or-history
|
||||
|
||||
# Widgets
|
||||
bindkey '^e' _lfcd
|
||||
bindkey '^e' _lf
|
||||
bindkey '^g' lg
|
||||
bindkey -M vicmd v edit-command-line
|
||||
|
||||
|
|
|
@ -1,35 +1,45 @@
|
|||
# vim:set ft=zsh
|
||||
# LF Change Dir
|
||||
function lfcd () {
|
||||
tmp="$(mktemp)"
|
||||
fid="$(mktemp)"
|
||||
lf -command '$printf $id > '"$fid"'' -last-dir-path="$tmp" "$@"
|
||||
id="$(cat "$fid")"
|
||||
archivemount_dir="/tmp/__lf_archivemount_$id"
|
||||
if [ -f "$archivemount_dir" ]; then
|
||||
cat "$archivemount_dir" | \
|
||||
while read -r line; do
|
||||
sudo umount "$line"
|
||||
rmdir "$line"
|
||||
done
|
||||
command rm -f "$archivemount_dir"
|
||||
fi
|
||||
if [ -f "$tmp" ]; then
|
||||
dir="$(cat "$tmp")"
|
||||
command rm -f "$tmp"
|
||||
if [ -d "$dir" ]; then
|
||||
if [ "$dir" != "$(pwd)" ]; then
|
||||
cd "$dir"
|
||||
fi
|
||||
|
||||
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 _lfcd () {
|
||||
BUFFER="lfcd"
|
||||
zle accept-line
|
||||
|
||||
function _lf () {
|
||||
BUFFER="lfwrap"
|
||||
zle accept-line
|
||||
}
|
||||
zle -N _lfcd
|
||||
zle -N _lf
|
||||
|
||||
# Cursor Shape
|
||||
function zle-keymap-select () {
|
||||
|
@ -50,9 +60,8 @@ zle -N edit-command-line
|
|||
|
||||
# Lazygit
|
||||
function lg () {
|
||||
[ ! -d "$(pwd)/.git" ] && [[ $(read -ek "?Not in a git repository. Create a new git repository? (y/n): ") =~ ^[Yy]$ ]] && git init
|
||||
[ -d "$(pwd)/.git" ] && lazygit -p $(pwd)
|
||||
zle reset-prompt
|
||||
[ ! -d "$(pwd)/.git" ] && [[ $(read -erk "?Not in a git repository. Create a new git repository? (y/n): ") =~ ^[Yy]$ ]] && git init
|
||||
[ -d "$(pwd)/.git" ] && lazygit -p "$(pwd)"
|
||||
zle reset-prompt
|
||||
}
|
||||
zle -N lg{,}
|
||||
|
||||
|
|
Loading…
Reference in New Issue