mabox-colorizer/bin/jgctl

370 lines
11 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
ITEM_FG=$(pastel textcolor ${2}|pastel format hex)
if [[ "${ITEM_FG}" == *"ffffff"* ]];then
ITEM_FGCOLOR="#c0c0c0"
else
ITEM_FGCOLOR="#222222"
fi
read NFG NFGA<<< "$(grep 'color_norm_fg' ${THEMERC} | cut -d'=' -f2)"
sd "color_norm_fg.*$" "color_norm_fg = $ITEM_FGCOLOR $NFGA" ${THEMERC}
read NBG NBGA<<< "$(grep 'color_norm_bg' ${THEMERC} | cut -d'=' -f2)"
sd "color_norm_bg.*$" "color_norm_bg = $2 $NBGA" ${THEMERC}
# Title (Separator with text)
read TBG TBGA<<< "$(grep 'color_title_bg' ${THEMERC} | cut -d'=' -f2)"
sd "color_title_bg.*$" "color_title_bg = $2 $TBGA" ${THEMERC}
# calculate readable FG color
TITLE_FG=$(pastel textcolor ${2}|pastel format hex)
read TFG TFGA<<< "$(grep 'color_title_fg' ${THEMERC} | cut -d'=' -f2)"
###TITLE_FGCOLOR=$(pastel complement ${2}|pastel format hex)
if [[ "${TITLE_FG}" == *"ffffff"* ]];then
TITLE_FGCOLOR=$(pastel mix -f 0.7 '#ffffff' "${2}"|pastel format hex)
else
TITLE_FGCOLOR=$(pastel mix -f 0.7 '#000000' "${2}"|pastel format hex)
fi
sd "color_title_fg.*$" "color_title_fg = ${TITLE_FGCOLOR} $TFGA" ${THEMERC}
###sd "color_title_fg.*$" "color_title_fg = ${1} $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}
# Selected (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}
read SBORDER SBORDERA<<< "$(grep 'color_sel_border' ${THEMERC} | cut -d'=' -f2)"
alpha=${SBORDERA:-100}
sd "color_sel_border.*$" "color_sel_border = $1 $alpha" ${THEMERC}
# Separator line
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
#read IBOR<<< "$(grep 'item_border' ${THEMERC} | cut -d'=' -f2)"
#[[ ${IBOR} == "0" ]] && item_border 1
}
accent () {
color_sel_bg "${1}"
color_sel_fg "${2}"
color_sel_border "${2}"
}
tweak () {
case "$1" in
solid)
menu_gradient_pos none
tweak opacity 100
opacity color_norm_bg 0
opacity color_sep_fg 30
item_radius 0
item_border 0
;;
gradient)
menu_gradient_pos right
opacity color_norm_bg 10
opacity color_sep_fg 0
item_radius 3
item_border 0
;;
opacity)
opacity color_menu_bg "$2"
opacity color_menu_bg_to "$2"
;;
sizing)
case "$2" in
tight)
mb-setvar jgtools_padding=0
mb-setvar jgtools_border=0
mb-setvar submenu_spacing=1
;;
normal)
mb-setvar jgtools_padding=8
mb-setvar jgtools_border=0
mb-setvar submenu_spacing=2
;;
wide)
mb-setvar jgtools_padding=20
mb-setvar jgtools_border=4
mb-setvar submenu_spacing=4
;;
esac
;;
*):;;
esac
}
opacity () {
# jgctl opacity element value
read FUNC B COLOR OPACITY REST<<< "$(grep ${1} ${THEMERC})"
#echo "$FUNC $B $COLOR $OPACITY $REST"
sd "$1 .*= $COLOR.*$" "$FUNC = $COLOR $2 $REST" ${THEMERC}
}
savescheme () {
# ask for scheme name
schemename=$(yad --center --width=300 --title "SAVE_AS" --entry --entry-label="LABEL" --entry-text="NAME") || exit 1
echo "${1}${schemename}" >> "$HOME/.config/colorizer/menus/userschemes.csv"
#echo "${1}"
}
applyscheme () {
line=$(awk 'NR == n' n=$1 "$HOME/.config/colorizer/menus/userschemes.csv")
#notify-send.sh "$1" "${line}"
case "$1" in
sys) SCHEMEFILE="/usr/share/mabox-colorizer/colorschemes/menus.csv";;
usr) SCHEMEFILE="$HOME/.config/colorizer/menus/userschemes.csv";;
esac
while IFS="|" read -r mbg mbgt mborder tbg tfg tborder normbg nfg sbg sfg sborder sepfg grad scheme_name
do
mb-setvar jgmenu_theme=MBcolors
color_menu_bg "${mbg}"
color_menu_bg_to "${mbgt}"
color_menu_border "${mborder}"
color_title_bg "${tbg}"
color_title_fg "${tfg}"
color_title_border "${tborder}"
color_norm_bg "${normbg}"
color_norm_fg "${nfg}"
color_sel_bg "${sbg}"
color_sel_fg "${sfg}"
color_sel_border "${sborder}"
color_sep_fg "${sepfg}"
menu_gradient_pos "${grad}"
item_border 0
color_title_bg 100
color_menu_bg 100
color_menu_bg_to 100
color_norm_bg 0
#notify-send.sh "${scheme_name}" "${mbg}"
done < <(awk 'NR == n' n=$2 "$SCHEMEFILE")
}
delscheme() {
sed -i ${1}d "$HOME/.config/colorizer/menus/userschemes.csv"
}
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";;
accent) accent "$2" "$3";;
tweak) tweak "$2" "$3";;
opacity) opacity "$2" "$3";;
savescheme) savescheme "$2";;
applyscheme) applyscheme "$2" "$3";;
delscheme) delscheme "$2";;
*) : ;;
esac