| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | source "$(dirname "$0")/_lib.sh" |
| 4 | point=$(slurp -p -b '#00000000') || exit 0 |
| 5 | |
| 6 | if has magick; then conv=(magick); elif has convert; then conv=(convert) |
| 7 | else notify color dialog-error "Colour picker" "Install imagemagick"; exit 1; fi |
| 8 | |
| 9 | hex=$(grim -g "$point" -t ppm - | "${conv[@]}" - -format '%[hex:p{0,0}]' info:- | cut -c1-6) |
| 10 | [[ -n $hex ]] || exit 1 |
| 11 | printf '#%s' "$hex" | wl-copy |
| 12 | |
| 13 | |
| 14 | swatch="${XDG_RUNTIME_DIR:-/tmp}/color-$hex.png" |
| 15 | "${conv[@]}" -size 64x64 "xc:#$hex" "$swatch" 2>/dev/null |
| 16 | notify color "$swatch" "#$hex" "Copied to clipboard" |