Update theme engine
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
# shellcheck shell=bash
|
||||
|
||||
wallpaper=""
|
||||
color=""
|
||||
mode=""
|
||||
flavor=""
|
||||
contrast=""
|
||||
|
||||
set_wallpaper() {
|
||||
if [[ -f "$1" ]]; then
|
||||
@@ -12,6 +15,37 @@ set_wallpaper() {
|
||||
fi
|
||||
}
|
||||
|
||||
set_color() {
|
||||
local re='^#?([A-Fa-f0-9]{6})$'
|
||||
if [[ "$1" =~ $re ]]; then
|
||||
color="$1"
|
||||
else
|
||||
echo "Invalid color format: $1"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
set_flavor() {
|
||||
case "$1" in
|
||||
content|expressive|fidelity|fruit-salad|monochrome|neutral|rainbow|tonal-spot)
|
||||
flavor="$1"
|
||||
;;
|
||||
*)
|
||||
echo "Invalid flavor: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
set_contrast() {
|
||||
if [[ "$1" =~ ^-?[0-1](\.[0-9]+)?$ ]]; then
|
||||
contrast="$1"
|
||||
else
|
||||
echo "Invalid contrast value: $1"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
toggle_mode() {
|
||||
if [[ "$(cat "$CONFIG"/mode)" = "light" ]]; then
|
||||
mode="dark"
|
||||
@@ -21,37 +55,48 @@ toggle_mode() {
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 [-m {light|dark|toggle}] [-w <file>]"
|
||||
echo "Usage: $0 [-m {light|dark|toggle}] [-w <file>] [-h <hexcolor>] [-f <flavor>] [-c <contrast>]"
|
||||
echo " Only one of -w (wallpaper) or -h (hex color) can be used."
|
||||
echo " Valid flavors: content, expressive, fidelity, fruit-salad, monochrome, neutral, rainbow, tonal-spot"
|
||||
echo " Contrast must be a number between -1 and 1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
finish() {
|
||||
[[ -n "$wallpaper" ]] && ln -sf "$wallpaper" "$CONFIG"/wallpaper
|
||||
[[ -n "$wallpaper" ]] && rm -f "$CONFIG"/color && ln -sf "$wallpaper" "$CONFIG"/wallpaper
|
||||
[[ -n "$color" ]] && rm -f "$CONFIG"/wallpaper && echo "$color" > "$CONFIG"/color
|
||||
[[ -n "$mode" ]] && echo "$mode" > "$CONFIG"/mode
|
||||
[[ -n "$flavor" ]] && echo "$flavor" > "$CONFIG"/flavor
|
||||
[[ -n "$contrast" ]] && echo "$contrast" > "$CONFIG"/contrast
|
||||
|
||||
"$INIT" > /dev/null
|
||||
"$RELOAD" > /dev/null
|
||||
}
|
||||
|
||||
# Parse arguments
|
||||
while getopts "m:w:" opt; do
|
||||
while getopts "m:w:h:f:c:" opt; do
|
||||
case "$opt" in
|
||||
m)
|
||||
case "$OPTARG" in
|
||||
light|dark)
|
||||
mode="$OPTARG"
|
||||
;;
|
||||
toggle)
|
||||
toggle_mode
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
light|dark) mode="$OPTARG" ;;
|
||||
toggle) toggle_mode ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
;;
|
||||
w)
|
||||
[[ -n "$color" ]] && usage
|
||||
set_wallpaper "$OPTARG"
|
||||
;;
|
||||
h)
|
||||
[[ -n "$wallpaper" ]] && usage
|
||||
set_color "$OPTARG"
|
||||
;;
|
||||
f)
|
||||
set_flavor "$OPTARG"
|
||||
;;
|
||||
c)
|
||||
set_contrast "$OPTARG"
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
|
Reference in New Issue
Block a user