mabox-colorizer/bin/mbclr

276 lines
12 KiB
Bash
Executable File

#!/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/>.
# mbclr current polecenie funkcja argument backprg [config_file]
# mbclr
#notify-send.sh "mbclr" "${1}\n${2}\n${3}\n${4}\n${5}\n${6}"
case "$LANG" in
pl*)
PICK_FROM_SCREEN="Pobierz kolor z ekranu"
SELECT_OR_PICK="Wybierz kolor z selektora"
OPACITY="Nieprzezroczystość"
SHADES_OF_CURRENT="Oblicz z bieżącego"
SHADES_OF="Odcienie"
LIGHTEN_DARKEN="Jaśniejsze / Ciemniejsze"
SATURATION="Nasycenie..."
ROTATE_HSL_HUE="Obróć kanał barwy HSL..."
CHANGE_COLOR="Zmień na..."
CURRENT="obecny kolor"
WALLPAPER_COLORS="...kolory z tapety"
GTKCOLORS="Kolory motywu GTK"
ACCENT_COLORS="Popularne kolory akcentu"
GRAYS="Odcienie szarości"
;;
*)
PICK_FROM_SCREEN="Pick color from screen"
SELECT_OR_PICK="Select or pick from screen"
OPACITY="Opacity"
SHADES_OF_CURRENT="Calculate from"
SHADES_OF="Shades of"
LIGHTEN_DARKEN="Lighten / Darken"
SATURATION="Saturation..."
ROTATE_HSL_HUE="Rotate HSL hue channel..."
CHANGE_COLOR="Change to..."
CURRENT="current color"
WALLPAPER_COLORS="...wallpaper colors"
GTKCOLORS="GTK theme colors"
ACCENT_COLORS="Popular accent colors"
GRAYS="Shades of Gray"
;;
esac
ccol_ind="<span bgcolor='${1}'> </span>"
gtkthemename=$(grep gtk-theme ~/.config/gtk-3.0/settings.ini |cut -d'=' -f2)
main () {
#read WALLPAPER<<< $(grep file "$HOME"/.config/nitrogen/bg-saved.cfg | cut -d'=' -f2)
WALLPALDIR="$HOME/.cache/colorizer/palettes"
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"
fi
mapfile -t wallcolors < "$WALLPALDIR/$NAME.clr"
if [[ "${#wallcolors[@]}" -lt 8 ]]; then
wallcolors+=("#2e3440" "#4c566a" "#5e81ac" "#bf616b" "#b48ead" "#a3be8c" "#ebcb8b" "#d8dee9" "#eceff4")
fi
grays=("#000000" "#0d0d0d" "#1b1b1b" "#282828" "#363636" "#434343" "#515151" "#5e5e5e" "#6b6b6b" "#797979" "#868686" "#949494" "#a1a1a1" "#aeaeae" "#bcbcbc" "#c9c9c9" "#d7d7d7" "#e4e4e4" "#f2f2f2" "#FFFFFF")
accents=("#e93d57" "#c7162b" "#e9633a" "#e95620" "#f4a300" "#e8cc2d" "#3cd425" "#0e8420" "#00d3b7" "#18b0b0" "#3dade9" "#686b6f" "#3584e4" "#916ee4" "#b875dc" "#77216e" "#c748ba" "#e93a9a")
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)
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>,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}")
fi
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
CUR_FG=$(pastel textcolor $1|pastel format hex)
out+=("^sep($SHADES_OF_CURRENT <tt><span bgcolor='$1' fgcolor='$CUR_FG'>$1</span></tt>)")
out+=("$LIGHTEN_DARKEN,^checkout(curshades)")
out+=("$SATURATION,^checkout(saturate)")
out+=("<big>󰑧</big> $ROTATE_HSL_HUE,^checkout(rotate_hsl)")
#out+=("$SHADES_OF_CURRENT <tt><span bgcolor='$1'> </span></tt> (<small>$1</small>),^checkout(curshades)")
out+=("^sep($CHANGE_COLOR)")
#Current
out+=("<big></big> $PICK_FROM_SCREEN,mbclr pixelcolor $2 $3 ${5} ${6}")
out+=("<big></big> $SELECT_OR_PICK,mbclr pick $2 $3 ${5} ${6}")
out+=("^sep()")
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)")
out2+=("^tag(accents)")
out2+=("^sep($ACCENT_COLORS)")
for i in ${accents[@]};do out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span>${ccol_ind}</tt>,$2 $3 '${i}' ${6};${5}");done
out+=("^sep()")
mapfile -t gtkcolors < <( gtkcolors.py 2>/dev/null| grep -v None|awk '{print "#"$2}'|sort|uniq)
if [ "${#gtkcolors[@]}" -gt 0 ];then
out+=("$GTKCOLORS,^checkout(gtkcols)")
out2+=("^tag(gtkcols)")
out2+=("^sep($GTKCOLORS)")
out2+=("^sep($gtkthemename)")
for i in ${gtkcolors[@]};do out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span>${ccol_ind}</tt>,$2 $3 '${i}' ${6};${5}");done
out+=("^sep()")
fi
out+=("$GRAYS,^checkout(grayscol)")
out2+=("^tag(grayscol)")
out2+=("^sep($GRAYS)")
for i in "${grays[@]}"
do
out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span>${ccol_ind}</tt>,$2 $3 '${i}' ${6};${5}")
done
out+=("^sep($WALLPAPER_COLORS)")
for i in "${wallcolors[@]}"
do
out+=("<tt><small>$i</small> <span bgcolor='$i'> </span>${ccol_ind}</tt>,$2 $3 '${i}' ${6};${5}")
done
# Shades
out2+=("^tag(curshades)")
out2+=("^sep($SHADES_OF $1)")
for i in 3 25 2 15 1 05; do
clr=$(pastel lighten 0.$i "${1}" | pastel format hex)
if [ "${clr}" != "#ffffff" ];then
out2+=("<tt><small>$clr</small> <span bgcolor='$clr'> </span>${ccol_ind}</tt>,$2 $3 '${clr}' ${6};${5}")
fi
done
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 05 1 15 2 25 3; do
clr=$(pastel darken 0.$i "${1}" | pastel format hex)
if [ "${clr}" != "#000000" ];then
out2+=("<tt><small>$clr</small> <span bgcolor='$clr'> </span>${ccol_ind}</tt>,$2 $3 '${clr}' ${6};${5}")
fi
done
# Shades ENG
# SATURATION
out2+=("^tag(saturate)")
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>${ccol_ind}</tt>,$2 $3 '${clr}' ${6};${5}")
oldclr=${clr}
fi
done
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)
if [ "${clr}" != "${oldclr}" ];then
out2+=("<tt><small>$clr</small> <span bgcolor='$clr'> </span>${ccol_ind}</tt>,$2 $3 '${clr}' ${6};${5}")
oldclr=${clr}
fi
done
# SATURATION END
# ROTATE HSL
out2+=("^tag(rotate_hsl)")
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>${ccol_ind} <small>-$i°</small></tt>,$2 $3 '${clr}' ${6};${5}")
done
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 {15..135..15};do
clr=$(pastel rotate $i "${1}" |pastel format hex)
out2+=("<tt><small>$clr</small> <span bgcolor='$clr'> </span>${ccol_ind} <small>$i°</small></tt>,$2 $3 '${clr}' ${6};${5}")
done
# ROTATE HSL END
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"
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}")
fi
eval "${mycmd[@]}"
}
case "$1" in
pick) pickcolor "$2" "${3}" "${4} ${5}" "${6}";;
pixelcolor) pixelcolor "$2" "${3}" "${4} ${5}" "${6}";;
*) main "$@" ;;
esac