1
0
Fork 0

rework lf previewer selection

This commit is contained in:
Luca Bilke 2024-01-29 20:46:03 +01:00
parent 994453b5e2
commit 26f135d26b
10 changed files with 54 additions and 23 deletions

View File

@ -7,21 +7,10 @@ set scrolloff 10
set icons
set wrapscroll
set period 1
set previewer ~/.config/lf/preview
set cleaner ~/.config/lf/clean
set previewer "~/.config/lf/preview/chafa"
set cursorpreviewfmt "\033[7;90m"
set promptfmt "\033[34;1m%u\033[36m@\033[34m%h \033[35m[\033[0;1m%d\033[35m]\033[32m » \033[33m%f\033[0m"
cmd toggle-preview %{{
if [ "$(basename $lf_previewer)" = "preview" ]; then
lf -remote "send $id set previewer mediainfo"
else
lf -remote "send $id set previewer ~/.config/lf/preview"
fi
$lf_cleaner
lf -remote "send $id reload"
}}
cmd open $set -f; rifle -c $XDG_CONFIG_HOME/lf/rifle.conf -p 0 $fx; clear
cmd open-with ${{
@ -33,7 +22,6 @@ cmd mkdir &mkdir -p "$(echo $* | tr ' ' '\ ')"
cmd trash &{{
for f in $fx; do
echo $f
trash-put $f &
done
lf -remote "send $id load"
@ -139,16 +127,37 @@ cmd fzfgrep ${{
)"
[ -n "$res" ] && lf -remote "send $id select \"$res\""
}}
cmd extract ${{
for f in $fx; do
aunpack "$f"
done
}}
# TODO: Move this to zsh config
# cmd fzfworkon ${{
# workon -n $(workon | fzf)
# }}
cmd set_previewer %{{
if [ "${1}" = "sixel" ]; then
lf -remote "send $id set sixel"
lf -remote "send $id set previewer ~/.config/lf/preview/sixel"
lf -remote "send $id reload"
echo 'Previewer set to sixel'
elif [ "${1}" = "ueberzug" ]; then
lf -remote "send $id set cleaner ~/.config/lf/preview/clean"
lf -remote "send $id set previewer ~/.config/lf/preview/ueberzug"
lf -remote "send $id reload"
echo 'Previewer set to ueberzug'
else
lf -remote "send $id set previewer ~/.config/lf/preview/chafa"
lf -remote "send $id reload"
echo 'Previewer set to chafa'
fi
}}
# Bindings
map <c-c>a fzfsearch
map <c-c>t fzftags
@ -159,7 +168,6 @@ map T trash
map <c-t> $trash-restore $PWD
map <c-d> &rm -rf -- $fx
map <c-e> extract
map R toggle-preview
map P link
# map S share
map <c-g> lazygit

1
.config/lf/preview/chafa Symbolic link
View File

@ -0,0 +1 @@
preview

View File

@ -1,5 +1,6 @@
#!/bin/sh
RED="\033[31m"
RESET="\033[0m"
@ -10,12 +11,22 @@ f=$1 w=$2 h=$3 x=$4 y=$5
image() {
f=$1 w=$2 h=$3 x=$4 y=$5
if [ -f "$f" ] && [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
# chafa "$f" -f sixel -s "$(($2 - 2))x$3" --animate false
if command -V ueberzug >/dev/null 2>&1; then
printf '{"action": "add", "identifier": "PREVIEW", "x": "%s", "y": "%s", "width": "%s", "height": "%s", "scaler": "contain", "path": "%s"}\n' "$(($4 + 3))" "$(($5 + 1))" "$(($2 - 6))" "$(($3 - 2))" "$1" >"$FIFO_UEBERZUG"
name=$(basename "$0")
if [ "$name" = "sixel" ]; then
[ "$TERM_PROGRAM" = "tmux" ] && tmuxflags="--passthrough tmux"
# shellcheck disable=2086
chafa "$f" -f sixel -s "$(($2 - 2))x$3" --animate false --polite on $tmuxflags
exit 0
elif [ "$name" = "ueberzug" ]; then
if command -V ueberzug >/dev/null 2>&1; then
printf '{"action": "add", "identifier": "PREVIEW", "x": "%s", "y": "%s", "width": "%s", "height": "%s", "scaler": "contain", "path": "%s"}\n' "$(($4 + 3))" "$(($5 + 1))" "$(($2 - 6))" "$(($3 - 2))" "$1" >"$FIFO_UEBERZUG"
fi
exit 1
else
chafa "$f" -s "$(($2 - 2))x$3" --polite on
fi
fi
exit 1
}
video() {
@ -92,7 +103,7 @@ if command -v gio 1>/dev/null 2>&1; then
fi
case $(file -b "$f") in
*ASCII* | *UTF*) text "$f" "$w";;
*ASCII* | *UTF*) text "$f" "$w" ;;
*)
printf "%b" "\$(file --mime-type)\t\t\t : $filerun\n"
[ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n"

1
.config/lf/preview/sixel Symbolic link
View File

@ -0,0 +1 @@
preview

1
.config/lf/preview/ueberzug Symbolic link
View File

@ -0,0 +1 @@
preview

View File

@ -2,3 +2,4 @@ HISTSIZE=10000000
SAVEHIST=10000000
HISTFILE="$XDG_DATA_HOME/zsh/history"
KEYTIMEOUT=1
LF_PREVIEW_TYPE=sixel # sixel | ueberzug | *chafa*

View File

@ -16,7 +16,13 @@ function reset_beam() { echo -ne '\e[5 q'; }
function lfwrap () {
LF_DIRFILE="/tmp/lfdir.$(uuidgen)"
lf-ueberzug -last-dir-path="$LF_DIRFILE"
if [ "${LF_PREVIEW_TYPE:-sixel}" = "sixel" ]; then
lf-sixel -last-dir-path="$LF_DIRFILE"
elif [ "${LF_PREVIEW_TYPE}" = "ueberzug" ]; then
lf-ueberzug -last-dir-path="$LF_DIRFILE"
else
lf -last-dir-path="$LF_DIRFILE"
fi
dir="$(cat "$LF_DIRFILE")"
rm "$LF_DIRFILE"
if [ -d "$dir" ]; then

View File

@ -2,8 +2,9 @@
set -e
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
lf "$@"
command lf "$@"
else
[ ! -d "$HOME/.cache/lf" ] && mkdir --parents "$HOME/.cache/lf"
lf "$@" 3>&-
# shellcheck disable=2016
command lf -command 'set_previewer sixel' "$@" 3>&-
fi

View File

@ -15,5 +15,6 @@ else
ueberzug layer -s -p json <"$FIFO_UEBERZUG" &
exec 3>"$FIFO_UEBERZUG"
trap clean EXIT
command lf "$@" 3>&-
# shellcheck disable=2016
command lf -command 'set_previewer ueberzug' "$@" 3>&-
fi