-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
96 lines (73 loc) · 3.46 KB
/
script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
####################################################
# INIT / CHECK
[ ! -d "$HOME/.local/share/themes" ] && echo "No themes in $HOME/.local/share/themes" && read -p "PRESS ENTER TO CLOSE" hold && exit
####################################################
# GET VALID THEMES
declare -a validThemeNamesArr=()
for indexThemeDir in $(find "$HOME/.local/share/themes" -type f -name 'index.theme'); do
themeDir=$(dirname "$indexThemeDir")
[ ! -d "$themeDir/gtk-4.0" ] && continue # no gtk-4.0 = theme won't be compatible
themeName=$(basename $themeDir)
validThemeNamesArr+=("$themeName")
done
validThemeNamesArr=($(printf '%s\n' "${validThemeNamesArr[@]}" | sort)) # sort array
validThemeNamesArr=('Reset' "${validThemeNamesArr[@]}") # add reset as the first option
####################################################
# GET DESIRED THEME USER INPUT
clear
echo "SELECT AN OPTION AND CLICK ENTER:"
for ((i=0; i<${#validThemeNamesArr[@]}; i++)); do
echo "[$i] ${validThemeNamesArr[$i]}"
done
while true; do
read tuin
tuin=$(echo "$tuin" | xargs) # trim
if [[ "$tuin" =~ ^[0-9]+$ && -v validThemeNamesArr[$tuin] ]]; then
break
else
echo "Invalid input, try again."
fi
done
####################################################
# APPLY THEME
chosenThemeName=${validThemeNamesArr[$tuin]}
# remove previous .bash-profile export - always done
grep -v "export GTK_THEME=" "$HOME/.bash_profile" > tmpfile && mv tmpfile "$HOME/.bash_profile"
if [[ "$tuin" == "0" ]]; then
gsettings reset org.gnome.desktop.interface gtk-theme
grep -v "GTK_THEME=" "$HOME/.local/share/flatpak/overrides/global" > tmpfile && mv tmpfile "$HOME/.local/share/flatpak/overrides/global"
clear
echo "CUSTOM USER THEME RESET"
echo "RESTART FOR EVERYTHING TO BE CHANGED"
else
# gsettings gtk (needed for window decorations in non-flatpak apps)
gsettings set org.gnome.desktop.interface gtk-theme "$chosenThemeName"
# add new export
echo "export GTK_THEME=$chosenThemeName" >> "$HOME/.bash_profile"
# flatpak
flatpak override --user --filesystem=xdg-data/themes # only way to give access to /.local/share/themes
flatpak override --user --env=GTK_THEME="$chosenThemeName"
echo "CUSTOM USER THEME APPLIED"
echo "LOGOUT FOR EVERYTHING TO BE CHANGED"
fi
echo "ALSO APPLY TO ROOT USER? y/N"
read suin
suin=$(echo "$suin" | xargs) # trim
suin=$(echo "$suin" | tr '[:upper:]' '[:lower:]') # lower case
if [[ "$suin" == "y" ]]; then
sudo [ ! -d "/root/.local/share/themes" ] && sudo mkdir -p "/root/.local/share/themes" # create root themes folder if not already there
sudo [ ! -d "/root/.local/share/themes/$chosenThemeName" ] && sudo cp -r "$HOME/.local/share/themes/$chosenThemeName" "/root/.local/share/themes/$chosenThemeName" # copy chosen theme to root if it's not there
# remove previous .bash-profile export - always done
sudo grep -v "export GTK_THEME=" "/root/.bash_profile" > tmpfile && sudo mv tmpfile "/root/.bash_profile"
if [[ "$tuin" == "0" ]]; then
sudo gsettings reset org.gnome.desktop.interface gtk-theme
else
# gsettings gtk (needed for window decorations in non-flatpak apps)
sudo gsettings set org.gnome.desktop.interface gtk-theme "$chosenThemeName"
# add new export
echo "export GTK_THEME=$chosenThemeName" | sudo tee --append "/root/.bash_profile" > /dev/null 2>&1
fi
echo "ROOT ACCOUNT UPDATED"
fi
read -p "PRESS ENTER TO CLOSE" hold