merge feature/replace_sed

This commit is contained in:
Christian Schendel 2025-12-08 22:07:24 +00:00
commit 71485f4b1f
Signed by: doppelhelix
GPG key ID: 5874D2437CD5BBB3

View file

@ -74,6 +74,17 @@ if ! command -v gsettings >/dev/null 2>&1; then
echo -e "${red}==> ERROR:${all_off}${bold} ${mesg}${all_off}" echo -e "${red}==> ERROR:${all_off}${bold} ${mesg}${all_off}"
exit 1 exit 1
fi fi
if ! command -v /usr/lib/plasma-changeicons >/dev/null 2>&1; then
notify-send \
'Missing dependency' \
'plasma-changeicons not found.\nPlease install plasma-workspace.' \
-h string:x-canonical-private-synchronous:sys-notify \
-u critical \
-i dialog-error
mesg="plasma-workspace is required to use this script."
echo -e "${red}==> ERROR:${all_off}${bold} ${mesg}${all_off}"
exit 1
fi
check_config() { check_config() {
if [[ ! -f $default_config_file ]]; then if [[ ! -f $default_config_file ]]; then
@ -128,39 +139,35 @@ check_config() {
fi fi
} }
_reset_settings() {
## GTK3
gtk3_settings_file="$XDG_CONFIG_HOME/gtk-3.0/settings.ini"
gtk4_settings_file="$XDG_CONFIG_HOME/gtk-4.0/settings.ini"
qt6ct_settings_file="$XDG_CONFIG_HOME/qt6ct/qt6ct.conf"
gsettings reset org.gnome.desktop.interface color-scheme
gsettings reset org.gnome.desktop.interface gtk-theme
gsettings reset org.gnome.desktop.interface icon-theme
if [[ ! -w "$gtk3_settings_file" ]]; then
touch "$gtk3_settings_file"
fi
if [[ ! -w "$gtk4_settings_file" ]]; then
touch "$gtk4_settings_file"
fi
if [[ ! -w "$qt6ct_settings_file" ]]; then
touch "$qt6ct_settings_file"
fi
}
_set_theme() { _set_theme() {
## gtk-theme ## GTK
gsettings set org.gnome.desktop.interface color-scheme "$gtk_color_scheme" gsettings set org.gnome.desktop.interface color-scheme "$gtk_color_scheme"
gsettings set org.gnome.desktop.interface gtk-theme "$gtk_theme" gsettings set org.gnome.desktop.interface gtk-theme "$gtk_theme"
gsettings set org.gnome.desktop.interface icon-theme "$icon_theme" gsettings set org.gnome.desktop.interface icon-theme "$icon_theme"
## GTK2
if [[ -w "$HOME/.gtkrc-2.0" ]]; then
sed -i "s/gtk-theme-name=.*/gtk-theme-name=$gtk_theme/g" \
"$HOME/.gtkrc-2.0"
sed -i "s/gtk-icon-theme-name=.*/gtk-icon-theme-name=$icon_theme/g" \
"$HOME/.gtkrc-2.0"
fi
## GTK3
if [[ -w "$HOME/.config/gtk-3.0/settings.ini" ]]; then
sed -i "s/gtk-application-prefer-dark-theme=.*/gtk-application-prefer-dark-theme=$gtk_prefer_dark_theme/g" \
"$HOME/.config/gtk-3.0/settings.ini"
sed -i "s/gtk-theme-name=.*/gtk-theme-name=$gtk_theme/g" \
"$HOME/.config/gtk-3.0/settings.ini"
sed -i "s/gtk-icon-theme-name=.*/gtk-icon-theme-name=$icon_theme/g" \
"$HOME/.config/gtk-3.0/settings.ini"
fi
## GTK4
if [[ -w "$HOME/.config/gtk-4.0/settings.ini" ]]; then
sed -i "s/gtk-application-prefer-dark-theme=.*/gtk-application-prefer-dark-theme=$gtk_prefer_dark_theme/g" \
"$HOME/.config/gtk-4.0/settings.ini"
sed -i "s/gtk-icon-theme-name=.*/gtk-icon-theme-name=$icon_theme/g" \
"$HOME/.config/gtk-4.0/settings.ini"
sed -i "s/gtk-theme-name=.*/gtk-theme-name=$gtk_theme/g" \
"$HOME/.config/gtk-4.0/settings.ini"
fi
## QT ## QT
/usr/lib/plasma-changeicons "$icon_theme" >/dev/null 2>&1
if [[ -w "$HOME/.config/qt5ct/qt5ct.conf" ]]; then if [[ -w "$HOME/.config/qt5ct/qt5ct.conf" ]]; then
sed -i "s/icon_theme=.*/icon_theme=$icon_theme/g" \ sed -i "s/icon_theme=.*/icon_theme=$icon_theme/g" \
"$HOME/.config/qt5ct/qt5ct.conf" "$HOME/.config/qt5ct/qt5ct.conf"
@ -175,10 +182,6 @@ _set_theme() {
sed -i "s,color_scheme_path=.*,color_scheme_path=$qt_color_scheme_path,g" \ sed -i "s,color_scheme_path=.*,color_scheme_path=$qt_color_scheme_path,g" \
"$HOME/.config/qt6ct/qt6ct.conf" "$HOME/.config/qt6ct/qt6ct.conf"
fi fi
## workaround if plasma-workspace is installed
if [ -x "$(command -v /usr/lib/plasma-changeicon)" ]; then
/usr/lib/plasma-changeicons "$icon_theme"
fi
} }
switch-dark-light() { switch-dark-light() {
@ -186,7 +189,7 @@ switch-dark-light() {
if [[ ! $gtk_color_scheme == ''\''prefer-dark'\''' ]]; then if [[ ! $gtk_color_scheme == ''\''prefer-dark'\''' ]]; then
gtk_color_scheme=prefer-dark gtk_color_scheme=prefer-dark
gtk_prefer_dark_theme=true gtk_prefer_dark_theme=1
gtk_theme=$gtk_theme_dark gtk_theme=$gtk_theme_dark
icon_theme=$icon_theme_dark icon_theme=$icon_theme_dark
qt_custom_palette=true qt_custom_palette=true
@ -194,7 +197,7 @@ switch-dark-light() {
_set_theme _set_theme
else else
gtk_color_scheme=default gtk_color_scheme=default
gtk_prefer_dark_theme=false gtk_prefer_dark_theme=0
gtk_theme=$gtk_theme_light gtk_theme=$gtk_theme_light
icon_theme=$icon_theme_light icon_theme=$icon_theme_light
qt_custom_palette=true qt_custom_palette=true
@ -210,7 +213,7 @@ restore-theme-on-login() {
if [[ ! $gtk_color_scheme == ''\''prefer-dark'\''' ]]; then if [[ ! $gtk_color_scheme == ''\''prefer-dark'\''' ]]; then
gtk_color_scheme=default gtk_color_scheme=default
gtk_prefer_dark_theme=false gtk_prefer_dark_theme=0
gtk_theme=$gtk_theme_light gtk_theme=$gtk_theme_light
icon_theme=$icon_theme_light icon_theme=$icon_theme_light
qt_custom_palette=true qt_custom_palette=true
@ -218,7 +221,7 @@ restore-theme-on-login() {
_set_theme _set_theme
else else
gtk_color_scheme=prefer-dark gtk_color_scheme=prefer-dark
gtk_prefer_dark_theme=true gtk_prefer_dark_theme=1
gtk_theme=$gtk_theme_dark gtk_theme=$gtk_theme_dark
icon_theme=$icon_theme_dark icon_theme=$icon_theme_dark
qt_custom_palette=true qt_custom_palette=true
@ -269,6 +272,9 @@ case "$1" in
r) r)
check_config && restore-theme-on-login check_config && restore-theme-on-login
;; ;;
c)
check_config && _reset_settings && preview
;;
p) p)
check_config && preview check_config && preview
;; ;;
@ -279,6 +285,7 @@ case "$1" in
echo echo
echo -e "${bold} s) swith between dark and light theme${all_off}" echo -e "${bold} s) swith between dark and light theme${all_off}"
echo -e "${bold} r) restore theme (usefull only once after login)${all_off}" echo -e "${bold} r) restore theme (usefull only once after login)${all_off}"
echo -e "${bold} c) create sane default GTK/qt6ct settings files${all_off}"
echo -e "${bold} p) Preview settings${all_off}" echo -e "${bold} p) Preview settings${all_off}"
;; ;;
esac esac