diff --git a/prev/ueberzug.sh b/prev/ueberzug.sh index a221ed5..425b9bb 100644 --- a/prev/ueberzug.sh +++ b/prev/ueberzug.sh @@ -3,5 +3,3 @@ setup_fifo send_image "$f" - -exit 1 diff --git a/sh/clear.sh b/sh/clear.sh index 1db0456..b493694 100644 --- a/sh/clear.sh +++ b/sh/clear.sh @@ -1,3 +1,7 @@ setup_fifo 1 -printf '{"action": "remove", "identifier": "preview"}\n' > "$fifo" +if use_ueberzug; then + printf '{"action": "remove", "identifier": "preview"}\n' > "$fifo" +elif use_kitty; then + kitty +kitten icat --clear --transfer-mode file +fi diff --git a/sh/end.sh b/sh/end.sh index 1f893d3..6e10a84 100644 --- a/sh/end.sh +++ b/sh/end.sh @@ -1,4 +1,4 @@ setup_fifo 1 # tell ctpv server to exit -printf '\0' > "$fifo" +use_ueberzug && printf '\0' > "$fifo" diff --git a/sh/helpers.sh b/sh/helpers.sh index 70c1061..234a01a 100644 --- a/sh/helpers.sh +++ b/sh/helpers.sh @@ -2,6 +2,19 @@ echo_err() { echo "$@" >&2 } +is_kitty() { + [ -n "$KITTY_PID" ] +} + +use_ueberzug() { + exists ueberzug +} + +use_kitty() { + use_ueberzug && return 1 + is_kitty +} + fifo_open() { # https://unix.stackexchange.com/a/522940/183147 dd oflag=nonblock conv=notrunc,nocreat count=0 of="$1" \ @@ -9,6 +22,8 @@ fifo_open() { } setup_fifo() { + use_ueberzug || return 1 + exit_code="${1:-127}" [ -n "$fifo" ] || exit "$exit_code" [ -e "$fifo" ] || exit "$exit_code" @@ -24,9 +39,17 @@ check_exists() { } send_image() { - path="$(printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g')" - printf '{ "action": "add", "identifier": "preview", "x": %d, "y": %d, "width": %d, "height": %d, "scaler": "contain", "scaling_position_x": 0.5, "scaling_position_y": 0.5, "path": "%s"}\n' "$x" "$y" "$w" "$h" "$path" > "$fifo" - return 1 + if use_kitty; then + kitty +kitten icat --transfer-mode file --align left \ + --place "${w}x${h}@${x}x${y}" "$1" + return 1 + elif use_ueberzug; then + path="$(printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g')" + printf '{ "action": "add", "identifier": "preview", "x": %d, "y": %d, "width": %d, "height": %d, "scaler": "contain", "scaling_position_x": 0.5, "scaling_position_y": 0.5, "path": "%s"}\n' "$x" "$y" "$w" "$h" "$path" > "$fifo" + return 1 + else + return 127 + fi } convert_and_show_image() {