Fix LF previewer

This commit is contained in:
Filippo Berto 2023-09-18 11:56:57 +02:00
parent b56563cf07
commit 0c9bdf42ec
No known key found for this signature in database
GPG key ID: FE98AE5EC52B1056

View file

@ -1,13 +1,9 @@
{ pkgs, ... }:
let
cleaner = pkgs.writeShellScript "cleaner" ''
file=$1
case $TERM in
xterm-kitty ) kitty +icat --clear --silent --transfer-mode $file; ;;
* ) exit 0 ;;
esac
kitty +kitten icat --clear --stdin no --silent --transfer-mode file < /dev/null > /dev/tty
'';
previewer = pkgs.writeShellScript "previewer" ''
file=$1
w=$2
@ -15,10 +11,44 @@ let
x=$4
y=$5
case $TERM in
xterm-kitty ) kitty +icat --silent --transfer-mode file --place "''${w}x''${h}@''${x}x''${y}" "$file"; ;;
* ) ${pkgs.pistol}/bin/pistol "$file"; ;;
preview() {
kitty +kitten icat --silent --stdin no --transfer-mode file --place "''${w}x''${h}@''${x}x''${y}" "$1" < /dev/null > /dev/tty
}
TEMPDIR=~/.cache/lf
file="$1"; shift
case "$(basename "$file" | tr '[A-Z]' '[a-z]')" in
*.tar*) tar tf "$file" ;;
*.zip) unzip -l "$file" ;;
*.rar) unrar l "$file" ;;
*.7z) 7z l "$file" ;;
*.avi|*.mp4|*.mkv)
thumbnail="$TEMPDIR/thumbnail.png"
ffmpeg -y -i "$file" -vframes 1 "$thumbnail"
preview "$thumbnail"
;;
*.pdf)
thumbnail="$TEMPDIR/thumbnail.png"
gs -o "$thumbnail" -sDEVICE=pngalpha -dLastPage=1 "$file" >/dev/null
preview "$thumbnail"
;;
*.jpg|*.jpeg|*.png|*.bmp)
preview "$file"
;;
*.ttf|*.otf|*.woff)
thumbnail="$TEMPDIR/thumbnail.png"
fontpreview -i "$file" -o "$thumbnail"
preview "$thumbnail"
;;
*.svg)
thumbnail="$TEMPDIR/thumbnail.png"
convert "$file" "$thumbnail"
preview "$thumbnail"
;;
*) lf_bat_preview "$file" ;;
esac
return 127 # nonzero retcode required for lf previews to reload
'';
in
{
@ -31,6 +61,7 @@ in
number = true;
# scrollof = 3;
hidden = true;
ignorecase = true;
tabstop = 2;
};
previewer = {
@ -39,28 +70,53 @@ in
};
keybindings = { "<c-f>" = "$EDITOR $(fzf)"; };
commands = {
"z" = ''
''${{
result="$(zoxide query --exclude "$PWD" -- "$@")"
lf -remote "send $id cd '$result'"
}}'';
"zi" = ''
''${{
result="$(zoxide query -i -- "$@")"
lf -remote "send $id cd '$result'"
}}'';
"extract" = ''
''${{
set -f
case $f in
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.xz|*.txz) tar xJvf $f;;
*.zip) unzip $f;;
*.rar) unrar x $f;;
*.7z) 7z x $f;;
esac
}}'';
mkdir = ''''${{
printf "Directory name: "
read ans
mkdir $ans
}}'';
mkfile = ''''${{
printf "File name: "
read ans
$VISUAL $ans
}}'';
trash = ''''${{
files=$(printf "$fx" | tr '\n' ';')
while [ "$files" ]; do
file=''${files%%;*}
${pkgs.trash-cli}/bin/trash-put "$(basename "$file")"
if [ "$files" = "$file" ]; then
files=""
else
files="''${files#*;}"
fi
done
}}'';
restore_trash = ''''${{
trash-restore
}}'';
z = ''''${{
result="$(zoxide query --exclude "$PWD" -- "$@")"
lf -remote "send $id cd '$result'"
}}'';
zi = ''''${{
result="$(zoxide query -i -- "$@")"
lf -remote "send $id cd '$result'"
}}'';
extract = ''''${{
set -f
case $f in
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.xz|*.txz) tar xJvf $f;;
*.zip) unzip $f;;
*.rar) unrar x $f;;
*.7z) 7z x $f;;
esac
}}'';
"tar" = ''
''${{
set -f