shell-scripts/color-picker

39 lines
914 B
Bash
Executable File

#!/bin/sh
# Modification of https://github.com/jgmdev/wl-color-picker
# Check if running under wayland.
if [ "$WAYLAND_DISPLAY" = "" ]; then
echo "Error: No wayland session found."
exit 1
fi
# Get color position
position=$(slurp -b 00000000 -p)
# Sleep at least for a second to prevet issues with grim always
# returning improper color.
#sleep 1
# Store the hex color value using graphicsmagick or imagemagick.
if type gm &> /dev/null; then
color=$(grim -g "$position" -t png - \
| gm convert - -format '%[pixel:p{0,0}]' txt:- \
| tail -n 1 \
| rev \
| cut -d ' ' -f 1 \
| rev
)
else
color=$(grim -g "$position" -t png - \
| convert - -format '%[pixel:p{0,0}]' txt:- \
| tail -n 1 \
| cut -d ' ' -f 4
)
fi
# Display as a notification
if [[ "$(notify-send --action 'click=Copied to clipboard' 'Color Picker' $color)" == "click" ]]; then
# Copy to clipboard
echo $color | wl-copy -n
fi