From f4c4550e327d9090c82a735d39d104d0bedb602d Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sun, 30 Mar 2025 01:00:51 -0400 Subject: Loads of laptop shit --- .config/lf/kitty.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 .config/lf/kitty.sh (limited to '.config/lf/kitty.sh') diff --git a/.config/lf/kitty.sh b/.config/lf/kitty.sh new file mode 100755 index 0000000..fa84b3f --- /dev/null +++ b/.config/lf/kitty.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Transmits an image in png format via file-mode transmission. +# $1 file path +# $2 image id +transmit_file_png() { + abspath_b64="$(printf -- "$(realpath -- "$1")" | base64 -w0)" + printf "\e_Gt=f,i=$2,f=100,q=1;$abspath_b64\e\\" >/dev/tty +} + +# Displays an already transferred image. +# $1 image id +# $2 placement id +# $3 x, $4 y, $5 w, $6 h +display_img() { + printf "\e[s" >/dev/tty # save cursor position + tput cup $4 $3 >/dev/tty # move cursor + printf "\e_Ga=p,i=$1,p=$2,q=1\e\\" >/dev/tty + printf "\e[u" >/dev/tty # restore cursor position +} + +# Deletes a displayed image. +# $1 image id +# $2 placement id +delete_img() { + printf "\e_Ga=d,d=I,i=$1,p=$2,q=1\e\\" >/dev/tty +} + +# Combines transmit_file_png and display_img. +# $1 file path +# $2 image id +# $3 placement id +# $4 x, $5 y, $6 w, $7 h +show() { + local img_width img_height new_width new_height + img_width=$(identify -format "%w" "$1") + img_height=$(identify -format "%h" "$1") + new_width=$6 + new_height=$7 + transmit_file_png "$1" "$2" + display_img "$2" "$3" "$4" "$5" "$new_width" "$new_height" +} + +"$@" -- cgit v1.2.3