Skip to content

Commit

Permalink
Merge pull request #3 from fowlerro/main
Browse files Browse the repository at this point in the history
Add option to copy selected color without opening window
  • Loading branch information
jgmdev authored Jan 11, 2022
2 parents 65f6d1c + fc15f13 commit ec88e43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ A script that provides a working color picker for wayland and wlroots
by leveraging [grim](https://github.com/emersion/grim) and
[slurp](https://github.com/emersion/slurp).

## Usage
- Command `wl-color-picker` - Select position on screen and open color picker window
- Command `wl-color-picker clipboard` - Select position on screen without opening color picker window, just copy selected color to clipboard


## Inspiration

This script is possible by the information provided on the following
Expand Down
32 changes: 18 additions & 14 deletions wl-color-picker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,24 @@ else
)
fi

# Display a color picker and store the returned rgb color
rgb_color=$(zenity --color-selection \
--title="Copy color to Clipboard" \
--color="${color}"
)
if [ "$1" == "clipboard" ]; then
echo $color | wl-copy -n
else
# Display a color picker and store the returned rgb color
rgb_color=$(zenity --color-selection \
--title="Copy color to Clipboard" \
--color="${color}"
)

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

# Copy user selection to clipboard
echo $hex_color | wl-copy -n
# Copy user selection to clipboard
echo $hex_color | wl-copy -n
fi
fi

0 comments on commit ec88e43

Please sign in to comment.