From efd336adf26d51997d2815aac60e093478baf602 Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Mon, 10 May 2021 11:03:32 +0800 Subject: [PATCH] bash: add function to cat image with sixel with max size of estimated printable size without scrolling --- .bashrc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.bashrc b/.bashrc index 179b106..fde10ff 100644 --- a/.bashrc +++ b/.bashrc @@ -118,6 +118,17 @@ sleepto() { sleep $(($(date --date="$1" +%s) - $(date +%s))) } +imgcat_max_pixels() { + TREE=$(swaymsg -t get_tree) + SCALE=$(echo "$TREE" | jq 'getpath(path(.nodes[]|..|select(.focused? == true))[0:2]).scale') + SIZE=$(echo "$TREE" | jq '.nodes[]|..|select(.focused? == true).window_rect|.width,.height') + echo $(($SCALE * $(echo "$SIZE" | head -n 1)))x$(($SCALE * $(($(echo "$SIZE" | tail -n 1) - 20)))) +} + +imgcat() { + convert $@ -resize $(imgcat_max_pixels)\> sixel:- +} + # application envs # policy: should here even if global like /etc/environments export GPG_TTY=$(tty) -- 2.45.2