-
Notifications
You must be signed in to change notification settings - Fork 10
/
change_color.sh
executable file
·317 lines (279 loc) · 9.31 KB
/
change_color.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/usr/bin/env bash
# shellcheck disable=SC1090
#set -x
set -ueo pipefail
SRC_PATH="$(readlink -f "$(dirname "$0")")"
darker() {
"$SRC_PATH/scripts/darker.sh" "$@"
}
mix() {
"$SRC_PATH/scripts/mix.sh" "$@"
}
is_dark() {
hexinput="$(tr '[:lower:]' '[:upper:]' <<< "$1")"
half_darker="$(darker "$hexinput" 88)"
[[ "$half_darker" == "000000" ]]
}
print_usage() {
echo "usage: $0 [-t TARGET_DIR] [-o OUTPUT_THEME_NAME] [-p PATH_LIST] PATH_TO_PRESET"
echo "examples:"
# shellcheck disable=SC2028 # This is meant to be usage text.
echo " $0 -o my-theme-name <(echo -e \"ROUNDNESS=0\\nBG=d8d8d8\\nFG=101010\\nHDR_BG=3c3c3c\\nHDR_FG=e6e6e6\\nSEL_BG=ad7fa8\\nMATERIA_VIEW=ffffff\\nMATERIA_SURFACE=f5f5f5\\nMATERIA_STYLE_COMPACT=True\\n\")"
echo " $0 -t ~/.themes ../colors/retro/twg"
echo " $0 --hidpi True ../colors/retro/clearlooks"
exit 1
}
while [[ "$#" -gt 0 ]]; do
case "$1" in
-p|--path-list)
CUSTOM_PATHLIST="$2"
shift
;;
-t|--target)
TARGET_DIR="$2"
shift
;;
-o|--output)
OUTPUT_THEME_NAME="$2"
shift
;;
-d|--hidpi)
OPTION_GTK2_HIDPI="$2"
shift
;;
-i|--inkscape)
OPTION_FORCE_INKSCAPE="$2"
shift
;;
*)
if [[ "$1" == -* ]] || [[ "${THEME-}" ]]; then
echo "unknown option $1"
print_usage
exit 2
fi
THEME="$1"
;;
esac
shift
done
if [[ -z "${THEME:-}" ]]; then
print_usage
fi
PATHLIST=(
'./src/_theme-color.scss'
'./src/chrome'
'./src/cinnamon'
'./src/cinnamon/assets'
'./src/gnome-shell'
'./src/gtk-2.0/assets.svg'
'./src/gtk-2.0/assets-dark.svg'
'./src/gtk-2.0/gtkrc'
'./src/gtk-2.0/gtkrc-dark'
'./src/gtk-2.0/gtkrc-light'
'./src/gtk-3.0/assets.svg'
'./src/metacity-1'
'./src/unity'
'./src/xfwm4'
)
if [[ -n "${CUSTOM_PATHLIST:-}" ]]; then
IFS=', ' read -r -a PATHLIST <<< "${CUSTOM_PATHLIST:-}"
fi
EXPORT_QT5CT=0
for FILEPATH in "${PATHLIST[@]}"; do
if [[ "$FILEPATH" == *qt5ct* ]]; then
EXPORT_QT5CT=1
fi
done
OPTION_GTK2_HIDPI=$(tr '[:upper:]' '[:lower:]' <<< "${OPTION_GTK2_HIDPI-False}")
OPTION_FORCE_INKSCAPE=$(tr '[:upper:]' '[:lower:]' <<< "${OPTION_FORCE_INKSCAPE-True}")
if [[ "$THEME" == */* ]] || [[ "$THEME" == *.* ]]; then
source "$THEME"
THEME=$(basename "$THEME")
else
if [[ -f "$SRC_PATH/../colors/$THEME" ]]; then
source "$SRC_PATH/../colors/$THEME"
else
echo "Theme '$THEME' not found"
exit 1
fi
fi
if [[ $(date +"%m%d") = "0401" ]] && grep -q "no-jokes" <<< "$*"; then
echo -e "\\n\\nError patching uxtheme.dll\\n\\n"
BG=C0C0C0 MATERIA_SURFACE=C0C0C0 FG=000000 MATERIA_PANEL_OPACITY=1
HDR_BG=C0C0C0 HDR_FG=000000 SEL_BG=000080 MATERIA_VIEW=FFFFFF
fi
# Migration:
HDR_BG=${HDR_BG-$MENU_BG}
HDR_FG=${HDR_FG-$MENU_FG}
MATERIA_VIEW=${MATERIA_VIEW-$TXT_BG}
MATERIA_SURFACE=${MATERIA_SURFACE-$BTN_BG}
GNOME_SHELL_PANEL_OPACITY=${GNOME_SHELL_PANEL_OPACITY-0.6}
MATERIA_PANEL_OPACITY=${MATERIA_PANEL_OPACITY-$GNOME_SHELL_PANEL_OPACITY}
MATERIA_STYLE_COMPACT=$(tr '[:upper:]' '[:lower:]' <<< "${MATERIA_STYLE_COMPACT-False}")
MATERIA_COLOR_VARIANT=$(tr '[:upper:]' '[:lower:]' <<< "${MATERIA_COLOR_VARIANT:-}")
SPACING=${SPACING-3}
ROUNDNESS=${ROUNDNESS-4}
# shellcheck disable=SC2034 # will this be used in the future?
ROUNDNESS_GTK2_HIDPI=$(( ROUNDNESS * 2 ))
MATERIA_PANEL_OPACITY=${MATERIA_PANEL_OPACITY-0.6}
MATERIA_SELECTION_OPACITY=${MATERIA_SELECTION_OPACITY-0.32}
INACTIVE_FG=$(mix "$FG" "$BG" 0.75)
INACTIVE_MATERIA_VIEW=$(mix "$MATERIA_VIEW" "$BG" 0.60)
TERMINAL_COLOR4=${TERMINAL_COLOR4:-1E88E5}
TERMINAL_COLOR5=${TERMINAL_COLOR5:-E040FB}
TERMINAL_COLOR9=${TERMINAL_COLOR9:-DD2C00}
TERMINAL_COLOR10=${TERMINAL_COLOR10:-00C853}
TERMINAL_COLOR11=${TERMINAL_COLOR11:-FF6D00}
TERMINAL_COLOR12=${TERMINAL_COLOR12:-66BB6A}
TARGET_DIR=${TARGET_DIR-$HOME/.themes}
OUTPUT_THEME_NAME=${OUTPUT_THEME_NAME-oomox-$THEME}
DEST_PATH="$TARGET_DIR/${OUTPUT_THEME_NAME/\//-}"
if [[ "$SRC_PATH" == "$DEST_PATH" ]]; then
echo "can't do that"
exit 1
fi
tempdir=$(mktemp -d)
post_clean_up() {
rm -r "$tempdir" || :
}
trap post_clean_up EXIT SIGHUP SIGINT SIGTERM
cp -r "$SRC_PATH/"* "$tempdir/"
cd "$tempdir"
# autodetection which color variant to use
if [[ -z "$MATERIA_COLOR_VARIANT" ]]; then
if is_dark "$BG"; then
echo "== Dark background color detected. Setting color variant to dark."
MATERIA_COLOR_VARIANT="dark"
elif is_dark "$HDR_BG"; then
echo "== Dark headerbar background color detected. Setting color variant to default."
MATERIA_COLOR_VARIANT="default"
else
echo "== Light background color detected. Setting color variant to light."
MATERIA_COLOR_VARIANT="light"
fi
fi
echo "== Converting theme into template..."
for FILEPATH in "${PATHLIST[@]}"; do
if [[ "$MATERIA_COLOR_VARIANT" != "dark" ]]; then
find "$FILEPATH" -type f -not -name '_color-palette.scss' -exec sed -i'' \
-e '/color-surface/{n;s/#ffffff/%MATERIA_SURFACE%/g}' \
-e '/color-base/{n;s/#ffffff/%MATERIA_VIEW%/g}' \
-e 's/#8ab4f8/%SEL_BG%/g' \
-e 's/#1967d2/%SEL_BG%/g' \
-e 's/#000000/%FG%/g' \
-e 's/#212121/%FG%/g' \
-e 's/#f9f9f9/%BG%/g' \
-e 's/#ffffff/%MATERIA_SURFACE%/g' \
-e 's/#ffffff/%MATERIA_VIEW%/g' \
-e 's/#424242/%HDR_BG%/g' \
-e 's/#303030/%HDR_BG2%/g' \
-e 's/#ffffff/%HDR_FG%/g' \
-e 's/#c1c1c1/%INACTIVE_FG%/g' \
-e 's/#f0f0f0/%HDR_BG%/g' \
-e 's/#ebebeb/%HDR_BG2%/g' \
-e 's/#1d1d1d/%HDR_FG%/g' \
-e 's/#565656/%INACTIVE_FG%/g' \
-e 's/Materia/%OUTPUT_THEME_NAME%/g' \
{} \; ;
else
find "$FILEPATH" -type f -not -name '_color-palette.scss' -exec sed -i'' \
-e 's/#8ab4f8/%SEL_BG%/g' \
-e 's/#ffffff/%FG%/g' \
-e 's/#eeeeee/%FG%/g' \
-e 's/#121212/%BG%/g' \
-e 's/#2e2e2e/%MATERIA_SURFACE%/g' \
-e 's/#1e1e1e/%MATERIA_VIEW%/g' \
-e 's/#272727/%HDR_BG%/g' \
-e 's/#1e1e1e/%HDR_BG2%/g' \
-e 's/#e4e4e4/%HDR_FG%/g' \
-e 's/#a7a7a7/%INACTIVE_FG%/g' \
-e 's/Materia/%OUTPUT_THEME_NAME%/g' \
{} \; ;
fi
done
#Not implemented yet:
#-e 's/%SPACING%/'"$SPACING"'/g' \
# shellcheck disable=SC2016
sed -i -e 's/^$corner-radius: .px/$corner-radius: '"$ROUNDNESS"'px/g' ./src/_theme.scss
if [[ "${DEBUG:-}" ]]; then
echo "You can debug TEMP DIR: $tempdir, press [Enter] when finished"; read -r
fi
mv ./src/_theme-color.template.scss ./src/_theme-color.scss
echo "== Filling the template with the new colorscheme..."
for FILEPATH in "${PATHLIST[@]}"; do
find "$FILEPATH" -type f -exec sed -i'' \
-e 's/%BG%/#'"$BG"'/g' \
-e 's/%BG2%/#'"$(darker $BG)"'/g' \
-e 's/%FG%/#'"$FG"'/g' \
-e 's/%SEL_BG%/#'"$SEL_BG"'/g' \
-e 's/%SEL_BG2%/#'"$(darker $SEL_BG -20)"'/g' \
-e 's/%MATERIA_VIEW%/#'"$MATERIA_VIEW"'/g' \
-e 's/%HDR_BG%/#'"$HDR_BG"'/g' \
-e 's/%HDR_BG2%/#'"$(darker $HDR_BG 10)"'/g' \
-e 's/%HDR_BG3%/#'"$(darker $HDR_BG 20)"'/g' \
-e 's/%HDR_FG%/#'"$HDR_FG"'/g' \
-e 's/%MATERIA_SURFACE%/#'"$MATERIA_SURFACE"'/g' \
-e 's/%SPACING%/'"$SPACING"'/g' \
-e 's/%INACTIVE_FG%/#'"$INACTIVE_FG"'/g' \
-e 's/%INACTIVE_MATERIA_VIEW%/#'"$INACTIVE_MATERIA_VIEW"'/g' \
-e 's/%TERMINAL_COLOR4%/#'"$TERMINAL_COLOR4"'/g' \
-e 's/%TERMINAL_COLOR5%/#'"$TERMINAL_COLOR5"'/g' \
-e 's/%TERMINAL_COLOR9%/#'"$TERMINAL_COLOR9"'/g' \
-e 's/%TERMINAL_COLOR10%/#'"$TERMINAL_COLOR10"'/g' \
-e 's/%TERMINAL_COLOR11%/#'"$TERMINAL_COLOR11"'/g' \
-e 's/%TERMINAL_COLOR12%/#'"$TERMINAL_COLOR12"'/g' \
-e 's/%MATERIA_SELECTION_OPACITY%/'"$MATERIA_SELECTION_OPACITY"'/g' \
-e 's/%MATERIA_PANEL_OPACITY%/'"$MATERIA_PANEL_OPACITY"'/g' \
-e 's/%OUTPUT_THEME_NAME%/'"$OUTPUT_THEME_NAME"'/g' \
{} \; ;
done
if [[ "$MATERIA_COLOR_VARIANT" == "default" ]]; then
COLOR_VARIANT="default"
COLOR_SUFFIX=""
fi
if [[ "$MATERIA_COLOR_VARIANT" == "light" ]]; then
COLOR_VARIANT="light"
COLOR_SUFFIX="-light"
fi
if [[ "$MATERIA_COLOR_VARIANT" == "dark" ]]; then
COLOR_VARIANT="dark"
COLOR_SUFFIX="-dark"
fi
if [[ "$OPTION_GTK2_HIDPI" == "true" ]]; then
mv ./src/gtk-2.0/main.rc.hidpi ./src/gtk-2.0/main.rc
fi
if [[ "$EXPORT_QT5CT" = 1 ]]; then
config_home=${XDG_CONFIG_HOME:-"$HOME/.config"}
qt5ct_colors_dir="$config_home/qt5ct/colors/"
test -d "$qt5ct_colors_dir" || mkdir -p "$qt5ct_colors_dir"
mv ./src/qt5ct_palette.conf "$qt5ct_colors_dir/$OUTPUT_THEME_NAME.conf"
fi
if [[ "$MATERIA_STYLE_COMPACT" == "true" ]]; then
SIZE_VARIANT="compact"
SIZE_SUFFIX="-compact"
else
SIZE_VARIANT="default"
SIZE_SUFFIX=""
fi
# NOTE we use the functions we already have in render-assets.sh
echo "== Rendering GTK 2 assets..."
if [[ "$MATERIA_COLOR_VARIANT" != "dark" ]]; then
FORCE_INKSCAPE="$OPTION_FORCE_INKSCAPE" GTK2_HIDPI="$OPTION_GTK2_HIDPI" ./render-assets.sh gtk2-light
else
FORCE_INKSCAPE="$OPTION_FORCE_INKSCAPE" GTK2_HIDPI="$OPTION_GTK2_HIDPI" ./render-assets.sh gtk2-dark
fi
echo "== Rendering GTK 3 assets..."
FORCE_INKSCAPE="$OPTION_FORCE_INKSCAPE" ./render-assets.sh gtk
meson _build -Dprefix="$tempdir" -Dcolors="$COLOR_VARIANT" -Dsizes="$SIZE_VARIANT"
meson install -C _build
GENERATED_PATH="$tempdir/share/themes/Materia$COLOR_SUFFIX$SIZE_SUFFIX"
if [[ -d "$DEST_PATH" ]]; then
rm -r "$DEST_PATH"
elif [[ ! -d "$DEST_PATH"/.. ]]; then
mkdir -p "$(readlink -f $DEST_PATH/..)"
fi
mv "$GENERATED_PATH" "$DEST_PATH"
echo
echo "== SUCCESS"
echo "== The theme was installed to '$DEST_PATH'"
exit 0