#!/usr/bin/env bash
#
# shows images, scaled to terminal dimensions, via kitty's icat.
# designed for image-feeds like xkcd.com.
# by Timm Heuss (https://github.com/heussd/) - CC-BY 4.0 
#
# usage:
# 1) define a new macro in your config:
#    macro i set pager "$PATHTOTHIS/kitty-img-pager"; open; set pager internal
# 2) now you use this pager in articleview using the hotkey <comma>+<i>

set -o errexit
set -o nounset

image=$(grep -E -o "https?://[a-zA-Z0-9./?=_%:-]*" <"${1}" | tail -n 1)

# detect terminal dimensions
# cols="${COLUMNS:-$(tput cols)}"
# lines="${LINES:-$(tput lines)}"
# dims="${cols}x${lines}@0x0"
dims="$(tput cols)x$(tput lines)@0x0"

clear
kitty +kitten icat --clear
kitty +kitten icat --hold --scale-up --place "$dims" "$image"
clear
