mabox-colorizer/bin/jgctl
2022-12-19 22:22:23 +01:00

240 lines
7.5 KiB
Bash
Executable File

#!/bin/bash
# jgctl - menu config actions
# jgctl variable value config_file
. $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
# Backup original theme file
if [ ! -f "${THEMERC}.bak" ]; then
cp ${THEMERC} ${THEMERC}.bak
fi
theme () {
mb-setvar jgmenu_theme=${1}
}
reset () {
rm ${THEMERC}
mv ${THEMERC}.bak ${THEMERC}
}
resetMBcolors() {
mb-setvar jgmenu_theme=MBcolors
reset
case "$1" in
show) colorizer-menus -s;;
*):;;
esac
}
color_menu_bg () {
read MBG MBGA<<< "$(grep 'color_menu_bg ' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_menu_bg .*$" "color_menu_bg = $1 $MBGA" ${THEMERC}
;;
*)
sd "color_menu_bg .*$" "color_menu_bg = $MBG $1" ${THEMERC}
;;
esac
}
color_menu_bg_to () {
read MBGT MBGTA<<< "$(grep 'color_menu_bg_to ' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_menu_bg_to.*$" "color_menu_bg_to = $1 $MBGTA" ${THEMERC}
;;
*)
sd "color_menu_bg_to.*$" "color_menu_bg_to = $MBGT $1" ${THEMERC}
;;
esac
}
color_menu_border () {
read MBORDER MBORDERA<<< "$(grep 'color_menu_border' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_menu_border.*$" "color_menu_border = $1 $MBORDERA" ${THEMERC}
;;
*)
sd "color_menu_border.*$" "color_menu_border = $MBORDER $1" ${THEMERC}
;;
esac
}
menu_gradient_pos () {
sd "menu_gradient_pos.*$" "menu_gradient_pos = $1" ${THEMERC}
}
gradient () {
read MBG MBGA<<< "$(grep 'color_menu_bg ' ${THEMERC} | cut -d'=' -f2)"
read MBGT MBGTA<<< "$(grep 'color_menu_bg_to ' ${THEMERC} | cut -d'=' -f2)"
sd "color_menu_bg .*$" "color_menu_bg = $1 $MBGA" ${THEMERC}
sd "color_menu_bg_to.*$" "color_menu_bg_to = $2 $MBGTA" ${THEMERC}
ITEM_FG=$(pastel textcolor ${2}|pastel format hex)
read NFG NFGA<<< "$(grep 'color_norm_fg' ${THEMERC} | cut -d'=' -f2)"
sd "color_norm_fg.*$" "color_norm_fg = $ITEM_FG $NFGA" ${THEMERC}
# Title
read TBG TBGA<<< "$(grep 'color_title_bg' ${THEMERC} | cut -d'=' -f2)"
sd "color_title_bg.*$" "color_title_bg = $1 $TBGA" ${THEMERC}
# calculate readable FG color
TITLE_FG=$(pastel textcolor ${1}|pastel format hex)
read TFG TFGA<<< "$(grep 'color_title_fg' ${THEMERC} | cut -d'=' -f2)"
if [[ "${TITLE_FG}" == *"ffffff"* ]];then
TITLE_FGCOLOR=$(pastel mix -f 0.6 '#ffffff' "${2}"|pastel format hex)
else
TITLE_FGCOLOR=$(pastel mix -f 0.6 '#000000' "${2}"|pastel format hex)
fi
sd "color_title_fg.*$" "color_title_fg = ${TITLE_FGCOLOR} $TFGA" ${THEMERC}
read TBORDER TBORDERA<<< "$(grep 'color_title_border' ${THEMERC} | cut -d'=' -f2)"
TITLE_BORDER=$(pastel darken 0.05 ${1}|pastel format hex)
sd "color_title_border.*$" "color_title_border = $TITLE_BORDER $TBORDERA" ${THEMERC}
# Active item
read SBG SBGA<<< "$(grep 'color_sel_bg' ${THEMERC} | cut -d'=' -f2)"
alpha=${SBGA:-100}
sd "color_sel_bg.*$" "color_sel_bg = $2 $alpha" ${THEMERC}
ACTIVE_FG=$(pastel textcolor ${2}|pastel format hex)
read SFG SFGA<<< "$(grep 'color_sel_fg' ${THEMERC} | cut -d'=' -f2)"
sd "color_sel_fg.*$" "color_sel_fg = $ACTIVE_FG $SFGA" ${THEMERC}
# Sep
read SFG SFGA<<< "$(grep 'color_sep_fg' ${THEMERC} | cut -d'=' -f2)"
SEP_FG=$(pastel mix -f 0.5 "${1}" "${2}"|pastel format hex)
sd "color_sep_fg.*$" "color_sep_fg = $SEP_FG $SFGA" ${THEMERC}
# Menu border
read MBORDER MBORDERA<<< "$(grep 'color_menu_border' ${THEMERC} | cut -d'=' -f2)"
sd "color_menu_border.*$" "color_menu_border = $1 $MBORDERA" ${THEMERC}
}
sep_halign () {
sd "sep_halign.*$" "sep_halign = $1" ${THEMERC}
}
color_sep_fg () {
read SFG SFGA<<< "$(grep 'color_sep_fg' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_sep_fg.*$" "color_sep_fg = $1 $SFGA" ${THEMERC}
;;
*)
sd "color_sep_fg.*$" "color_sep_fg = $SFG $1" ${THEMERC}
;;
esac
}
color_title_bg () {
read TBG TBGA<<< "$(grep 'color_title_bg' ${THEMERC} | cut -d'=' -f2)"
#notify-send.sh "${1}" "${#1}"
case "${#1}" in
7) #color
sd "color_title_bg.*$" "color_title_bg = $1 $TBGA" ${THEMERC}
;;
*)
sd "color_title_bg.*$" "color_title_bg = $TBG $1" ${THEMERC}
;;
esac
}
color_title_fg () {
read TFG TFGA<<< "$(grep 'color_title_fg' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_title_fg.*$" "color_title_fg = $1 $TFGA" ${THEMERC}
;;
*)
sd "color_title_fg.*$" "color_title_fg = $TFG $1" ${THEMERC}
;;
esac
}
color_title_border () {
read TBORDER TBORDERA<<< "$(grep 'color_title_border' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_title_border.*$" "color_title_border = $1 $TBORDERA" ${THEMERC}
;;
*)
sd "color_title_border.*$" "color_title_border = $TBORDER $1" ${THEMERC}
;;
esac
}
item_border () {
sd "item_border.*$" "item_border = $1" ${THEMERC}
}
item_radius () {
sd "item_radius.*$" "item_radius = $1" ${THEMERC}
}
color_norm_bg () {
read NBG NBGA<<< "$(grep 'color_norm_bg' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_norm_bg.*$" "color_norm_bg = $1 $NBGA" ${THEMERC}
;;
*)
sd "color_norm_bg.*$" "color_norm_bg = $NBG $1" ${THEMERC}
;;
esac
}
color_norm_fg () {
read NFG NFGA<<< "$(grep 'color_norm_fg' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_norm_fg.*$" "color_norm_fg = $1 $NFGA" ${THEMERC}
;;
*)
sd "color_norm_fg.*$" "color_norm_fg = $NFG $1" ${THEMERC}
;;
esac
}
color_sel_bg () {
read SBG SBGA<<< "$(grep 'color_sel_bg' ${THEMERC} | cut -d'=' -f2)"
alpha=${SBGA:-100}
case "${#1}" in
7) #color
sd "color_sel_bg.*$" "color_sel_bg = $1 $alpha" ${THEMERC}
;;
*)
sd "color_sel_bg.*$" "color_sel_bg = $SBG $1" ${THEMERC}
;;
esac
}
color_sel_fg () {
read SFG SFGA<<< "$(grep 'color_sel_fg' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_sel_fg.*$" "color_sel_fg = $1 $SFGA" ${THEMERC}
;;
*)
sd "color_sel_fg.*$" "color_sel_fg = $SFG $1" ${THEMERC}
;;
esac
}
color_sel_border () {
read SBORDER SBORDERA<<< "$(grep 'color_sel_border' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_sel_border.*$" "color_sel_border = $1 $SBORDERA" ${THEMERC}
;;
*)
sd "color_sel_border.*$" "color_sel_border = $SBORDER $1" ${THEMERC}
;;
esac
}
case "$1" in
theme) theme "$2";;
reset) reset ;;
resetMBcolors) resetMBcolors "$2";;
color_menu_bg) color_menu_bg "$2";;
color_menu_bg_to) color_menu_bg_to "$2";;
color_menu_border) color_menu_border "$2";;
menu_gradient_pos) menu_gradient_pos "$2";;
gradient) gradient "$2" "$3";;
sep_halign) sep_halign "$2";;
color_sep_fg) color_sep_fg "$2";;
color_title_bg) color_title_bg "$2";;
color_title_fg) color_title_fg "$2";;
color_title_border) color_title_border "$2";;
item_border) item_border "$2";;
item_radius) item_radius "$2";;
color_norm_bg) color_norm_bg "$2";;
color_norm_fg) color_norm_fg "$2";;
color_sel_bg) color_sel_bg "$2";;
color_sel_fg) color_sel_fg "$2";;
color_sel_border) color_sel_border "$2";;
*) : ;;
esac