#!/usr/bin/env bash

# Selects the region, echoes the hex string (in RGBA format) of the average color of the region.

# Depedencies:
# * maim v5.6.3
# * ImageMagick 7.0.10

# It's a small script and the main code is a chain of commands so a pipeline fail is appropriate here.
set -o pipefail

# Make some form of user feedback.
notify-send "Select a region for color picking."

# The color picker code.
# Take note it uses a slop shader named `crosshair` from the shader examples of the official repo at https://github.com/naelstrof/slop.
maim --select --shader crosshair --tolerance 0 --hidecursor | magick convert - -resize 1x1\! -format '%[hex:p{0,0}]' info:-