♻️ Refactored 3 letter arg clause
This commit is contained in:
parent
f73517e9b1
commit
d3526ce24e
1 changed files with 25 additions and 1 deletions
26
scripts/dye
26
scripts/dye
|
|
@ -49,7 +49,23 @@ hex_to_rgb() {
|
||||||
a=1.0
|
a=1.0
|
||||||
# else if hex value is 3 characters (minimal hex value provided)
|
# else if hex value is 3 characters (minimal hex value provided)
|
||||||
elif ((${#_} == 3)); then
|
elif ((${#_} == 3)); then
|
||||||
((r = 16#${_:0:1}, g = 16#${_:1:1}, b = 16#${_:2:1}))
|
# if the first character still has a hashtag in it...
|
||||||
|
if [[ ${1:0:1} != "#" ]]; then
|
||||||
|
color="#$1"
|
||||||
|
else
|
||||||
|
color="$1"
|
||||||
|
fi
|
||||||
|
# grab out each passed value
|
||||||
|
r="$(echo "$color" | cut -c2)"
|
||||||
|
g="$(echo "$color" | cut -c3)"
|
||||||
|
b="$(echo "$color" | cut -c4)"
|
||||||
|
|
||||||
|
# and convert them to hexadecimal
|
||||||
|
r=$(printf "%d" 0x$r$r)
|
||||||
|
g=$(printf "%d" 0x$g$g)
|
||||||
|
b=$(printf "%d" 0x$b$b)
|
||||||
|
|
||||||
|
# ((r = 16#${_:0:1}, g = 16#${_:1:1}, b = 16#${_:2:1}))
|
||||||
a=1.0
|
a=1.0
|
||||||
else
|
else
|
||||||
error "$1 is not a recognized hex color code."
|
error "$1 is not a recognized hex color code."
|
||||||
|
|
@ -57,6 +73,12 @@ hex_to_rgb() {
|
||||||
printf "%s\n" "rgba($r, $g, $b, $a)"
|
printf "%s\n" "rgba($r, $g, $b, $a)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# parse_rgb() takes rgb string to extract
|
||||||
|
# numeric values from it and then pass that to rgb_to_hex()
|
||||||
|
# parse_rgb() {
|
||||||
|
#
|
||||||
|
# }
|
||||||
|
|
||||||
rgb_to_hex() {
|
rgb_to_hex() {
|
||||||
local a
|
local a
|
||||||
# if a fourth arg is provided (alpha channel)
|
# if a fourth arg is provided (alpha channel)
|
||||||
|
|
@ -91,6 +113,8 @@ main() {
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
r)
|
r)
|
||||||
|
# parse an 'rgb()' or 'rgba' string here
|
||||||
|
# regex compare to string
|
||||||
if [[ "$#" -gt 5 ]]; then
|
if [[ "$#" -gt 5 ]]; then
|
||||||
error "-r parses up to four following argument"
|
error "-r parses up to four following argument"
|
||||||
exit 2
|
exit 2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue