Noah Vogt 1 天之前
父节点
当前提交
6daf607bc7
共有 3 个文件被更改,包括 51 次插入63 次删除
  1. 4 3
      dot-config/lf/cleaner
  2. 14 24
      dot-config/lf/lfrc
  3. 33 36
      dot-config/lf/scope

+ 4 - 3
dot-config/lf/cleaner

@@ -1,4 +1,5 @@
 #!/bin/sh
-if [ -n "$FIFO_UEBERZUG" ]; then
-	printf '{"action": "remove", "identifier": "PREVIEW"}\n' > "$FIFO_UEBERZUG"
-fi
+# This only runs when the preview needs to be wiped
+# This is the raw Kitty Graphics Protocol escape sequence to delete all images.
+# It is 100% silent and won't trigger those weird symbols like with kitten.
+printf "\033_Gi=31,a=d\033\\" >/dev/tty

+ 14 - 24
dot-config/lf/lfrc

@@ -1,19 +1,4 @@
-# Luke's lf settings
-
-
-# Note on Image Previews
-# For those wanting image previews, like this system, there are four steps to
-# set it up. These are done automatically for LARBS users, but I will state
-# them here for others doing it manually.
-#
-# 1. ueberzug must be installed.
-# 2. The scope file (~/.config/lf/scope for me), must have a command similar to
-#    mine to generate ueberzug images.
-# 3. A `set cleaner` line as below is a cleaner script.
-# 4. lf should be started through a wrapper script (~/.local/bin/lfub for me)
-#    that creates the environment for ueberzug. This command can be be aliased
-#    in your shellrc (`alias lf="lfub") or if set to a binding, should be
-#    called directly instead of normal lf.
+# most things here are inherited from Luke Smith's lf settings
 
 # Basic vars
 set shellopts '-eu'
@@ -33,12 +18,11 @@ cmd open ${{
         text/*|application/json|inode/x-empty) $EDITOR $fx;;
 	image/x-xcf) setsid -f gimp $f >/dev/null 2>&1 ;;
 	image/svg+xml) display -- $f ;;
-	image/*) rotdir $f | grep -i "\.\(png\|jpg\|jpeg\|gif\|webp\|tif\|ico\)\(_large\)*$" |
-		setsid -f sxiv -aio 2>/dev/null | while read -r file; do
-			[ -z "$file" ] && continue
-			lf -remote "send select \"$file\""
-			lf -remote "send toggle"
-		done &
+    image/*)
+	    # We use rotdir to make sure the current file is the first one imv shows,
+		# then we pass the rest of the directory's images to imv for scrolling.
+		rotdir "$f" | grep -i "\.\(png\|jpg\|jpeg\|gif\|webp\|tif\|ico\)\(_large\)*$" |
+		xargs -d '\n' setsid -f imv >/dev/null 2>&1 &
 		;;
 	audio/*) mpv --audio-display=no $f ;;
 	video/*) setsid -f mpv $f -quiet >/dev/null 2>&1 ;;
@@ -126,8 +110,14 @@ map <c-e> down
 map <c-y> up
 map V push :!nvim<space>
 
-map t $tesseract -l deu $f - | xclip -selection clipboard
+map t $tesseract -l deu $f - | wl-copy
 
 map W $setsid -f $TERMINAL >/dev/null 2>&1
 
-map Y $printf "%s" "$fx" | xclip -selection clipboard
+map Y $printf "%s" "$fx" | wl-copy
+
+# Force a redraw to clear Kitty images when moving selection
+# cmd on-select &{{
+    # kitten icat --clear --stdin no > /dev/tty
+    # lf -remote "send $id redraw"
+# }}

+ 33 - 36
dot-config/lf/scope

@@ -3,44 +3,41 @@
 # File preview handler for lf.
 
 set -C -f
-IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}"
+IFS="$(printf '%b_' '\n')"
+IFS="${IFS%_}"
 
-image() {
-	if [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && 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" "$5" "$(($2-1))" "$(($3-1))" "$1" > "$FIFO_UEBERZUG"
-	else
-		mediainfo "$1"
-	fi
+# Define the draw function using Kitty's native protocol
+draw() {
+    # $1=path, $2=width, $3=height, $4=x, $5=y
+    # Mapping: width(2) x height(3) @ x(4) x y(5)
+    kitten icat --stdin no --transfer-mode memory --place "${2}x${3}@${4}x${5}" "$1" </dev/null >/dev/tty
+    exit 1 # this prevents lf from caching the image (which Kitty doesn't need)
 }
 
-ifub() {
-	[ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && command -V ueberzug >/dev/null 2>&1
-}
-
-# Note that the cache file name is a function of file information, meaning if
-# an image appears in multiple places across the machine, it will not have to
-# be regenerated once seen.
-
 case "$(file --dereference --brief --mime-type -- "$1")" in
-	image/*) image "$1" "$2" "$3" "$4" "$5" ;;
-	text/html) lynx -width="$4" -display_charset=utf-8 -dump "$1" ;;
-	text/troff) man ./ "$1" | col -b ;;
-	text/* | */xml | application/json) bat --terminal-width "$4" -f "$1" ;;
-	application/zip) zipinfo -2htz "$1" ;;
-    application/vnd*) pptx2text -v "$1" ;;
-	#application/zip) atool --list -- "$1" ;;
-        audio/* | application/octet-stream) mediainfo "$1" || exit 1 ;;
-	video/* )
-		CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
-		[ ! -f "$CACHE" ] && ffmpegthumbnailer -i "$1" -o "$CACHE" -s 0
-		image "$CACHE" "$2" "$3" "$4" "$5"
-		;;
-        */pdf)
-		CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
-		[ ! -f "$CACHE.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"
-		image "$CACHE.jpg" "$2" "$3" "$4" "$5"
-		;;
-        *opendocument*) odt2txt "$1" ;;
-	application/pgp-encrypted) gpg -d -- "$1" ;;
+image/*) draw "$1" "$2" "$3" "$4" "$5" ;;
+text/html) lynx -width="$4" -display_charset=utf-8 -dump "$1" ;;
+text/troff) man ./ "$1" | col -b ;;
+text/* | */xml | application/json) bat --terminal-width "$4" -f "$1" ;;
+application/zip) zipinfo -2htz "$1" ;;
+application/vnd*) pptx2text -v "$1" ;;
+    #application/zip) atool --list -- "$1" ;;
+audio/* | application/octet-stream) mediainfo "$1" || exit 1 ;;
+video/*)
+    CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
+    [ ! -f "$CACHE" ] && ffmpegthumbnailer -i "$1" -o "$CACHE" -s 0
+    draw "$CACHE" "$2" "$3" "$4" "$5"
+    ;;
+*/pdf)
+    CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
+    [ ! -f "$CACHE.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"
+    draw "$CACHE.jpg" "$2" "$3" "$4" "$5"
+    ;;
+*opendocument*) odt2txt "$1" ;;
+application/pgp-encrypted) gpg -d -- "$1" ;;
+*)
+    # Default text preview for other files
+    bat --color=always --style=plain "$1" || cat "$1"
+    ;;
 esac
-exit 1
+exit 0