rework lf previewer selection
This commit is contained in:
parent
994453b5e2
commit
26f135d26b
10 changed files with 54 additions and 23 deletions
|
@ -7,21 +7,10 @@ set scrolloff 10
|
||||||
set icons
|
set icons
|
||||||
set wrapscroll
|
set wrapscroll
|
||||||
set period 1
|
set period 1
|
||||||
set previewer ~/.config/lf/preview
|
set previewer "~/.config/lf/preview/chafa"
|
||||||
set cleaner ~/.config/lf/clean
|
|
||||||
set cursorpreviewfmt "\033[7;90m"
|
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"
|
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 $set -f; rifle -c $XDG_CONFIG_HOME/lf/rifle.conf -p 0 $fx; clear
|
||||||
|
|
||||||
cmd open-with ${{
|
cmd open-with ${{
|
||||||
|
@ -33,7 +22,6 @@ cmd mkdir &mkdir -p "$(echo $* | tr ' ' '\ ')"
|
||||||
|
|
||||||
cmd trash &{{
|
cmd trash &{{
|
||||||
for f in $fx; do
|
for f in $fx; do
|
||||||
echo $f
|
|
||||||
trash-put $f &
|
trash-put $f &
|
||||||
done
|
done
|
||||||
lf -remote "send $id load"
|
lf -remote "send $id load"
|
||||||
|
@ -139,16 +127,37 @@ cmd fzfgrep ${{
|
||||||
)"
|
)"
|
||||||
[ -n "$res" ] && lf -remote "send $id select \"$res\""
|
[ -n "$res" ] && lf -remote "send $id select \"$res\""
|
||||||
}}
|
}}
|
||||||
|
|
||||||
cmd extract ${{
|
cmd extract ${{
|
||||||
for f in $fx; do
|
for f in $fx; do
|
||||||
aunpack "$f"
|
aunpack "$f"
|
||||||
done
|
done
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
# TODO: Move this to zsh config
|
||||||
# cmd fzfworkon ${{
|
# cmd fzfworkon ${{
|
||||||
# workon -n $(workon | fzf)
|
# 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
|
# Bindings
|
||||||
map <c-c>a fzfsearch
|
map <c-c>a fzfsearch
|
||||||
map <c-c>t fzftags
|
map <c-c>t fzftags
|
||||||
|
@ -159,7 +168,6 @@ map T trash
|
||||||
map <c-t> $trash-restore $PWD
|
map <c-t> $trash-restore $PWD
|
||||||
map <c-d> &rm -rf -- $fx
|
map <c-d> &rm -rf -- $fx
|
||||||
map <c-e> extract
|
map <c-e> extract
|
||||||
map R toggle-preview
|
|
||||||
map P link
|
map P link
|
||||||
# map S share
|
# map S share
|
||||||
map <c-g> lazygit
|
map <c-g> lazygit
|
||||||
|
|
1
.config/lf/preview/chafa
Symbolic link
1
.config/lf/preview/chafa
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
preview
|
|
@ -1,5 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
|
||||||
RED="\033[31m"
|
RED="\033[31m"
|
||||||
RESET="\033[0m"
|
RESET="\033[0m"
|
||||||
|
|
||||||
|
@ -10,12 +11,22 @@ f=$1 w=$2 h=$3 x=$4 y=$5
|
||||||
image() {
|
image() {
|
||||||
f=$1 w=$2 h=$3 x=$4 y=$5
|
f=$1 w=$2 h=$3 x=$4 y=$5
|
||||||
if [ -f "$f" ] && [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
|
if [ -f "$f" ] && [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
|
||||||
# chafa "$f" -f sixel -s "$(($2 - 2))x$3" --animate false
|
name=$(basename "$0")
|
||||||
if command -V ueberzug >/dev/null 2>&1; then
|
if [ "$name" = "sixel" ]; 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"
|
[ "$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
|
||||||
fi
|
fi
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
video() {
|
video() {
|
||||||
|
@ -92,7 +103,7 @@ if command -v gio 1>/dev/null 2>&1; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case $(file -b "$f") in
|
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"
|
printf "%b" "\$(file --mime-type)\t\t\t : $filerun\n"
|
||||||
[ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n"
|
[ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n"
|
1
.config/lf/preview/sixel
Symbolic link
1
.config/lf/preview/sixel
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
preview
|
1
.config/lf/preview/ueberzug
Symbolic link
1
.config/lf/preview/ueberzug
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
preview
|
|
@ -2,3 +2,4 @@ HISTSIZE=10000000
|
||||||
SAVEHIST=10000000
|
SAVEHIST=10000000
|
||||||
HISTFILE="$XDG_DATA_HOME/zsh/history"
|
HISTFILE="$XDG_DATA_HOME/zsh/history"
|
||||||
KEYTIMEOUT=1
|
KEYTIMEOUT=1
|
||||||
|
LF_PREVIEW_TYPE=sixel # sixel | ueberzug | *chafa*
|
||||||
|
|
|
@ -16,7 +16,13 @@ function reset_beam() { echo -ne '\e[5 q'; }
|
||||||
|
|
||||||
function lfwrap () {
|
function lfwrap () {
|
||||||
LF_DIRFILE="/tmp/lfdir.$(uuidgen)"
|
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")"
|
dir="$(cat "$LF_DIRFILE")"
|
||||||
rm "$LF_DIRFILE"
|
rm "$LF_DIRFILE"
|
||||||
if [ -d "$dir" ]; then
|
if [ -d "$dir" ]; then
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||||
lf "$@"
|
command lf "$@"
|
||||||
else
|
else
|
||||||
[ ! -d "$HOME/.cache/lf" ] && mkdir --parents "$HOME/.cache/lf"
|
[ ! -d "$HOME/.cache/lf" ] && mkdir --parents "$HOME/.cache/lf"
|
||||||
lf "$@" 3>&-
|
# shellcheck disable=2016
|
||||||
|
command lf -command 'set_previewer sixel' "$@" 3>&-
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -15,5 +15,6 @@ else
|
||||||
ueberzug layer -s -p json <"$FIFO_UEBERZUG" &
|
ueberzug layer -s -p json <"$FIFO_UEBERZUG" &
|
||||||
exec 3>"$FIFO_UEBERZUG"
|
exec 3>"$FIFO_UEBERZUG"
|
||||||
trap clean EXIT
|
trap clean EXIT
|
||||||
command lf "$@" 3>&-
|
# shellcheck disable=2016
|
||||||
|
command lf -command 'set_previewer ueberzug' "$@" 3>&-
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue