1
0
Fork 0

lf: switch to ouch, clean up wrappers

This commit is contained in:
Luca Bilke 2025-03-07 17:12:49 +01:00
parent 1449dde205
commit d717166a82
Signed by: luca
GPG key ID: F6E11C9BAA7C82F5
4 changed files with 33 additions and 38 deletions
common
.config
.local/bin

View file

@ -195,9 +195,15 @@ cmd find_project ${{
}}
cmd extract ${{
for f in $fx; do
aunpack "$f"
done
set -f
ouch decompress $fx
}}
cmd archivemount ${{
mntdir="${f}.mnt"
mkdir -p -- "$mntdir"
archivemount "$f" "$mntdir"
lf -remote "send $id cd \"$(printf '%s' "$mntdir" | sed 's/\\/\\\\/g;s/"/\\"/g')\""
}}
cmd pdf_merge ${{
@ -262,7 +268,7 @@ map <c-d> confirm_delete
map d cut
map D &dragon-drop -a -x $fx
map <c-e> scroll-down
map e :set user_multiedit "true" ; open; set user_multiedit "false"
map e :set user_multiedit "true"; open; set user_multiedit "false"
map E $sudo -e $f
map f find
map F find-back
@ -304,8 +310,8 @@ map u :clear; unselect
map <c-v> pushedit
map v invert
# map W new_lf_term
map x $$f
map X !$f
map x :extract
map X :archivemount
map <c-y> scroll-down
map y copy
map Y &echo $f | xclip -r -selection c

View file

@ -27,12 +27,8 @@ CHAFA="chafa \
--animate false
"
archive1() {
7z l "$f" | sed 1,11d
}
archive2() {
als -- "$f"
archive() {
ouch list -Htyq "$f" | tail -n +2
}
csv() {
@ -46,7 +42,7 @@ docx() {
}
epub() {
gnome-epub-thumbnailer -s 1024 "$f" /dev/stdout
gnome-epub-thumbnailer -s 1024 "$f" /dev/stdout | $CHAFA
}
html() {
@ -91,7 +87,7 @@ odt() {
}
pdf() {
pdftoppm -jpeg -f 1 -singlefile "$f"
pdftoppm -jpeg -f 1 -singlefile "$f" | $CHAFA
}
sqlite() {
@ -149,7 +145,11 @@ run() {
if [ -r "$cache" ]; then
cat "$cache"
else
"$@" | tee -p "$cache"
if out=$("$@"); then
printf "%s" "$out" | tee -p "$cache"
else
printf "%s" "$out"
fi
fi
}
@ -158,7 +158,7 @@ preview() {
case "$mimetype" in
*/vnd.openxmlformats-officedocument.spreadsheetml.sheet | */vnd.oasis.opendocument.spreadsheet) run ods ;;
*/vnd.sqlite3) run sqlite ;;
*/x-7z-compressed | */vnd.rar | */x-tar | */zip | */x-java-archive | */x-xz | */gzip) run archive1 ;;
*/x-7z-compressed | */vnd.rar | */x-tar | */zip | */x-java-archive | */x-xz | */gzip | */x-bzip-compressed-tar | */x-compressed-tar | */x-xz-compressed-tar) run archive ;;
*/epub+zip) run -s epub ;;
image/svg+xml) run -s svg ;;
image/*) run -s image ;;
@ -173,7 +173,6 @@ preview() {
*/msword) run word ;;
*/x-bittorrent) run torrent ;;
*/x-cd-image) run iso ;;
*/x-bzip-compressed-tar | */x-compressed-tar | */x-xz-compressed-tar) run archive2 ;;
*/*lua) run lua ;;
*/*yaml) run yaml ;;
*text*) run text ;;

View file

@ -79,17 +79,15 @@ zle -N sudo-command-line
function lf-wrap() {
LF_DIRFILE="$(mktemp -u)"
env lfX -last-dir-path="$LF_DIRFILE" \
lfX -last-dir-path="$LF_DIRFILE" \
-command "set promptfmt \"$(${HOME}/.local/libexec/lf_prompt 2>/dev/null)\""
dir="$(cat "$LF_DIRFILE")"
rm "$LF_DIRFILE" &>/dev/null
if [ -d "$dir" ]; then
if [ "$dir" != "$(pwd)" ]; then
cd "$dir"
fi
fi
while ! cd "$dir"; do
dir="$(dirname -- "$dir")"
done
reset_prompt
write_title_wd

View file

@ -1,19 +1,11 @@
#!/bin/sh
set -e
# clean() {
# exec 3>&-
# rm "$FIFO_UEBERZUG"
# }
mkdir --parents "${XDG_CACHE_HOME:-"${HOME}/.cache"}/lf"
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
command lf "$@"
else
[ ! -d "$HOME/.cache/lf" ] && mkdir --parents "$HOME/.cache/lf"
# export FIFO_UEBERZUG="$XDG_RUNTIME_DIR/ueberzug-$$"
# mkfifo "$FIFO_UEBERZUG"
# ueberzug layer -s -p json <"$FIFO_UEBERZUG" &
# exec 3>"$FIFO_UEBERZUG"
# trap clean EXIT
command lf "$@" 3>&-
fi
command lf "$@"
awk '$1 == "archivemount" { print $2 }' /etc/mtab | while read -r mntdir; do
sanitized="$(printf "%s" "$mntdir")"
umount "$sanitized" && rmdir "$sanitized"
done