1
0
forked from extern/nix-config
donovanglover-nix-config/terminal/joshuto/kitty-show.sh
Donovan Glover d8914cb4d2
meta: Switch from ranger to joshuto
Joshuto is *significantly* faster than ranger and is written in Rust
instead of Python. Although both ranger and joshuto have not seen a new
release in a while, the future of joshuto seems more promising.

Joshuto is additionally faster than lf and, similar to lf, does not hang
when previewing images with kitty.
2023-05-27 16:45:05 -04:00

33 lines
858 B
Bash
Executable File

#!/usr/bin/env bash
FILE_PATH="$1" # Full path of the previewed file
PREVIEW_X_COORD="$2" # x coordinate of upper left cell of preview area
PREVIEW_Y_COORD="$3" # y coordinate of upper left cell of preview area
PREVIEW_WIDTH="$4" # Width of the preview pane (number of fitting characters)
PREVIEW_HEIGHT="$5" # Height of the preview pane (number of fitting characters)
TMP_FILE="$HOME/.cache/joshuto/thumbcache.png"
mimetype=$(file --mime-type -Lb "$FILE_PATH")
function image {
kitty +kitten icat \
--transfer-mode=file \
--clear 2>/dev/null
kitty +kitten icat \
--transfer-mode=file \
--place "${PREVIEW_WIDTH}x${PREVIEW_HEIGHT}@${PREVIEW_X_COORD}x${PREVIEW_Y_COORD}" \
"$1" 2>/dev/null
}
case "$mimetype" in
image/*)
image "${FILE_PATH}"
;;
*)
kitty +kitten icat \
--transfer-mode=file \
--clear 2>/dev/null
;;
esac