Skip to content

Commit ec88e43

Browse files
authored
Merge pull request #3 from fowlerro/main
Add option to copy selected color without opening window
2 parents 65f6d1c + fc15f13 commit ec88e43

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ A script that provides a working color picker for wayland and wlroots
44
by leveraging [grim](https://github.com/emersion/grim) and
55
[slurp](https://github.com/emersion/slurp).
66

7+
## Usage
8+
- Command `wl-color-picker` - Select position on screen and open color picker window
9+
- Command `wl-color-picker clipboard` - Select position on screen without opening color picker window, just copy selected color to clipboard
10+
11+
712
## Inspiration
813

914
This script is possible by the information provided on the following

wl-color-picker.sh

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,24 @@ else
4545
)
4646
fi
4747

48-
# Display a color picker and store the returned rgb color
49-
rgb_color=$(zenity --color-selection \
50-
--title="Copy color to Clipboard" \
51-
--color="${color}"
52-
)
48+
if [ "$1" == "clipboard" ]; then
49+
echo $color | wl-copy -n
50+
else
51+
# Display a color picker and store the returned rgb color
52+
rgb_color=$(zenity --color-selection \
53+
--title="Copy color to Clipboard" \
54+
--color="${color}"
55+
)
5356

54-
# Execute if user didn't click cancel
55-
if [ "$rgb_color" != "" ]; then
56-
# Convert rgb color to hex
57-
hex_color="#"
58-
for value in $(echo "${rgb_color}" | grep -E -o -m1 '[0-9]+'); do
59-
hex_color="$hex_color$(printf "%.2x" $value)"
60-
done
57+
# Execute if user didn't click cancel
58+
if [ "$rgb_color" != "" ]; then
59+
# Convert rgb color to hex
60+
hex_color="#"
61+
for value in $(echo "${rgb_color}" | grep -E -o -m1 '[0-9]+'); do
62+
hex_color="$hex_color$(printf "%.2x" $value)"
63+
done
6164

62-
# Copy user selection to clipboard
63-
echo $hex_color | wl-copy -n
65+
# Copy user selection to clipboard
66+
echo $hex_color | wl-copy -n
67+
fi
6468
fi

0 commit comments

Comments
 (0)