diff options
Diffstat (limited to 'config/hypr/scripts/Kitty_themes.sh')
| -rwxr-xr-x | config/hypr/scripts/Kitty_themes.sh | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/config/hypr/scripts/Kitty_themes.sh b/config/hypr/scripts/Kitty_themes.sh index 585bc7fc..8bc6e0f0 100755 --- a/config/hypr/scripts/Kitty_themes.sh +++ b/config/hypr/scripts/Kitty_themes.sh @@ -16,14 +16,20 @@ notify_user() { # Function to apply the selected kitty theme apply_kitty_theme_to_config() { local theme_name_to_apply="$1" + local apply_mode="${2:-preview}" if [ -z "$theme_name_to_apply" ]; then echo "Error: No theme name provided to apply_kitty_theme_to_config." >&2 return 1 fi + local theme_file_path_to_apply + if [ "$theme_name_to_apply" = "Set by wallpaper" ]; then + theme_file_path_to_apply="$kitty_themes_DiR/00-Default.conf" + else + theme_file_path_to_apply="$kitty_themes_DiR/$theme_name_to_apply.conf" + fi - local theme_file_path_to_apply="$kitty_themes_DiR/$theme_name_to_apply.conf" if [ ! -f "$theme_file_path_to_apply" ]; then - notify_user "$iDIR/error.png" "Error" "Theme file not found: $theme_name_to_apply.conf" + notify_user "$iDIR/error.png" "Error" "Theme file not found: $(basename "$theme_file_path_to_apply")" return 1 fi @@ -31,23 +37,31 @@ apply_kitty_theme_to_config() { temp_kitty_config_file=$(mktemp) cp "$kitty_config" "$temp_kitty_config_file" + local include_target + include_target="include ./kitty-themes/$(basename "$theme_file_path_to_apply")" + if grep -q -E '^[#[:space:]]*include\s+\./kitty-themes/.*\.conf' "$temp_kitty_config_file"; then - sed -i -E "s|^([#[:space:]]*include\s+\./kitty-themes/).*\.conf|include ./kitty-themes/$theme_name_to_apply.conf|g" "$temp_kitty_config_file" + sed -i -E "s|^([#[:space:]]*include\s+\./kitty-themes/).*\.conf|$include_target|g" "$temp_kitty_config_file" else if [ -s "$temp_kitty_config_file" ] && [ "$(tail -c1 "$temp_kitty_config_file")" != "" ]; then echo >>"$temp_kitty_config_file" fi - echo "include ./kitty-themes/$theme_name_to_apply.conf" >>"$temp_kitty_config_file" + echo "$include_target" >>"$temp_kitty_config_file" fi cp "$temp_kitty_config_file" "$kitty_config" rm "$temp_kitty_config_file" - - for pid_kitty in $(pidof kitty); do - if [ -n "$pid_kitty" ]; then - kill -SIGUSR1 "$pid_kitty" + if pidof kitty >/dev/null 2>&1; then + if [ "$apply_mode" = "apply" ] && command -v kitty >/dev/null 2>&1; then + kitty @ load-config >/dev/null 2>&1 + kitty @ set-colors --all --configured "$theme_file_path_to_apply" >/dev/null 2>&1 fi - done + for pid_kitty in $(pidof kitty); do + if [ -n "$pid_kitty" ]; then + kill -SIGUSR1 "$pid_kitty" + fi + done + fi return 0 } @@ -65,7 +79,8 @@ fi original_kitty_config_content_backup=$(cat "$kitty_config") -mapfile -t available_theme_names < <(find "$kitty_themes_DiR" -maxdepth 1 -name "*.conf" -type f -printf "%f\n" | sed 's/\.conf$//' | sort) +mapfile -t available_theme_names < <(find "$kitty_themes_DiR" -maxdepth 1 -name "*.conf" -type f -printf "%f\n" | sed 's/\.conf$//' | grep -v -E '^(00-Default|01-Wallust)$' | sort) +available_theme_names=("Set by wallpaper" "${available_theme_names[@]}") if [ ${#available_theme_names[@]} -eq 0 ]; then notify_user "$iDIR/error.png" "No Kitty Themes" "No .conf files found in $kitty_themes_DiR." @@ -73,7 +88,10 @@ if [ ${#available_theme_names[@]} -eq 0 ]; then fi current_selection_index=0 -current_active_theme_name=$(awk -F'include ./kitty-themes/|\\.conf' '/^[[:space:]]*include \.\/kitty-themes\/.*\.conf/{print $2; exit}' "$kitty_config") +current_active_theme_name=$(awk -F'include ./kitty-themes/|\\.conf' '/^[[:space:]]*include \\.\/kitty-themes\/.*\\.conf/{print $2; exit}' "$kitty_config") +if [ "$current_active_theme_name" = "00-Default" ]; then + current_active_theme_name="Set by wallpaper" +fi if [ -n "$current_active_theme_name" ]; then for i in "${!available_theme_names[@]}"; do @@ -85,14 +103,6 @@ if [ -n "$current_active_theme_name" ]; then fi while true; do - theme_to_preview_now="${available_theme_names[$current_selection_index]}" - - if ! apply_kitty_theme_to_config "$theme_to_preview_now"; then - echo "$original_kitty_config_content_backup" >"$kitty_config" - for pid_kitty in $(pidof kitty); do if [ -n "$pid_kitty" ]; then kill -SIGUSR1 "$pid_kitty"; fi; done - notify_user "$iDIR/error.png" "Preview Error" "Failed to apply $theme_to_preview_now. Reverted." - exit 1 - fi rofi_input_list="" for theme_name_in_list in "${available_theme_names[@]}"; do @@ -104,16 +114,24 @@ while true; do rofi -dmenu -i \ -format 'i' \ -p "Kitty Theme" \ - -mesg "Preview: ${theme_to_preview_now} | Enter: Preview | Ctrl+S: Apply & Exit | Esc: Cancel" \ + -mesg "Enter: Preview | Ctrl+S: Apply & Exit | Esc: Cancel" \ -config "$rofi_theme_for_this_script" \ -selected-row "$current_selection_index" \ - -kb-custom-1 "Control+s") # MODIFIED HERE: Changed to Control+s for custom action 1 + -kb-custom-1 "Control+s") rofi_exit_code=$? if [ $rofi_exit_code -eq 0 ]; then if [[ "$chosen_index_from_rofi" =~ ^[0-9]+$ ]] && [ "$chosen_index_from_rofi" -lt "${#available_theme_names[@]}" ]; then current_selection_index="$chosen_index_from_rofi" + theme_to_preview_now="${available_theme_names[$current_selection_index]}" + if ! apply_kitty_theme_to_config "$theme_to_preview_now" "preview"; then + echo "$original_kitty_config_content_backup" >"$kitty_config" + for pid_kitty in $(pidof kitty); do if [ -n "$pid_kitty" ]; then kill -SIGUSR1 "$pid_kitty"; fi; done + notify_user "$iDIR/error.png" "Preview Error" "Failed to apply $theme_to_preview_now. Reverted." + exit 1 + fi + continue else : fi @@ -123,6 +141,7 @@ while true; do for pid_kitty in $(pidof kitty); do if [ -n "$pid_kitty" ]; then kill -SIGUSR1 "$pid_kitty"; fi; done break elif [ $rofi_exit_code -eq 10 ]; then # This is the exit code for -kb-custom-1 + apply_kitty_theme_to_config "$theme_to_preview_now" "apply" notify_user "$iDIR/ja.png" "Kitty Theme Applied" "$theme_to_preview_now" break else |
