-
Notifications
You must be signed in to change notification settings - Fork 4
/
apply_theme.sh
executable file
·183 lines (165 loc) · 3.72 KB
/
apply_theme.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env bash
# #<---------------------------->
# # You must include this section when:
# # Distributing, Using and/or Modifying this code.
# # Please read and abide by the terms of the included LICENSE.
# # Copyright 2024, Deepankar Chakroborty, All rights reserved.
# #
# # Version : 0.3
# # Author : Deepankar Chakroborty (https://github.com/dchakro)
# # Report issues: https://github.com/dchakro/alacritty_colors/issues
# # License: https://github.com/dchakro/alacritty_colors/blob/master/LICENSE
# #<---------------------------->
# Set the directory where this is installed:
BASEDIR="${HOME}/scripts/alacritty_colors"
cd ${BASEDIR}
# Make a list of themes
declare -a arrFiles
cd themes
for file in *.toml; do
arrFiles=("${arrFiles[@]}" "$file")
done
cd ..
# Looks for configs everywhere Alacritty does by default
# If no config file is found in all the typical locations
# then it defaults to "$CONFIG" for backwards compatibilty
get_config() {
if [[ -f "$XDG_CONFIG_HOME/alacritty/alacritty.toml" ]]; then
echo "$XDG_CONFIG_HOME/alacritty/alacritty.toml"
elif [[ -f "$XDG_CONFIG_HOME/alacritty.toml" ]]; then
echo "$XDG_CONFIG_HOME/alacritty.toml"
elif [[ -f "$HOME/.config/alacritty/alacritty.toml" ]]; then
echo "$HOME/.config/alacritty/alacritty.toml"
else
[[ -f "$HOME/.alacritty.toml" ]]
echo "$HOME/.alacritty.toml"
fi
}
CONFIG=$(get_config)
RESET() {
# Copies ./base.toml
echo ""
echo "This will overwrite or create $CONFIG with ./base.toml"
while true; do
read -p "Restore base config (y/N): " backup_choice1
case $backup_choice1 in
[Yy]*)
cp ./base.toml $CONFIG
echo "Config reset to base!"
break
;;
[Nn]*)
echo "Reset aborted."
break
;;
*)
echo "Please answer with either Y/y or N/n."
;;
esac
done
}
BACKUP() {
# Backs up "$CONFIG" as ~/.alacritty.bak.toml
if [ ! -f "$CONFIG" ]; then
echo 'No config file found!'
RESET
fi
if [ ! -f ~/.alacritty.bak.toml ]; then
cp $CONFIG ~/.alacritty.bak.toml && echo "Config backup successful!"
else
while true; do
read -p "Backup exists. Overwrite? (y/N): " backup_choice2
case $backup_choice2 in
[Yy]*)
cp "$CONFIG" ~/.alacritty.bak.toml && echo "Backup overwrite successful!"
break
;;
[Nn]*)
echo "Backup aborted."
break
;;
*)
echo "Please answer with either Y/y or N/n."
;;
esac
done
fi
}
RESTORE() {
if [ -f ~/.alacritty.bak.toml ]; then
cp -f ~/.alacritty.bak.toml $CONFIG && echo "Config restored!"
else
echo "Backup config for alacritty does not exist!!"
exit 1
fi
}
LIST_THEMES() {
echo 'Availabe themes:'
declare -i counter
counter=1
for item in "${arrFiles[@]}"; do
echo "# ${counter} :${item}"
counter=($counter+1)
done
}
APPLY_THEMES() {
LIST_THEMES
read -p "Choose (default=1): " inp
if [ -z "${inp}" ]; then
inp=1
fi
inp=$((inp - 1)) # as array indices start from 0
echo ""
echo "Applying the theme: ${arrFiles[inp]}"
cat ./base.toml ./themes/${arrFiles[inp]} >|"$CONFIG"
bash ./show_colors.sh
while true; do
read -p "Keep changes (Y/n): " choice
case $choice in
[Yy]*)
echo "Theme set to: ${arrFiles[inp]}"
exit 0
;;
[Nn]*)
RESTORE
break
;;
*)
echo "Please answer with either Y/y or N/n."
;;
esac
done
}
while true; do
reset_choice=""
choice=""
backup_choice1=""
backup_choice2=""
inp=""
printf ' -- Apply alacritty themes --
1) Apply Themes
2) Backup configs
3) Restore from backup
4) Reset config (no defined color scheme)
5) Exit
Enter: '
read var
if [ "$var" -eq "1" ]; then
APPLY_THEMES
fi
if [ "$var" -eq "2" ]; then
BACKUP
exit 0
fi
if [ "$var" -eq "3" ]; then
RESTORE
exit 0
fi
if [ "$var" -eq "4" ]; then
RESET
exit 0
fi
if [ "$var" -eq "5" ]; then
exit 0
fi
done