mabox-colorizer/bin/mbclr

274 lines
12 KiB
Plaintext
Raw Normal View History

2022-05-15 03:25:01 +02:00
#!/bin/bash
#
# colorizer - set of tools for Mabox (auto)theming
# Copyright (C) 2022-2023 Daniel Napora <napcok@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2022-05-15 03:25:01 +02:00
# mbclr current polecenie funkcja argument backprg [config_file]
# mbclr
2022-10-15 12:19:57 +02:00
#notify-send.sh "mbclr" "${1}\n${2}\n${3}\n${4}\n${5}\n${6}"
2022-08-15 01:42:52 +02:00
case "$LANG" in
pl*)
SELECT_COLOR="Wybierz kolor"
PICK_FROM_SCREEN="Pobierz kolor z ekranu"
SELECT_OR_PICK="Wybierz kolor z selektora"
OPACITY="Nieprzezroczystość"
2023-04-22 20:49:26 +02:00
SHADES_OF_CURRENT="Oblicz z bieżącego"
SHADES_OF="Odcienie"
2023-05-10 23:50:21 +02:00
LIGHTEN_DARKEN="Jaśniejsze / Ciemniejsze"
2023-04-22 20:49:26 +02:00
SATURATION="Nasycenie..."
ROTATE_HSL_HUE="Obróć kanał barwy HSL..."
2023-05-10 23:50:21 +02:00
CURRENT="obecny kolor"
2022-08-15 01:42:52 +02:00
WALLPAPER_COLORS="Kolory z tapety"
ACCENT_COLORS="Popularne kolory akcentu"
LIGHTCOLORS="Jasne kolory..."
DARKCOLORS="Ciemne kolory..."
2023-05-10 23:50:21 +02:00
2022-08-15 01:42:52 +02:00
;;
*)
SELECT_COLOR="Select color"
PICK_FROM_SCREEN="Pick color from screen"
SELECT_OR_PICK="Select or pick from screen"
OPACITY="Opacity"
2023-04-22 20:49:26 +02:00
SHADES_OF_CURRENT="Calculate from current"
SHADES_OF="Shades of"
2023-05-10 23:50:21 +02:00
LIGHTEN_DARKEN="Lighten / Darken"
2023-04-22 20:49:26 +02:00
SATURATION="Saturation..."
ROTATE_HSL_HUE="Rotate HSL hue channel..."
2023-05-10 23:50:21 +02:00
CURRENT="current color"
2022-08-15 01:42:52 +02:00
WALLPAPER_COLORS="Wallpaper colors"
ACCENT_COLORS="Popular accent colors"
LIGHTCOLORS="Light colors..."
DARKCOLORS="Dark colors..."
;;
esac
2022-05-15 03:25:01 +02:00
main () {
#read WALLPAPER<<< $(grep file "$HOME"/.config/nitrogen/bg-saved.cfg | cut -d'=' -f2)
WALLPALDIR="$HOME/.cache/colorizer/palettes"
2022-05-15 03:25:01 +02:00
mkdir -p "$WALLPALDIR"
read WALLPATH<<< $(grep file "$HOME"/.config/nitrogen/bg-saved.cfg | cut -d'=' -f2)
NAME=${WALLPATH////_}
if [[ "${NAME}" =~ ^_home_.* ]]; then
n=${#HOME}
((n++))
NAME=${NAME:${n}}
fi
if [ ! -f "$WALLPALDIR/$NAME.clr" ]; then
convert ${WALLPATH} -resize 25% -colors 16 -unique-colors txt:- |grep -v '^#'| awk '{print substr($3,1,7)}' |pastel sort-by brightness |pastel format hex > "$WALLPALDIR/$NAME.clr"
2022-05-15 03:25:01 +02:00
fi
mapfile -t wallcolors < "$WALLPALDIR/$NAME.clr"
2022-08-15 01:42:52 +02:00
if [[ "${#wallcolors[@]}" -lt 8 ]]; then
wallcolors+=("#2e3440" "#4c566a" "#5e81ac" "#bf616b" "#b48ead" "#a3be8c" "#ebcb8b" "#d8dee9" "#eceff4")
fi
2022-05-15 03:25:01 +02:00
dark=("#000000" "#111111" "#222222" "#333333" "#444444" "#555555" "#666666")
light=("#FFFFFF" "#EEEEEE" "#DDDDDD" "#CCCCCC" "#BBBBBB" "#AAAAAA" "#999999")
2023-07-25 00:21:05 +02:00
accents=("#e93d57" "#c7162b" "#e9633a" "#e95620" "#f4a300" "#e8cc2d" "#3cd425" "#0e8420" "#00d3b7" "#18b0b0" "#3dade9" "#686b6f" "#3584e4" "#916ee4" "#b875dc" "#77216e" "#c748ba" "#e93a9a")
2022-05-15 03:25:01 +02:00
out+=("^sep($4)")
if [[ "$2" == "jgctl" ]]; then
. $HOME/.config/mabox/mabox.conf
case "$jgmenu_theme" in
obtheme)
OBTHEME=$(awk '/<theme>/ {while (getline n) {if (match(n, /<name>/))
{l=n; exit}}} END {split(l, a, "[<>]"); print a[3]}' "$HOME/.config/openbox/rc.xml");
THEMERC="$HOME/.config/mabox/jgobthemes/${OBTHEME}.colorrc";;
*)
THEMERC="$HOME/.config/mabox/jgobthemes/${jgmenu_theme}.colorrc";;
esac
read COLOR OP<<< $(grep "${3}" ${THEMERC} | cut -d'=' -f2)
2022-08-15 01:42:52 +02:00
out+=("^sep($OPACITY)")
2022-08-27 16:36:46 +02:00
out+=("$OPACITY <small>[ <b>$OP</b> ]</small>,^checkout(opacity)")
2022-05-15 03:25:01 +02:00
out2+=("^tag(opacity)")
2022-08-15 01:42:52 +02:00
out2+=("^sep($OPACITY <small>[ $OP ]</small>")
2022-09-19 20:59:26 +02:00
out2+=("<tt><small>100</small> <span bgcolor='$1' bgalpha='100%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 100;${5}")
out2+=("<tt><small> 95</small> <span bgcolor='$1' bgalpha='95%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 95 ;${5}")
out2+=("<tt><small> 90</small> <span bgcolor='$1' bgalpha='90%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 90 ;${5}")
out2+=("<tt><small> 80</small> <span bgcolor='$1' bgalpha='80%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 80 ;${5}")
out2+=("<tt><small> 70</small> <span bgcolor='$1' bgalpha='70%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 70 ;${5}")
out2+=("<tt><small> 60</small> <span bgcolor='$1' bgalpha='60%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 60 ;${5}")
out2+=("<tt><small> 50</small> <span bgcolor='$1' bgalpha='50%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 50 ;${5}")
out2+=("<tt><small> 40</small> <span bgcolor='$1' bgalpha='40%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 40 ;${5}")
out2+=("<tt><small> 30</small> <span bgcolor='$1' bgalpha='30%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 30 ;${5}")
out2+=("<tt><small> 20</small> <span bgcolor='$1' bgalpha='20%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 20 ;${5}")
out2+=("<tt><small> 10</small> <span bgcolor='$1' bgalpha='10%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 10 ;${5}")
out2+=("<tt><small> 5</small> <span bgcolor='$1' bgalpha='5%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 5 ;${5}")
out2+=("<tt><small> 0</small> <span bgcolor='$1' bgalpha='1%'> </span><span bgcolor='$1'> </span></tt>,jgctl $3 0 ;${5}")
2022-05-15 03:25:01 +02:00
fi
2023-07-25 00:21:05 +02:00
if [[ "$2" == "t2ctl" ]]; then
T2RC="$HOME/.config/tint2/jaskier_mb.tint2rc"
read COLOR OP<<< $(grep "${3}" ${T2RC} | cut -d'=' -f2)
out+=("^sep($OPACITY)")
out+=("$OPACITY <small>[ <b>$OP</b> ]</small>,^checkout(opacity)")
out2+=("^tag(opacity)")
out2+=("^sep($OPACITY <small>[ $OP ]</small>")
out2+=("<tt><small>100</small> <span bgcolor='$1' bgalpha='100%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 100;${5}")
out2+=("<tt><small> 95</small> <span bgcolor='$1' bgalpha='95%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 95 ;${5}")
out2+=("<tt><small> 90</small> <span bgcolor='$1' bgalpha='90%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 90 ;${5}")
out2+=("<tt><small> 80</small> <span bgcolor='$1' bgalpha='80%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 80 ;${5}")
out2+=("<tt><small> 70</small> <span bgcolor='$1' bgalpha='70%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 70 ;${5}")
out2+=("<tt><small> 60</small> <span bgcolor='$1' bgalpha='60%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 60 ;${5}")
out2+=("<tt><small> 50</small> <span bgcolor='$1' bgalpha='50%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 50 ;${5}")
out2+=("<tt><small> 40</small> <span bgcolor='$1' bgalpha='40%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 40 ;${5}")
out2+=("<tt><small> 30</small> <span bgcolor='$1' bgalpha='30%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 30 ;${5}")
out2+=("<tt><small> 20</small> <span bgcolor='$1' bgalpha='20%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 20 ;${5}")
out2+=("<tt><small> 10</small> <span bgcolor='$1' bgalpha='10%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 10 ;${5}")
out2+=("<tt><small> 5</small> <span bgcolor='$1' bgalpha='5%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 5 ;${5}")
out2+=("<tt><small> 0</small> <span bgcolor='$1' bgalpha='1%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 0 ;${5}")
fi
2022-05-15 03:25:01 +02:00
#Current
2022-08-15 01:42:52 +02:00
out+=("^sep($SELECT_COLOR)")
2022-12-19 22:22:23 +01:00
out+=(" $PICK_FROM_SCREEN,mbclr pixelcolor $2 $3 ${5} ${6}")
out+=(" $SELECT_OR_PICK,mbclr pick $2 $3 ${5} ${6}")
2023-05-10 23:50:21 +02:00
CUR_FG=$(pastel textcolor $1|pastel format hex)
2023-07-25 00:21:05 +02:00
out+=("^sep($SHADES_OF_CURRENT <tt><span bgcolor='$1' fgcolor='$CUR_FG'>$1</span></tt>)")
2023-05-10 23:50:21 +02:00
out+=("$LIGHTEN_DARKEN,^checkout(curshades)")
out+=("$SATURATION,^checkout(saturate)")
2023-09-08 12:34:28 +02:00
out+=("<big>󰑧</big> $ROTATE_HSL_HUE,^checkout(rotate_hsl)")
2023-05-10 23:50:21 +02:00
#out+=("$SHADES_OF_CURRENT <tt><span bgcolor='$1'> </span></tt> (<small>$1</small>),^checkout(curshades)")
2022-08-15 01:42:52 +02:00
out+=("^sep()")
2023-09-08 12:34:28 +02:00
out+=("<big><span bgcolor='#e93d57'> </span> <span bgcolor='#f4a300'> </span> <span bgcolor='#3cd425'> </span> <span bgcolor='#3584e4'> </span> <span bgcolor='#e93a9a'> </span></big> $ACCENT_COLORS,^checkout(accents)")
2022-08-15 01:42:52 +02:00
out2+=("^tag(accents)")
2023-07-25 00:21:05 +02:00
out2+=("^sep($ACCENT_COLORS)")
for i in ${accents[@]};do out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,$2 $3 '${i}' ${6};${5}");done
2022-05-15 03:25:01 +02:00
out+=("^sep()")
2022-08-27 16:36:46 +02:00
out+=("<tt><span bgcolor='#DDDDDD'> </span></tt> $LIGHTCOLORS,^checkout(light)")
2022-05-15 03:25:01 +02:00
out2+=("^tag(light)")
2022-08-15 01:42:52 +02:00
out2+=("^sep($LIGHTCOLORS)")
2022-05-15 03:25:01 +02:00
for i in "${light[@]}"
do
2022-09-19 20:59:26 +02:00
out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,$2 $3 '${i}' ${6};${5}")
2022-05-15 03:25:01 +02:00
done
out+=("^sep()")
2022-08-27 16:36:46 +02:00
out+=("<tt><span bgcolor='#222222'> </span></tt> $DARKCOLORS,^checkout(dark)")
2022-05-15 03:25:01 +02:00
out2+=("^tag(dark)")
2022-08-15 01:42:52 +02:00
out2+=("^sep($DARKCOLORS)")
2022-05-15 03:25:01 +02:00
for i in "${dark[@]}"
do
2022-09-19 20:59:26 +02:00
out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,$2 $3 '${i}' ${6};${5}")
2022-05-15 03:25:01 +02:00
done
2023-07-25 00:21:05 +02:00
out+=("^sep($WALLPAPER_COLORS)")
for i in "${wallcolors[@]}"
do
out+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,$2 $3 '${i}' ${6};${5}")
done
2023-05-10 23:50:21 +02:00
# Shades
2022-05-15 03:25:01 +02:00
out2+=("^tag(curshades)")
2022-08-15 01:42:52 +02:00
out2+=("^sep($SHADES_OF $1)")
2022-05-15 03:25:01 +02:00
for i in 3 25 2 15 1 05; do
clr=$(pastel lighten 0.$i "${1}" | pastel format hex)
if [ "${clr}" != "#ffffff" ];then
2023-05-10 23:50:21 +02:00
out2+=("<tt><small>$clr</small> <span bgcolor='$clr'> </span></tt>,$2 $3 '${clr}' ${6};${5}")
2022-05-15 03:25:01 +02:00
fi
done
out2+=("^sep()")
2023-05-10 23:50:21 +02:00
out2+=("<tt><span bgcolor='$1' fgcolor='$CUR_FG'> <small>$CURRENT $1</small> </span></tt>,$2 $3 '${1}' ${6};${5}")
2022-05-15 03:25:01 +02:00
out2+=("^sep()")
for i in 05 1 15 2 25 3; do
clr=$(pastel darken 0.$i "${1}" | pastel format hex)
if [ "${clr}" != "#000000" ];then
2023-05-10 23:50:21 +02:00
out2+=("<tt><small>$clr</small> <span bgcolor='$clr'> </span></tt>,$2 $3 '${clr}' ${6};${5}")
2022-05-15 03:25:01 +02:00
fi
done
2023-05-10 23:50:21 +02:00
# Shades ENG
2022-05-15 03:25:01 +02:00
2023-05-10 23:50:21 +02:00
# SATURATION
out2+=("^tag(saturate)")
2023-04-22 20:49:26 +02:00
out2+=("^sep($SATURATION)")
for i in 9 8 7 6 5 4 3 2 1; do
clr=$(pastel desaturate 0.$i "${1}" | pastel format hex)
if [ "${clr}" != "${oldclr}" ];then
out2+=("<tt><small>$clr</small> <span bgcolor='$clr'> </span></tt>,$2 $3 '${clr}' ${6};${5}")
oldclr=${clr}
fi
done
2023-05-10 23:50:21 +02:00
out2+=("^sep()")
out2+=("<tt><span bgcolor='$1' fgcolor='$CUR_FG'> <small>$CURRENT $1</small> </span></tt>,$2 $3 '${1}' ${6};${5}")
out2+=("^sep()")
for i in 1 2 3 4 5 6 7 8 9; do
clr=$(pastel saturate 0.$i "${1}" | pastel format hex)
2023-04-22 20:49:26 +02:00
if [ "${clr}" != "${oldclr}" ];then
out2+=("<tt><small>$clr</small> <span bgcolor='$clr'> </span></tt>,$2 $3 '${clr}' ${6};${5}")
2023-04-22 20:49:26 +02:00
oldclr=${clr}
fi
done
2023-05-10 23:50:21 +02:00
# SATURATION END
# ROTATE HSL
out2+=("^tag(rotate_hsl)")
2023-04-22 20:49:26 +02:00
out2+=("^sep($ROTATE_HSL_HUE)")
for i in {135..15..15};do
clr=$(pastel rotate -- -$i "${1}" |pastel format hex)
out2+=("<tt><small>$clr</small> <span bgcolor='$clr'> </span> <small>-$i°</small></tt>,$2 $3 '${clr}' ${6};${5}")
done
2023-05-10 23:50:21 +02:00
out2+=("^sep()")
out2+=("<tt><span bgcolor='$1' fgcolor='$CUR_FG'> <small>$CURRENT $1</small> </span></tt>,$2 $3 '${1}' ${6};${5}")
out2+=("^sep()")
2023-04-22 20:49:26 +02:00
for i in {15..135..15};do
clr=$(pastel rotate $i "${1}" |pastel format hex)
out2+=("<tt><small>$clr</small> <span bgcolor='$clr'> </span> <small>$i°</small></tt>,$2 $3 '${clr}' ${6};${5}")
done
2023-05-10 23:50:21 +02:00
# ROTATE HSL END
2022-05-15 03:25:01 +02:00
printf '%s\n' "${out[@]}"
printf '%s\n' "${out2[@]}"
}
pickcolor () {
#notify-send.sh -t 50000 "From pickcolor" "1: $1\n2: $2\n3: $3\n4: $4\n5: $5\n6: $6"
2022-05-15 03:25:01 +02:00
color=$(gcolor3 2>/dev/null)
if [ "$color" ]; then
mycmd=("$1 $2 '${color}' ${4};${3}")
fi
eval "${mycmd[@]}"
}
pixelcolor() {
picker=${picker:-gpick}
if [ "$picker" == "gpick" ]; then
command="gpick -pso 2>/dev/null"
else
command="xcolor --preview-size ${size} --scale ${scale}"
fi
color="$(${command})"
if [ -n "${color}" ]; then
mycmd=("$1 $2 '${color}' ${4};${3}")
2022-05-15 03:25:01 +02:00
fi
eval "${mycmd[@]}"
}
case "$1" in
pick) pickcolor "$2" "${3}" "${4} ${5}" "${6}";;
pixelcolor) pixelcolor "$2" "${3}" "${4} ${5}" "${6}";;
2022-05-15 03:25:01 +02:00
*) main "$@" ;;
esac