irongit
hygoland/scripts/DarkLight.sh
253 lines8.6 KBBourne Again Shell (bash)
1#!/bin/bash
2## /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ##
3# For Dark and Light switching
4# Note: Scripts are looking for keywords Light or Dark except for wallpapers as the are in a separate directories
5
6# Paths
7wallpaper_base_path="$HOME/Pictures/wallpapers/Dynamic-Wallpapers"
8dark_wallpapers="$wallpaper_base_path/Dark"
9light_wallpapers="$wallpaper_base_path/Light"
10hypr_config_path="$HOME/.config/hypr"
11swaync_style="$HOME/.config/swaync/style.css"
12ags_style="$HOME/.config/ags/user/style.css"
13SCRIPTSDIR="$HOME/.config/hypr/scripts"
14notif="$HOME/.config/swaync/images/bell.png"
15wallust_rofi="$HOME/.config/wallust/templates/colors-rofi.rasi"
16
17kitty_conf="$HOME/.config/kitty/kitty.conf"
18
19wallust_config="$HOME/.config/wallust/wallust.toml"
20pallete_dark="dark16"
21pallete_light="light16"
22
23# intial kill process
24for pid in waybar rofi swaync ags swaybg; do
25 killall -SIGUSR1 "$pid"
26done
27
28
29# Initialize swww if needed
30swww query || swww-daemon --format xrgb
31
32# Set swww options
33swww="swww img"
34effect="--transition-bezier .43,1.19,1,.4 --transition-fps 60 --transition-type grow --transition-pos 0.925,0.977 --transition-duration 2"
35
36# Determine current theme mode
37if [ "$(cat $HOME/.cache/.theme_mode)" = "Light" ]; then
38 next_mode="Dark"
39 # Logic for Dark mode
40 wallpaper_path="$dark_wallpapers"
41else
42 next_mode="Light"
43 # Logic for Light mode
44 wallpaper_path="$light_wallpapers"
45fi
46
47# Function to update theme mode for the next cycle
48update_theme_mode() {
49 echo "$next_mode" > "$HOME/.cache/.theme_mode"
50}
51
52# Function to notify user
53notify_user() {
54 notify-send -u low -i "$notif" " Switching to" " $1 mode"
55}
56
57# Use sed to replace the palette setting in the wallust config file
58if [ "$next_mode" = "Dark" ]; then
59 sed -i 's/^palette = .*/palette = "'"$pallete_dark"'"/' "$wallust_config"
60else
61 sed -i 's/^palette = .*/palette = "'"$pallete_light"'"/' "$wallust_config"
62fi
63
64# Function to set Waybar style
65set_waybar_style() {
66 theme="$1"
67 waybar_styles="$HOME/.config/waybar/style"
68 waybar_style_link="$HOME/.config/waybar/style.css"
69 style_prefix="\\[${theme}\\].*\\.css$"
70
71 style_file=$(find -L "$waybar_styles" -maxdepth 1 -type f -regex ".*$style_prefix" | shuf -n 1)
72
73 if [ -n "$style_file" ]; then
74 ln -sf "$style_file" "$waybar_style_link"
75 else
76 echo "Style file not found for $theme theme."
77 fi
78}
79
80# Call the function after determining the mode
81set_waybar_style "$next_mode"
82notify_user "$next_mode"
83
84
85# swaync color change
86if [ "$next_mode" = "Dark" ]; then
87 sed -i '/@define-color noti-bg/s/rgba([0-9]*,\s*[0-9]*,\s*[0-9]*,\s*[0-9.]*);/rgba(0, 0, 0, 0.8);/' "${swaync_style}"
88 #sed -i '/@define-color noti-bg-alt/s/#.*;/#111111;/' "${swaync_style}"
89else
90 sed -i '/@define-color noti-bg/s/rgba([0-9]*,\s*[0-9]*,\s*[0-9]*,\s*[0-9.]*);/rgba(255, 255, 255, 0.9);/' "${swaync_style}"
91 #sed -i '/@define-color noti-bg-alt/s/#.*;/#F0F0F0;/' "${swaync_style}"
92fi
93
94# ags color change
95if command -v ags >/dev/null 2>&1; then
96 if [ "$next_mode" = "Dark" ]; then
97 sed -i '/@define-color noti-bg/s/rgba([0-9]*,\s*[0-9]*,\s*[0-9]*,\s*[0-9.]*);/rgba(0, 0, 0, 0.4);/' "${ags_style}"
98 sed -i '/@define-color text-color/s/rgba([0-9]*,\s*[0-9]*,\s*[0-9]*,\s*[0-9.]*);/rgba(255, 255, 255, 0.7);/' "${ags_style}"
99 sed -i '/@define-color noti-bg-alt/s/#.*;/#111111;/' "${ags_style}"
100 else
101 sed -i '/@define-color noti-bg/s/rgba([0-9]*,\s*[0-9]*,\s*[0-9]*,\s*[0-9.]*);/rgba(255, 255, 255, 0.4);/' "${ags_style}"
102 sed -i '/@define-color text-color/s/rgba([0-9]*,\s*[0-9]*,\s*[0-9]*,\s*[0-9.]*);/rgba(0, 0, 0, 0.7);/' "${ags_style}"
103 sed -i '/@define-color noti-bg-alt/s/#.*;/#F0F0F0;/' "${ags_style}"
104 fi
105fi
106
107# kitty background color change
108if [ "$next_mode" = "Dark" ]; then
109 sed -i '/^foreground /s/^foreground .*/foreground #dddddd/' "${kitty_conf}"
110 sed -i '/^background /s/^background .*/background #000000/' "${kitty_conf}"
111 sed -i '/^cursor /s/^cursor .*/cursor #dddddd/' "${kitty_conf}"
112else
113 sed -i '/^foreground /s/^foreground .*/foreground #000000/' "${kitty_conf}"
114 sed -i '/^background /s/^background .*/background #dddddd/' "${kitty_conf}"
115 sed -i '/^cursor /s/^cursor .*/cursor #000000/' "${kitty_conf}"
116fi
117
118for pid_kitty in $(pidof kitty); do
119 kill -SIGUSR1 "$pid_kitty"
120done
121
122# Set Dynamic Wallpaper for Dark or Light Mode
123if [ "$next_mode" = "Dark" ]; then
124 next_wallpaper="$(find -L "${dark_wallpapers}" -type f \( -iname "*.jpg" -o -iname "*.png" \) -print0 | shuf -n1 -z | xargs -0)"
125else
126 next_wallpaper="$(find -L "${light_wallpapers}" -type f \( -iname "*.jpg" -o -iname "*.png" \) -print0 | shuf -n1 -z | xargs -0)"
127fi
128
129# Update wallpaper using swww command
130$swww "${next_wallpaper}" $effect
131
132
133# Set Kvantum Manager theme & QT5/QT6 settings
134if [ "$next_mode" = "Dark" ]; then
135 kvantum_theme="catppuccin-mocha-blue"
136 #qt5ct_color_scheme="$HOME/.config/qt5ct/colors/Catppuccin-Mocha.conf"
137 #qt6ct_color_scheme="$HOME/.config/qt6ct/colors/Catppuccin-Mocha.conf"
138else
139 kvantum_theme="catppuccin-latte-blue"
140 #qt5ct_color_scheme="$HOME/.config/qt5ct/colors/Catppuccin-Latte.conf"
141 #qt6ct_color_scheme="$HOME/.config/qt6ct/colors/Catppuccin-Latte.conf"
142fi
143
144sed -i "s|^color_scheme_path=.*$|color_scheme_path=$qt5ct_color_scheme|" "$HOME/.config/qt5ct/qt5ct.conf"
145sed -i "s|^color_scheme_path=.*$|color_scheme_path=$qt6ct_color_scheme|" "$HOME/.config/qt6ct/qt6ct.conf"
146kvantummanager --set "$kvantum_theme"
147
148
149# set the rofi color for background
150if [ "$next_mode" = "Dark" ]; then
151 sed -i '/^background:/s/.*/background: rgba(0,0,0,0.7);/' $wallust_rofi
152else
153 sed -i '/^background:/s/.*/background: rgba(255,255,255,0.9);/' $wallust_rofi
154fi
155
156
157# GTK themes and icons switching
158set_custom_gtk_theme() {
159 mode=$1
160 gtk_themes_directory="$HOME/.themes"
161 icon_directory="$HOME/.icons"
162 color_setting="org.gnome.desktop.interface color-scheme"
163 theme_setting="org.gnome.desktop.interface gtk-theme"
164 icon_setting="org.gnome.desktop.interface icon-theme"
165
166 if [ "$mode" == "Light" ]; then
167 search_keywords="*Light*"
168 gsettings set $color_setting 'prefer-light'
169 elif [ "$mode" == "Dark" ]; then
170 search_keywords="*Dark*"
171 gsettings set $color_setting 'prefer-dark'
172 else
173 echo "Invalid mode provided."
174 return 1
175 fi
176
177 themes=()
178 icons=()
179
180 while IFS= read -r -d '' theme_search; do
181 themes+=("$(basename "$theme_search")")
182 done < <(find "$gtk_themes_directory" -maxdepth 1 -type d -iname "$search_keywords" -print0)
183
184 while IFS= read -r -d '' icon_search; do
185 icons+=("$(basename "$icon_search")")
186 done < <(find "$icon_directory" -maxdepth 1 -type d -iname "$search_keywords" -print0)
187
188 if [ ${#themes[@]} -gt 0 ]; then
189 if [ "$mode" == "Dark" ]; then
190 selected_theme=${themes[RANDOM % ${#themes[@]}]}
191 else
192 selected_theme=${themes[$RANDOM % ${#themes[@]}]}
193 fi
194 echo "Selected GTK theme for $mode mode: $selected_theme"
195 gsettings set $theme_setting "$selected_theme"
196
197 # Flatpak GTK apps (themes)
198 if command -v flatpak &> /dev/null; then
199 flatpak --user override --filesystem=$HOME/.themes
200 sleep 0.5
201 flatpak --user override --env=GTK_THEME="$selected_theme"
202 fi
203 else
204 echo "No $mode GTK theme found"
205 fi
206
207 if [ ${#icons[@]} -gt 0 ]; then
208 if [ "$mode" == "Dark" ]; then
209 selected_icon=${icons[RANDOM % ${#icons[@]}]}
210 else
211 selected_icon=${icons[$RANDOM % ${#icons[@]}]}
212 fi
213 echo "Selected icon theme for $mode mode: $selected_icon"
214 gsettings set $icon_setting "$selected_icon"
215
216 ## QT5ct icon_theme
217 sed -i "s|^icon_theme=.*$|icon_theme=$selected_icon|" "$HOME/.config/qt5ct/qt5ct.conf"
218 sed -i "s|^icon_theme=.*$|icon_theme=$selected_icon|" "$HOME/.config/qt6ct/qt6ct.conf"
219
220 # Flatpak GTK apps (icons)
221 if command -v flatpak &> /dev/null; then
222 flatpak --user override --filesystem=$HOME/.icons
223 sleep 0.5
224 flatpak --user override --env=ICON_THEME="$selected_icon"
225 fi
226 else
227 echo "No $mode icon theme found"
228 fi
229}
230
231# Call the function to set GTK theme and icon theme based on mode
232set_custom_gtk_theme "$next_mode"
233
234# Update theme mode for the next cycle
235update_theme_mode
236
237
238${SCRIPTSDIR}/WallustSwww.sh &&
239
240sleep 2
241# kill process
242for pid1 in waybar rofi swaync ags swaybg; do
243 killall "$pid1"
244done
245
246sleep 1
247${SCRIPTSDIR}/Refresh.sh
248
249sleep 0.5
250# Display notifications for theme and icon changes
251notify-send -u low -i "$notif" " Themes switched to:" " $next_mode Mode"
252
253exit 0