mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-25 14:02:53 -05:00
re-work mmatugen meta theming
able to handle more rapid changes now, and colors look better
This commit is contained in:
203
scripts/matugen-worker.sh
Executable file
203
scripts/matugen-worker.sh
Executable file
@@ -0,0 +1,203 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [ $# -lt 3 ]; then
|
||||
echo "Usage: $0 STATE_DIR SHELL_DIR --run" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
STATE_DIR="$1"
|
||||
SHELL_DIR="$2"
|
||||
|
||||
if [ ! -d "$STATE_DIR" ]; then
|
||||
echo "Error: STATE_DIR '$STATE_DIR' does not exist" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$SHELL_DIR" ]; then
|
||||
echo "Error: SHELL_DIR '$SHELL_DIR' does not exist" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shift 2 # Remove STATE_DIR and SHELL_DIR from arguments
|
||||
|
||||
if [[ "${1:-}" != "--run" ]]; then
|
||||
echo "usage: $0 STATE_DIR SHELL_DIR --run" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DESIRED_JSON="$STATE_DIR/matugen.desired.json"
|
||||
BUILT_KEY="$STATE_DIR/matugen.key"
|
||||
LAST_JSON="$STATE_DIR/last.json"
|
||||
LOCK="$STATE_DIR/matugen-worker.lock"
|
||||
|
||||
exec 9>"$LOCK"
|
||||
flock 9
|
||||
|
||||
|
||||
read_desired() {
|
||||
[[ ! -f "$DESIRED_JSON" ]] && { echo "no desired state" >&2; exit 0; }
|
||||
cat "$DESIRED_JSON"
|
||||
}
|
||||
|
||||
key_of() {
|
||||
local json="$1"
|
||||
local kind=$(echo "$json" | sed 's/.*"kind": *"\([^"]*\)".*/\1/')
|
||||
local value=$(echo "$json" | sed 's/.*"value": *"\([^"]*\)".*/\1/')
|
||||
local mode=$(echo "$json" | sed 's/.*"mode": *"\([^"]*\)".*/\1/')
|
||||
local icon=$(echo "$json" | sed 's/.*"iconTheme": *"\([^"]*\)".*/\1/')
|
||||
[[ -z "$icon" ]] && icon="System Default"
|
||||
echo "${kind}|${value}|${mode}|${icon}" | sha256sum | cut -d' ' -f1
|
||||
}
|
||||
|
||||
build_once() {
|
||||
local json="$1"
|
||||
local kind value mode icon
|
||||
kind=$(echo "$json" | sed 's/.*"kind": *"\([^"]*\)".*/\1/')
|
||||
value=$(echo "$json" | sed 's/.*"value": *"\([^"]*\)".*/\1/')
|
||||
mode=$(echo "$json" | sed 's/.*"mode": *"\([^"]*\)".*/\1/')
|
||||
icon=$(echo "$json" | sed 's/.*"iconTheme": *"\([^"]*\)".*/\1/')
|
||||
[[ -z "$icon" ]] && icon="System Default"
|
||||
|
||||
CONFIG_DIR="${CONFIG_DIR:-$HOME/.config}"
|
||||
|
||||
TMP_CFG="$(mktemp)"
|
||||
trap 'rm -f "$TMP_CFG"' RETURN
|
||||
|
||||
cat "$SHELL_DIR/matugen/configs/base.toml" > "$TMP_CFG"
|
||||
echo "" >> "$TMP_CFG"
|
||||
if command -v niri >/dev/null 2>&1; then
|
||||
cat "$SHELL_DIR/matugen/configs/niri.toml" >> "$TMP_CFG"
|
||||
echo "" >> "$TMP_CFG"
|
||||
fi
|
||||
|
||||
if command -v qt5ct >/dev/null 2>&1; then
|
||||
cat "$SHELL_DIR/matugen/configs/qt5ct.toml" >> "$TMP_CFG"
|
||||
echo "" >> "$TMP_CFG"
|
||||
fi
|
||||
|
||||
if command -v qt6ct >/dev/null 2>&1; then
|
||||
cat "$SHELL_DIR/matugen/configs/qt6ct.toml" >> "$TMP_CFG"
|
||||
echo "" >> "$TMP_CFG"
|
||||
fi
|
||||
|
||||
if [ "$mode" = "light" ]; then
|
||||
COLLOID_TEMPLATE="$SHELL_DIR/matugen/templates/gtk3-colloid-light.css"
|
||||
else
|
||||
COLLOID_TEMPLATE="$SHELL_DIR/matugen/templates/gtk3-colloid-dark.css"
|
||||
fi
|
||||
|
||||
sed -i "/\[templates\.gtk3\]/,/^$/ s|input_path = './matugen/templates/gtk-colors.css'|input_path = '$COLLOID_TEMPLATE'|" "$TMP_CFG"
|
||||
sed -i "s|input_path = './matugen/templates/|input_path = '$SHELL_DIR/matugen/templates/|g" "$TMP_CFG"
|
||||
|
||||
pushd "$SHELL_DIR" >/dev/null
|
||||
MAT_MODE=(-m "$mode")
|
||||
|
||||
case "$kind" in
|
||||
image)
|
||||
[[ -f "$value" ]] || { echo "wallpaper not found: $value" >&2; popd >/dev/null; return 2; }
|
||||
JSON=$(matugen -c "$TMP_CFG" --json hex image "$value" "${MAT_MODE[@]}")
|
||||
matugen -c "$TMP_CFG" image "$value" "${MAT_MODE[@]}" >/dev/null
|
||||
;;
|
||||
hex)
|
||||
[[ "$value" =~ ^#[0-9A-Fa-f]{6}$ ]] || { echo "invalid hex: $value" >&2; popd >/dev/null; return 2; }
|
||||
JSON=$(matugen -c "$TMP_CFG" --json hex color hex "$value" "${MAT_MODE[@]}")
|
||||
matugen -c "$TMP_CFG" color hex "$value" "${MAT_MODE[@]}" >/dev/null
|
||||
;;
|
||||
*)
|
||||
echo "unknown kind: $kind" >&2; popd >/dev/null; return 2;;
|
||||
esac
|
||||
|
||||
TMP_CONTENT_CFG="$(mktemp)"
|
||||
echo "[config]" > "$TMP_CONTENT_CFG"
|
||||
echo "" >> "$TMP_CONTENT_CFG"
|
||||
|
||||
if command -v ghostty >/dev/null 2>&1; then
|
||||
cat "$SHELL_DIR/matugen/configs/ghostty.toml" >> "$TMP_CONTENT_CFG"
|
||||
sed -i "s|input_path = './matugen/templates/|input_path = '$SHELL_DIR/matugen/templates/|g" "$TMP_CONTENT_CFG"
|
||||
echo "" >> "$TMP_CONTENT_CFG"
|
||||
fi
|
||||
|
||||
if command -v kitty >/dev/null 2>&1; then
|
||||
cat "$SHELL_DIR/matugen/configs/kitty.toml" >> "$TMP_CONTENT_CFG"
|
||||
sed -i "s|input_path = './matugen/templates/|input_path = '$SHELL_DIR/matugen/templates/|g" "$TMP_CONTENT_CFG"
|
||||
echo "" >> "$TMP_CONTENT_CFG"
|
||||
fi
|
||||
|
||||
if command -v dgop >/dev/null 2>&1; then
|
||||
cat "$SHELL_DIR/matugen/configs/dgop.toml" >> "$TMP_CONTENT_CFG"
|
||||
sed -i "s|input_path = './matugen/templates/|input_path = '$SHELL_DIR/matugen/templates/|g" "$TMP_CONTENT_CFG"
|
||||
echo "" >> "$TMP_CONTENT_CFG"
|
||||
fi
|
||||
|
||||
if [[ -s "$TMP_CONTENT_CFG" ]] && grep -q '\[templates\.' "$TMP_CONTENT_CFG"; then
|
||||
case "$kind" in
|
||||
image)
|
||||
matugen -c "$TMP_CONTENT_CFG" image "$value" "${MAT_MODE[@]}" >/dev/null
|
||||
;;
|
||||
hex)
|
||||
matugen -c "$TMP_CONTENT_CFG" color hex "$value" "${MAT_MODE[@]}" >/dev/null
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
rm -f "$TMP_CONTENT_CFG"
|
||||
popd >/dev/null
|
||||
|
||||
echo "$JSON" | grep -q '"primary"' || { echo "matugen JSON missing primary" >&2; return 2; }
|
||||
printf "%s" "$JSON" > "$LAST_JSON"
|
||||
|
||||
if [ "$mode" = "light" ]; then
|
||||
SECTION=$(echo "$JSON" | sed -n 's/.*"light":{\([^}]*\)}.*/\1/p')
|
||||
else
|
||||
SECTION=$(echo "$JSON" | sed -n 's/.*"dark":{\([^}]*\)}.*/\1/p')
|
||||
fi
|
||||
|
||||
PRIMARY=$(echo "$SECTION" | sed -n 's/.*"primary_container":"\(#[0-9a-fA-F]\{6\}\)".*/\1/p')
|
||||
HONOR=$(echo "$SECTION" | sed -n 's/.*"primary":"\(#[0-9a-fA-F]\{6\}\)".*/\1/p')
|
||||
|
||||
if command -v ghostty >/dev/null 2>&1 && [[ -f "$CONFIG_DIR/ghostty/config-dankcolors" ]]; then
|
||||
OUT=$("$SHELL_DIR/matugen/b16.py" "$PRIMARY" $([[ "$mode" == "light" ]] && echo --light) ${HONOR:+--honor-primary "$HONOR"} 2>/dev/null || true)
|
||||
if [[ -n "${OUT:-}" ]]; then
|
||||
TMP="$(mktemp)"
|
||||
printf "%s\n\n" "$OUT" > "$TMP"
|
||||
cat "$CONFIG_DIR/ghostty/config-dankcolors" >> "$TMP"
|
||||
mv "$TMP" "$CONFIG_DIR/ghostty/config-dankcolors"
|
||||
fi
|
||||
fi
|
||||
|
||||
if command -v kitty >/dev/null 2>&1 && [[ -f "$CONFIG_DIR/kitty/dank-theme.conf" ]]; then
|
||||
OUT=$("$SHELL_DIR/matugen/b16.py" "$PRIMARY" $([[ "$mode" == "light" ]] && echo --light) ${HONOR:+--honor-primary "$HONOR"} --kitty 2>/dev/null || true)
|
||||
if [[ -n "${OUT:-}" ]]; then
|
||||
TMP="$(mktemp)"
|
||||
printf "%s\n\n" "$OUT" > "$TMP"
|
||||
cat "$CONFIG_DIR/kitty/dank-theme.conf" >> "$TMP"
|
||||
mv "$TMP" "$CONFIG_DIR/kitty/dank-theme.conf"
|
||||
fi
|
||||
fi
|
||||
COLOR_SCHEME=$([[ "$mode" == "light" ]] && echo prefer-light || echo prefer-dark)
|
||||
if command -v dconf >/dev/null 2>&1; then
|
||||
dconf write /org/gnome/desktop/interface/color-scheme "\"$COLOR_SCHEME\"" 2>/dev/null || true
|
||||
[[ "$icon" != "System Default" && -n "$icon" ]] && dconf write /org/gnome/desktop/interface/icon-theme "\"$icon\"" 2>/dev/null || true
|
||||
elif command -v gsettings >/dev/null 2>&1; then
|
||||
gsettings set org.gnome.desktop.interface color-scheme "$COLOR_SCHEME" 2>/dev/null || true
|
||||
[[ "$icon" != "System Default" && -n "$icon" ]] && gsettings set org.gnome.desktop.interface icon-theme "$icon" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
while :; do
|
||||
DESIRED="$(read_desired)"
|
||||
WANT_KEY="$(key_of "$DESIRED")"
|
||||
HAVE_KEY=""
|
||||
[[ -f "$BUILT_KEY" ]] && HAVE_KEY="$(cat "$BUILT_KEY" 2>/dev/null || true)"
|
||||
|
||||
if [[ "$WANT_KEY" == "$HAVE_KEY" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if build_once "$DESIRED"; then
|
||||
echo "$WANT_KEY" > "$BUILT_KEY"
|
||||
else
|
||||
exit 2
|
||||
fi
|
||||
done
|
||||
@@ -1,361 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
INPUT_SOURCE="$1"
|
||||
SHELL_DIR="$2"
|
||||
CONFIG_DIR="$3"
|
||||
MODE="$4"
|
||||
IS_LIGHT="$5"
|
||||
ICON_THEME="$6"
|
||||
|
||||
if [ -z "$SHELL_DIR" ] || [ -z "$CONFIG_DIR" ]; then
|
||||
echo "Usage: $0 <input_source> <shell_dir> <config_dir> <mode> [is_light] [icon_theme]" >&2
|
||||
echo " input_source: wallpaper path for 'generate' mode, hex color for 'generate-color' mode" >&2
|
||||
exit 1
|
||||
fi
|
||||
MODE=${MODE:-"generate"}
|
||||
IS_LIGHT=${IS_LIGHT:-"false"}
|
||||
ICON_THEME=${ICON_THEME:-"System Default"}
|
||||
|
||||
update_theme_settings() {
|
||||
local color_scheme="$1"
|
||||
local icon_theme="$2"
|
||||
|
||||
echo "Updating theme settings..."
|
||||
|
||||
if command -v dconf >/dev/null 2>&1; then
|
||||
dconf write /org/gnome/desktop/interface/color-scheme "\"$color_scheme\""
|
||||
echo "Set color-scheme to: $color_scheme"
|
||||
|
||||
if [ "$icon_theme" != "System Default" ] && [ -n "$icon_theme" ]; then
|
||||
dconf write /org/gnome/desktop/interface/icon-theme "\"$icon_theme\""
|
||||
echo "Set icon-theme to: $icon_theme"
|
||||
fi
|
||||
elif command -v gsettings >/dev/null 2>&1; then
|
||||
gsettings set org.gnome.desktop.interface color-scheme "$color_scheme"
|
||||
echo "Set color-scheme to: $color_scheme"
|
||||
|
||||
if [ "$icon_theme" != "System Default" ] && [ -n "$icon_theme" ]; then
|
||||
gsettings set org.gnome.desktop.interface icon-theme "$icon_theme"
|
||||
echo "Set icon-theme to: $icon_theme"
|
||||
fi
|
||||
else
|
||||
echo "Warning: Neither dconf nor gsettings available"
|
||||
fi
|
||||
}
|
||||
|
||||
build_dynamic_config() {
|
||||
local temp_config="$1"
|
||||
local is_light="$2"
|
||||
local shell_dir="$3"
|
||||
|
||||
echo "Building dynamic matugen configuration..."
|
||||
|
||||
cat "$shell_dir/matugen/configs/base.toml" > "$temp_config"
|
||||
echo "" >> "$temp_config"
|
||||
|
||||
if command -v niri >/dev/null 2>&1; then
|
||||
echo " - Including niri config (niri found)"
|
||||
cat "$shell_dir/matugen/configs/niri.toml" >> "$temp_config"
|
||||
echo "" >> "$temp_config"
|
||||
else
|
||||
echo " - Skipping niri config (niri not found)"
|
||||
fi
|
||||
|
||||
if command -v qt5ct >/dev/null 2>&1; then
|
||||
echo " - Including qt5ct config (qt5ct found)"
|
||||
cat "$shell_dir/matugen/configs/qt5ct.toml" >> "$temp_config"
|
||||
echo "" >> "$temp_config"
|
||||
else
|
||||
echo " - Skipping qt5ct config (qt5ct not found)"
|
||||
fi
|
||||
|
||||
if command -v qt6ct >/dev/null 2>&1; then
|
||||
echo " - Including qt6ct config (qt6ct found)"
|
||||
cat "$shell_dir/matugen/configs/qt6ct.toml" >> "$temp_config"
|
||||
echo "" >> "$temp_config"
|
||||
else
|
||||
echo " - Skipping qt6ct config (qt6ct not found)"
|
||||
fi
|
||||
|
||||
if [ "$is_light" = "true" ]; then
|
||||
COLLOID_TEMPLATE="$shell_dir/matugen/templates/gtk3-colloid-light.css"
|
||||
else
|
||||
COLLOID_TEMPLATE="$shell_dir/matugen/templates/gtk3-colloid-dark.css"
|
||||
fi
|
||||
|
||||
sed -i "/\[templates\.gtk3\]/,/^$/ s|input_path = './matugen/templates/gtk-colors.css'|input_path = '$COLLOID_TEMPLATE'|" "$temp_config"
|
||||
sed -i "s|input_path = './matugen/templates/|input_path = '$shell_dir/matugen/templates/|g" "$temp_config"
|
||||
}
|
||||
|
||||
build_content_config() {
|
||||
local temp_config="$1"
|
||||
local is_light="$2"
|
||||
local shell_dir="$3"
|
||||
|
||||
echo "Building dynamic content configuration..."
|
||||
|
||||
echo "[config]" > "$temp_config"
|
||||
echo "" >> "$temp_config"
|
||||
|
||||
if command -v ghostty >/dev/null 2>&1; then
|
||||
echo " - Including ghostty config (ghostty found)"
|
||||
cat "$shell_dir/matugen/configs/ghostty.toml" >> "$temp_config"
|
||||
sed -i "s|input_path = './matugen/templates/|input_path = '$shell_dir/matugen/templates/|g" "$temp_config"
|
||||
echo "" >> "$temp_config"
|
||||
else
|
||||
echo " - Skipping ghostty config (ghostty not found)"
|
||||
fi
|
||||
|
||||
if command -v kitty >/dev/null 2>&1; then
|
||||
echo " - Including kitty config (kitty found)"
|
||||
cat "$shell_dir/matugen/configs/kitty.toml" >> "$temp_config"
|
||||
sed -i "s|input_path = './matugen/templates/|input_path = '$shell_dir/matugen/templates/|g" "$temp_config"
|
||||
echo "" >> "$temp_config"
|
||||
else
|
||||
echo " - Skipping kitty config (kitty not found)"
|
||||
fi
|
||||
|
||||
if command -v dgop >/dev/null 2>&1; then
|
||||
echo " - Including dgop config (dgop found)"
|
||||
cat "$shell_dir/matugen/configs/dgop.toml" >> "$temp_config"
|
||||
sed -i "s|input_path = './matugen/templates/|input_path = '$shell_dir/matugen/templates/|g" "$temp_config"
|
||||
echo "" >> "$temp_config"
|
||||
else
|
||||
echo " - Skipping dgop config (dgop not found)"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$MODE" = "generate" ]; then
|
||||
if [ ! -f "$INPUT_SOURCE" ]; then
|
||||
echo "Wallpaper file not found: $INPUT_SOURCE" >&2
|
||||
exit 1
|
||||
fi
|
||||
elif [ "$MODE" = "generate-color" ]; then
|
||||
if ! echo "$INPUT_SOURCE" | grep -qE '^#[0-9A-Fa-f]{6}$'; then
|
||||
echo "Invalid hex color format: $INPUT_SOURCE (expected format: #RRGGBB)" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d "$SHELL_DIR" ]; then
|
||||
echo "Shell directory not found: $SHELL_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$SHELL_DIR" || exit 1
|
||||
|
||||
if [ ! -d "matugen/configs" ]; then
|
||||
echo "Config directory not found: $SHELL_DIR/matugen/configs" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TEMP_CONFIG="/tmp/matugen-config-$$.toml"
|
||||
build_dynamic_config "$TEMP_CONFIG" "$IS_LIGHT" "$SHELL_DIR"
|
||||
|
||||
MATUGEN_MODE=""
|
||||
if [ "$IS_LIGHT" = "true" ]; then
|
||||
MATUGEN_MODE="-m light"
|
||||
else
|
||||
MATUGEN_MODE="-m dark"
|
||||
fi
|
||||
|
||||
EXTRACTED_PRIMARY=""
|
||||
|
||||
if [ "$MODE" = "generate" ]; then
|
||||
echo "Generating matugen themes from wallpaper: $INPUT_SOURCE"
|
||||
echo "Using dynamic config: $TEMP_CONFIG"
|
||||
|
||||
# Generate templates (no JSON needed for main themes)
|
||||
if ! matugen -c "$TEMP_CONFIG" image "$INPUT_SOURCE" $MATUGEN_MODE; then
|
||||
echo "Failed to generate themes with matugen" >&2
|
||||
rm -f "$TEMP_CONFIG"
|
||||
exit 1
|
||||
fi
|
||||
elif [ "$MODE" = "generate-color" ]; then
|
||||
echo "Generating matugen themes from color: $INPUT_SOURCE"
|
||||
echo "Using dynamic config: $TEMP_CONFIG"
|
||||
|
||||
# Generate templates, for color mode we already have the primary
|
||||
if ! matugen -c "$TEMP_CONFIG" color hex "$INPUT_SOURCE" $MATUGEN_MODE; then
|
||||
echo "Failed to generate themes with matugen" >&2
|
||||
rm -f "$TEMP_CONFIG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# For color mode, we already have the input color as primary
|
||||
EXTRACTED_PRIMARY="$INPUT_SOURCE"
|
||||
fi
|
||||
|
||||
TEMP_CONTENT_CONFIG="/tmp/matugen-content-config-$$.toml"
|
||||
build_content_config "$TEMP_CONTENT_CONFIG" "$IS_LIGHT" "$SHELL_DIR"
|
||||
|
||||
if [ -s "$TEMP_CONTENT_CONFIG" ] && grep -q '\[templates\.' "$TEMP_CONTENT_CONFIG"; then
|
||||
echo "Running content-specific theme generation..."
|
||||
# Generate content-specific templates
|
||||
if [ "$MODE" = "generate" ]; then
|
||||
matugen -c "$TEMP_CONTENT_CONFIG" -t scheme-content image "$INPUT_SOURCE" $MATUGEN_MODE
|
||||
elif [ "$MODE" = "generate-color" ]; then
|
||||
matugen -c "$TEMP_CONTENT_CONFIG" -t scheme-content color hex "$INPUT_SOURCE" $MATUGEN_MODE
|
||||
fi
|
||||
|
||||
# Small delay to ensure content generation completes
|
||||
sleep 0.1
|
||||
|
||||
# Get JSON with error handling
|
||||
if [ "$MODE" = "generate" ]; then
|
||||
if ! DEFAULT_JSON=$(matugen --json hex image "$INPUT_SOURCE" $MATUGEN_MODE 2>&1); then
|
||||
echo "Warning: Failed to get JSON from matugen for image mode"
|
||||
DEFAULT_JSON=""
|
||||
fi
|
||||
elif [ "$MODE" = "generate-color" ]; then
|
||||
if ! DEFAULT_JSON=$(matugen --json hex color hex "$INPUT_SOURCE" $MATUGEN_MODE 2>&1); then
|
||||
echo "Warning: Failed to get JSON from matugen for color mode"
|
||||
DEFAULT_JSON=""
|
||||
fi
|
||||
fi
|
||||
|
||||
# Extract primary_container for b16 base color and primary for honoring
|
||||
if [ -n "$DEFAULT_JSON" ] && echo "$DEFAULT_JSON" | grep -q '"primary_container"'; then
|
||||
EXTRACTED_PRIMARY=$(echo "$DEFAULT_JSON" | grep -oE '"primary_container":"#[0-9a-fA-F]{6}"' | sed -n '1p' | cut -d'"' -f4)
|
||||
echo "Successfully extracted primary_container: $EXTRACTED_PRIMARY"
|
||||
|
||||
# Also extract the actual primary color to honor in palette
|
||||
if [ "$IS_LIGHT" = "true" ]; then
|
||||
# Light mode: get primary from light theme (second occurrence)
|
||||
HONOR_PRIMARY=$(echo "$DEFAULT_JSON" | grep -oE '"primary":"#[0-9a-fA-F]{6}"' | sed -n '2p' | cut -d'"' -f4)
|
||||
else
|
||||
# Dark mode: get primary from dark theme (first occurrence)
|
||||
HONOR_PRIMARY=$(echo "$DEFAULT_JSON" | grep -oE '"primary":"#[0-9a-fA-F]{6}"' | sed -n '1p' | cut -d'"' -f4)
|
||||
fi
|
||||
echo "Successfully extracted primary for honoring: $HONOR_PRIMARY"
|
||||
else
|
||||
echo "Warning: No primary_container found in JSON output"
|
||||
EXTRACTED_PRIMARY=""
|
||||
HONOR_PRIMARY=""
|
||||
fi
|
||||
|
||||
# Fallback if extraction failed
|
||||
if [ -z "$EXTRACTED_PRIMARY" ]; then
|
||||
if [ "$MODE" = "generate-color" ]; then
|
||||
EXTRACTED_PRIMARY="$INPUT_SOURCE"
|
||||
HONOR_PRIMARY="$INPUT_SOURCE"
|
||||
echo "Using input color as primary: $EXTRACTED_PRIMARY"
|
||||
else
|
||||
EXTRACTED_PRIMARY="#6b5f8e"
|
||||
HONOR_PRIMARY="#ccbeff" # Default Material Design primary for fallback
|
||||
echo "Warning: Could not extract primary color, using fallback: $EXTRACTED_PRIMARY"
|
||||
fi
|
||||
else
|
||||
echo "Extracted primary color from scheme-content: $EXTRACTED_PRIMARY"
|
||||
fi
|
||||
|
||||
if command -v ghostty >/dev/null 2>&1; then
|
||||
echo "Generating base16 palette for ghostty..."
|
||||
|
||||
PRIMARY_COLOR="$EXTRACTED_PRIMARY"
|
||||
if [ -z "$PRIMARY_COLOR" ]; then
|
||||
if [ "$MODE" = "generate-color" ]; then
|
||||
PRIMARY_COLOR="$INPUT_SOURCE"
|
||||
echo "Using input color as primary: $PRIMARY_COLOR"
|
||||
else
|
||||
PRIMARY_COLOR="#6b5f8e"
|
||||
echo "Warning: Could not extract primary color, using fallback: $PRIMARY_COLOR"
|
||||
fi
|
||||
fi
|
||||
|
||||
B16_ARGS="$PRIMARY_COLOR"
|
||||
if [ "$IS_LIGHT" = "true" ]; then
|
||||
B16_ARGS="$B16_ARGS --light"
|
||||
fi
|
||||
if [ -n "$HONOR_PRIMARY" ]; then
|
||||
B16_ARGS="$B16_ARGS --honor-primary $HONOR_PRIMARY"
|
||||
fi
|
||||
|
||||
B16_OUTPUT=$("$SHELL_DIR/matugen/b16.py" $B16_ARGS)
|
||||
|
||||
if [ $? -eq 0 ] && [ -n "$B16_OUTPUT" ]; then
|
||||
TEMP_GHOSTTY="/tmp/ghostty-config-$$.conf"
|
||||
echo "$B16_OUTPUT" > "$TEMP_GHOSTTY"
|
||||
echo "" >> "$TEMP_GHOSTTY"
|
||||
|
||||
if [ -f "$CONFIG_DIR/ghostty/config-dankcolors" ]; then
|
||||
cat "$CONFIG_DIR/ghostty/config-dankcolors" >> "$TEMP_GHOSTTY"
|
||||
mv "$TEMP_GHOSTTY" "$CONFIG_DIR/ghostty/config-dankcolors"
|
||||
echo "Base16 palette prepended to ghostty config"
|
||||
else
|
||||
echo "Warning: $CONFIG_DIR/ghostty/config-dankcolors not found, skipping b16 prepend"
|
||||
rm -f "$TEMP_GHOSTTY"
|
||||
fi
|
||||
else
|
||||
echo "Warning: Failed to generate base16 palette"
|
||||
fi
|
||||
fi
|
||||
|
||||
if command -v kitty >/dev/null 2>&1; then
|
||||
echo "Generating base16 palette for kitty..."
|
||||
|
||||
PRIMARY_COLOR="$EXTRACTED_PRIMARY"
|
||||
if [ -z "$PRIMARY_COLOR" ]; then
|
||||
if [ "$MODE" = "generate-color" ]; then
|
||||
PRIMARY_COLOR="$INPUT_SOURCE"
|
||||
echo "Using input color as primary: $PRIMARY_COLOR"
|
||||
else
|
||||
PRIMARY_COLOR="#6b5f8e"
|
||||
echo "Warning: Could not extract primary color, using fallback: $PRIMARY_COLOR"
|
||||
fi
|
||||
fi
|
||||
|
||||
B16_ARGS="$PRIMARY_COLOR"
|
||||
if [ "$IS_LIGHT" = "true" ]; then
|
||||
B16_ARGS="$B16_ARGS --light"
|
||||
fi
|
||||
if [ -n "$HONOR_PRIMARY" ]; then
|
||||
B16_ARGS="$B16_ARGS --honor-primary $HONOR_PRIMARY"
|
||||
fi
|
||||
|
||||
B16_OUTPUT=$("$SHELL_DIR/matugen/b16.py" $B16_ARGS --kitty)
|
||||
|
||||
if [ $? -eq 0 ] && [ -n "$B16_OUTPUT" ]; then
|
||||
TEMP_KITTY="/tmp/kitty-config-$$.conf"
|
||||
echo "$B16_OUTPUT" > "$TEMP_KITTY"
|
||||
echo "" >> "$TEMP_KITTY"
|
||||
|
||||
if [ -f "$CONFIG_DIR/kitty/dank-theme.conf" ]; then
|
||||
cat "$CONFIG_DIR/kitty/dank-theme.conf" >> "$TEMP_KITTY"
|
||||
mv "$TEMP_KITTY" "$CONFIG_DIR/kitty/dank-theme.conf"
|
||||
echo "Base16 palette prepended to kitty config"
|
||||
else
|
||||
echo "Warning: $CONFIG_DIR/kitty/dank-theme.conf not found, skipping b16 prepend"
|
||||
rm -f "$TEMP_KITTY"
|
||||
fi
|
||||
else
|
||||
echo "Warning: Failed to generate base16 palette for kitty"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "No content-specific tools found, skipping content generation"
|
||||
fi
|
||||
|
||||
rm -f "$TEMP_CONFIG" "$TEMP_CONTENT_CONFIG"
|
||||
|
||||
echo "Updating system theme preferences..."
|
||||
|
||||
color_scheme=""
|
||||
if [ "$IS_LIGHT" = "true" ]; then
|
||||
color_scheme="prefer-light"
|
||||
else
|
||||
color_scheme="prefer-dark"
|
||||
fi
|
||||
|
||||
update_theme_settings "$color_scheme" "$ICON_THEME"
|
||||
|
||||
echo "Matugen theme generation completed successfully"
|
||||
echo "Generated configs for detected tools:"
|
||||
[ -f "$CONFIG_DIR/gtk-3.0/dank-colors.css" ] && echo " - GTK 3/4 themes"
|
||||
[ -f "$(eval echo ~/.local/share/color-schemes/DankMatugen.colors)" ] && echo " - KDE color scheme"
|
||||
command -v niri >/dev/null 2>&1 && [ -f "$CONFIG_DIR/niri/dankshell-colors.kdl" ] && echo " - Niri compositor"
|
||||
command -v qt5ct >/dev/null 2>&1 && [ -f "$CONFIG_DIR/qt5ct/colors/matugen.conf" ] && echo " - Qt5ct themes"
|
||||
command -v qt6ct >/dev/null 2>&1 && [ -f "$CONFIG_DIR/qt6ct/colors/matugen.conf" ] && echo " - Qt6ct themes"
|
||||
command -v ghostty >/dev/null 2>&1 && [ -f "$CONFIG_DIR/ghostty/config-dankcolors" ] && echo " - Ghostty terminal"
|
||||
command -v kitty >/dev/null 2>&1 && [ -f "$CONFIG_DIR/kitty/dank-theme.conf" ] && echo " - Kitty terminal"
|
||||
command -v dgop >/dev/null 2>&1 && [ -f "$CONFIG_DIR/dgop/colors.json" ] && echo " - Dgop colors"
|
||||
Reference in New Issue
Block a user