From fb57ba92ebe79eb94d6fcf1fc0a564721c32b964 Mon Sep 17 00:00:00 2001 From: ItsLemmy Date: Wed, 22 Oct 2025 22:55:38 -0400 Subject: [PATCH] ColorsApply: avoid modifying config(s) if unnecessary. --- Bin/colors-apply.sh | 61 +++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/Bin/colors-apply.sh b/Bin/colors-apply.sh index 00fe43b6..f31cdc27 100755 --- a/Bin/colors-apply.sh +++ b/Bin/colors-apply.sh @@ -23,13 +23,18 @@ case "$APP_NAME" in CONFIG_FILE="$HOME/.config/ghostty/config" # Check if the config file exists before trying to modify it. if [ -f "$CONFIG_FILE" ]; then - # Remove any existing theme include line to prevent duplicates. - sed -i '/theme/d' "$CONFIG_FILE" - # Add the new theme include line to the end of the file. - echo "theme = noctalia" >> "$CONFIG_FILE" - pkill -SIGUSR2 ghostty + # Check if theme is already set to noctalia + if grep -q "^theme = noctalia" "$CONFIG_FILE"; then + echo "Theme already set to noctalia, skipping modification." + else + # Remove any existing theme include line to prevent duplicates. + sed -i '/theme/d' "$CONFIG_FILE" + # Add the new theme include line to the end of the file. + echo "theme = noctalia" >> "$CONFIG_FILE" + pkill -SIGUSR2 ghostty + fi else - echo "Error: foot config file not found at $CONFIG_FILE" >&2 + echo "Error: ghostty config file not found at $CONFIG_FILE" >&2 exit 1 fi ;; @@ -40,15 +45,19 @@ case "$APP_NAME" in # Check if the config file exists before trying to modify it. if [ -f "$CONFIG_FILE" ]; then - # Remove any existing theme include line to prevent duplicates. - sed -i '/include=.*themes/d' "$CONFIG_FILE" - - if grep -q '^\[main\]' "$CONFIG_FILE"; then - # Insert the include line after the existing [main] section header - sed -i '/^\[main\]/a include=~/.config/foot/themes/noctalia' "$CONFIG_FILE" + # Check if theme is already set to noctalia + if grep -q "include=~/.config/foot/themes/noctalia" "$CONFIG_FILE"; then + echo "Theme already set to noctalia, skipping modification." else - # If [main] doesn't exist, create it at the beginning with the include - sed -i '1i [main]\ninclude=~/.config/foot/themes/noctalia\n' "$CONFIG_FILE" + # Remove any existing theme include line to prevent duplicates. + sed -i '/include=.*themes/d' "$CONFIG_FILE" + if grep -q '^\[main\]' "$CONFIG_FILE"; then + # Insert the include line after the existing [main] section header + sed -i '/^\[main\]/a include=~/.config/foot/themes/noctalia' "$CONFIG_FILE" + else + # If [main] doesn't exist, create it at the beginning with the include + sed -i '1i [main]\ninclude=~/.config/foot/themes/noctalia\n' "$CONFIG_FILE" + fi fi else echo "Error: foot config file not found at $CONFIG_FILE" >&2 @@ -62,10 +71,15 @@ case "$APP_NAME" in # Check if the config file exists. if [ -f "$CONFIG_FILE" ]; then - # Remove any existing theme include line. - sed -i '/themes/d' "$CONFIG_FILE" - # Add the new theme include line. - echo "include=~/.config/fuzzel/themes/noctalia" >> "$CONFIG_FILE" + # Check if theme is already set to noctalia + if grep -q "include=~/.config/fuzzel/themes/noctalia" "$CONFIG_FILE"; then + echo "Theme already set to noctalia, skipping modification." + else + # Remove any existing theme include line. + sed -i '/themes/d' "$CONFIG_FILE" + # Add the new theme include line. + echo "include=~/.config/fuzzel/themes/noctalia" >> "$CONFIG_FILE" + fi else echo "Error: fuzzel config file not found at $CONFIG_FILE" >&2 exit 1 @@ -73,11 +87,10 @@ case "$APP_NAME" in ;; vicinae) - echo "🎨 Applying 'matugen' theme to vicinae..." - - # Apply the theme - vicinae theme set matugen - ;; + echo "🎨 Applying 'matugen' theme to vicinae..." + # Apply the theme + vicinae theme set matugen + ;; pywalfox) echo "🎨 Updating pywalfox themes..." @@ -91,4 +104,4 @@ case "$APP_NAME" in ;; esac -echo "✅ Command sent for $APP_NAME." +echo "✅ Command sent for $APP_NAME." \ No newline at end of file