summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2020-12-03 12:48:53 +0100
committerRobert Günzler <r@gnzler.io>2020-12-03 12:48:53 +0100
commit01d7525db223e303d14d1ab42b97ba584ad7cea8 (patch)
treefc6cb575d21e54ef0ea3eec3de76aa3419874ff0 /bin
parent60b1a627c8e0dbd6aa8e83f17467c72fb262e5bb (diff)
bin/colorpick: preview color
Diffstat (limited to 'bin')
-rwxr-xr-xbin/colorpick35
1 files changed, 22 insertions, 13 deletions
diff --git a/bin/colorpick b/bin/colorpick
index af2807f..8561129 100755
--- a/bin/colorpick
+++ b/bin/colorpick
@@ -1,15 +1,24 @@
 #!/bin/sh
-# dependencies: grim slurp wl-clipboard
+
+set -e
+[ -n "$DEBUG" ] && set -x
+
+# check requirements
+for tool in convert grim slurp wl-copy; do
+	if ! command -v "$tool" >/dev/null; then
+		printf "%s: %s not installed but required\n" "$(basename "$0")" "$tool" >&2
+		exit 1
+	fi
+done
+
 # src: https://git.sr.ht/~sircmpwn/dotfiles/tree/f9e7e88a72c2b87e5ab823205cb3a3aa8f3babd0/bin/colorpick
-notify-send \
-	--icon '/usr/share/icons/Adwaita/scalable/actions/color-select-symbolic.svg' \
-	"Pick a color"
-
-(
-	color=$(grim -g "$(slurp -p -b 00000000)" - | convert - txt:- | awk 'END{print $3}')
-	wl-copy "$color"
-)
-
-notify-send \
-	--icon '/usr/share/icons/Adwaita/scalable/actions/color-select-symbolic.svg' \
-	"Color copied to clipboard" "$color"
+
+notify-send "pick a color"
+
+color=$(grim -g "$(slurp -p -b 00000000)" - | convert - txt:- | awk 'END{print $3}')
+icn=$(mktemp).png
+trap '{ rm $icn; }' EXIT
+convert -size '30x30' xc:white -fill "$color" -draw "rectangle 0,0 30,30" "$icn"
+wl-copy "$color"
+
+notify-send -i "$icn" "color copied to clipboard" "$color"