forked from nana-4/materia-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_color.sh
executable file
·272 lines (241 loc) · 8.08 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
#!/usr/bin/env bash
#set -x
set -ue
SRC_PATH=$(readlink -f $(dirname $0))
darker () {
"${SRC_PATH}/scripts/darker.sh" $@
}
mix () {
"${SRC_PATH}/scripts/mix.sh" $@
}
print_usage() {
echo "usage: $0 [-o OUTPUT_THEME_NAME] [-p PATH_LIST] PATH_TO_PRESET"
echo "examples:"
echo " $0 -o my-theme-name <(echo -e "BG=d8d8d8\\nFG=101010\\nMENU_BG=3c3c3c\\nMENU_FG=e6e6e6\\nSEL_BG=ad7fa8\\nSEL_FG=ffffff\\nTXT_BG=ffffff\\nTXT_FG=1a1a1a\\nBTN_BG=f5f5f5\\nBTN_FG=111111\\n")"
echo " $0 ../colors/retro/twg"
exit 1
}
while [[ $# > 0 ]]
do
case ${1} in
-p|--path-list)
CUSTOM_PATHLIST="${2}"
shift
;;
-o|--output)
OUTPUT_THEME_NAME="${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/gtk-2.0/gtkrc'
'./src/gtk-2.0/gtkrc-dark'
'./src/gtk-2.0/gtkrc-light'
'./src/gtk-3.0/3.22/sass/_colors.scss'
'./src/gnome-shell/3.18/sass/_colors.scss'
'./src/gtk-2.0/assets.svg'
'./src/gtk-2.0/assets-dark.svg'
'./src/gtk-3.0/gtk-common/assets.svg'
)
if [ ! -z "${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
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
ACCENT_BG=${ACCENT_BG-$SEL_BG}
HDR_BTN_BG=${HDR_BTN_BG-$BTN_BG}
HDR_BTN_FG=${HDR_BTN_FG-$BTN_FG}
WM_BORDER_FOCUS=${WM_BORDER_FOCUS-$SEL_BG}
WM_BORDER_UNFOCUS=${WM_BORDER_UNFOCUS-$MENU_BG}
FLATPACK_STYLE_COMPACT=$(echo ${FLATPACK_STYLE_COMPACT-True} | tr '[:upper:]' '[:lower:]')
GTK3_GENERATE_DARK=$(echo ${GTK3_GENERATE_DARK-True} | tr '[:upper:]' '[:lower:]')
GTK2_HIDPI=$(echo ${GTK2_HIDPI-False} | tr '[:upper:]' '[:lower:]')
UNITY_DEFAULT_LAUNCHER_STYLE=$(echo ${UNITY_DEFAULT_LAUNCHER_STYLE-False} | tr '[:upper:]' '[:lower:]')
SPACING=${SPACING-3}
GRADIENT=${GRADIENT-0}
ROUNDNESS=${ROUNDNESS-2}
ROUNDNESS_GTK2_HIDPI=$(( ${ROUNDNESS} * 2 ))
INACTIVE_FG=$(mix ${FG} ${BG} 0.75)
INACTIVE_MENU_FG=$(mix ${MENU_FG} ${MENU_BG} 0.75)
INACTIVE_TXT_FG=$(mix ${TXT_FG} ${TXT_BG} 0.75)
light_folder_base_fallback="$(darker ${SEL_BG} -10)"
medium_base_fallback="$(darker ${SEL_BG} 37)"
dark_stroke_fallback="$(darker ${SEL_BG} 50)"
ICONS_LIGHT_FOLDER="${ICONS_LIGHT_FOLDER-$light_folder_base_fallback}"
ICONS_LIGHT="${ICONS_LIGHT-$SEL_BG}"
ICONS_MEDIUM="${ICONS_MEDIUM-$medium_base_fallback}"
ICONS_DARK="${ICONS_DARK-$dark_stroke_fallback}"
CARET1_FG="${CARET1_FG-$TXT_FG}"
CARET2_FG="${CARET2_FG-$TXT_FG}"
CARET_SIZE="${CARET_SIZE-0.04}"
OUTPUT_THEME_NAME="${OUTPUT_THEME_NAME-oomox-$THEME}"
DEST_PATH="$HOME/.themes/${OUTPUT_THEME_NAME/\//-}"
test "$SRC_PATH" = "$DEST_PATH" && echo "can't do that" && exit 1
#rm -r "$DEST_PATH" || true
mkdir -p "$DEST_PATH"
tempdir=$(mktemp -d)
function post_clean_up {
rm -r "${tempdir}" || true
}
trap post_clean_up EXIT SIGHUP SIGINT SIGTERM
cp -r ${SRC_PATH}/* ${tempdir}/
cd ${tempdir}
echo "== Converting theme into template..."
for FILEPATH in "${PATHLIST[@]}"; do
find "${FILEPATH}" -type f -exec sed -i'' \
-e 's/$grey_100/%BG%/g' \
-e 's/#F5F5F5/%BG%/g' \
-e 's/$grey_200/%BG2%/g' \
-e 's/$black/%FG%/g' \
-e 's/$grey_900/%FG%/g' \
-e 's/#212121/%FG%/g' \
-e 's/$pink_A200/%ACCENT_BG%/g' \
-e 's/#FF4081/%ACCENT_BG%/g' \
-e 's/$blue_400/%SEL_BG%/g' \
-e 's/#42A5F5/%SEL_BG%/g' \
-e 's/$light_blue_A200/%SEL_BG2%/g' \
-e 's/$white/%TXT_BG%/g' \
-e 's/#FFFFFF/%TXT_BG%/g' \
-e 's/$black/%TXT_FG%/g' \
-e 's/#000000/%TXT_FG%/g' \
-e 's/$blue_grey_700/%MENU_BG%/g' \
-e 's/#333e43/%MENU_BG%/g' \
-e 's/#455A64/%MENU_BG%/g' \
-e 's/$blue_grey_800/%MENU_BG2%/g' \
-e 's/#3b484e/%MENU_BG2%/g' \
-e 's/$blue_grey_900/%MENU_BG3%/g' \
-e 's/#414f56/%MENU_BG3%/g' \
-e 's/$grey_50/%BTN_BG%/g' \
-e 's/#FAFAFA/%BTN_BG%/g' \
-e 's/Flat-Plat/%OUTPUT_THEME_NAME%/g' \
{} \; ;
done
#Not implemented yet:
#-e 's/%SEL_FG%/'"$SEL_FG"'/g' \
#-e 's/%MENU_FG%/'"$MENU_FG"'/g' \
#-e 's/%BTN_FG%/'"$BTN_FG"'/g' \
#-e 's/%HDR_BTN_BG%/'"$HDR_BTN_BG"'/g' \
#-e 's/%HDR_BTN_FG%/'"$HDR_BTN_FG"'/g' \
#-e 's/%WM_BORDER_FOCUS%/'"$WM_BORDER_FOCUS"'/g' \
#-e 's/%WM_BORDER_UNFOCUS%/'"$WM_BORDER_UNFOCUS"'/g' \
#-e 's/%ROUNDNESS%/'"$ROUNDNESS"'/g' \
#-e 's/%ROUNDNESS_GTK2_HIDPI%/'"$ROUNDNESS_GTK2_HIDPI"'/g' \
#-e 's/%SPACING%/'"$SPACING"'/g' \
#-e 's/%GRADIENT%/'"$GRADIENT"'/g' \
#-e 's/%INACTIVE_FG%/'"$INACTIVE_FG"'/g' \
#-e 's/%INACTIVE_TXT_FG%/'"$INACTIVE_TXT_FG"'/g' \
#-e 's/%INACTIVE_MENU_FG%/'"$INACTIVE_MENU_FG"'/g' \
#-e 's/%ICONS_DARK%/'"$ICONS_DARK"'/g' \
#-e 's/%ICONS_MEDIUM%/'"$ICONS_MEDIUM"'/g' \
#-e 's/%ICONS_LIGHT%/'"$ICONS_LIGHT"'/g' \
#-e 's/%ICONS_LIGHT_FOLDER%/'"$ICONS_LIGHT_FOLDER"'/g' \
#echo "You can debug TEMP DIR: ${tempdir}, press [Enter] when finish" && read
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/%ACCENT_BG%/#'"$ACCENT_BG"'/g' \
-e 's/%SEL_BG%/#'"$SEL_BG"'/g' \
-e 's/%SEL_BG2%/#'"$(darker $SEL_BG -20)"'/g' \
-e 's/%SEL_FG%/#'"$SEL_FG"'/g' \
-e 's/%TXT_BG%/#'"$TXT_BG"'/g' \
-e 's/%TXT_FG%/#'"$TXT_FG"'/g' \
-e 's/%MENU_BG%/#'"$MENU_BG"'/g' \
-e 's/%MENU_BG2%/#'"$(darker $MENU_BG 10)"'/g' \
-e 's/%MENU_BG3%/#'"$(darker $MENU_BG 20)"'/g' \
-e 's/%MENU_FG%/#'"$MENU_FG"'/g' \
-e 's/%BTN_BG%/#'"$BTN_BG"'/g' \
-e 's/%BTN_FG%/#'"$BTN_FG"'/g' \
-e 's/%HDR_BTN_BG%/#'"$HDR_BTN_BG"'/g' \
-e 's/%HDR_BTN_FG%/#'"$HDR_BTN_FG"'/g' \
-e 's/%WM_BORDER_FOCUS%/#'"$WM_BORDER_FOCUS"'/g' \
-e 's/%WM_BORDER_UNFOCUS%/#'"$WM_BORDER_UNFOCUS"'/g' \
-e 's/%ROUNDNESS%/'"$ROUNDNESS"'/g' \
-e 's/%ROUNDNESS_GTK2_HIDPI%/'"$ROUNDNESS_GTK2_HIDPI"'/g' \
-e 's/%SPACING%/'"$SPACING"'/g' \
-e 's/%GRADIENT%/'"$GRADIENT"'/g' \
-e 's/%INACTIVE_FG%/#'"$INACTIVE_FG"'/g' \
-e 's/%INACTIVE_TXT_FG%/#'"$INACTIVE_TXT_FG"'/g' \
-e 's/%INACTIVE_MENU_FG%/#'"$INACTIVE_MENU_FG"'/g' \
-e 's/%ICONS_DARK%/#'"$ICONS_DARK"'/g' \
-e 's/%ICONS_MEDIUM%/#'"$ICONS_MEDIUM"'/g' \
-e 's/%ICONS_LIGHT%/#'"$ICONS_LIGHT"'/g' \
-e 's/%ICONS_LIGHT_FOLDER%/#'"$ICONS_LIGHT_FOLDER"'/g' \
-e 's/%OUTPUT_THEME_NAME%/'"$OUTPUT_THEME_NAME"'/g' \
{} \; ;
done
rm ./src/gtk-3.0/3.{18,20,22}/*.css
rm ./src/gtk-3.0/3.{18,20,22}/gtk-light*.scss
if [[ ${GTK3_GENERATE_DARK} != "true" ]] ; then
grep -v "\-dark" ./src/gtk-3.0/gtk-common/assets.txt > ./new_assets.txt
mv ./new_assets.txt ./src/gtk-3.0/gtk-common/assets.txt
rm ./src/gtk-3.0/3.{20,22}/gtk-dark-compact.scss
rm ./src/gtk-3.0/3.{18,20,22}/gtk-dark.scss
fi
if [[ ${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:-}
if [[ -z "${config_home}" ]] ; then
config_home="${HOME}/.config"
fi
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 [[ ${UNITY_DEFAULT_LAUNCHER_STYLE} == "true" ]] ; then
rm ./src/unity/launcher*.svg
fi
if [[ ${FLATPACK_STYLE_COMPACT} == "true" ]] ; then
SIZE_VARIANTS="-compact"
else
SIZE_VARIANTS=","
fi
SIZE_VARIANTS="${SIZE_VARIANTS}" COLOR_VARIANTS="," THEME_DIR_BASE=${DEST_PATH} ./parse-sass.sh
rm ./src/gtk-2.0/assets/*.png || true
rm ./src/gtk-2.0/assets-dark/*.png || true
rm ./src/gtk-3.0/gtk-common/assets/*.png || true
echo "== Rendering GTK+2 assets..."
cd ./src/gtk-2.0
GTK2_HIDPI=${GTK2_HIDPI} ./render-assets.sh
cd ../../
echo "== Rendering GTK+3 assets..."
cd ./src/gtk-3.0/gtk-common
./render-assets.sh
cd ../../..
SIZE_VARIANTS="${SIZE_VARIANTS}" COLOR_VARIANTS="," THEME_DIR_BASE=${DEST_PATH} ./install.sh
echo
echo "== SUCCESS"
echo "== The theme was installed to '${DEST_PATH}$(tr -d ',' <<<${SIZE_VARIANTS})'"
exit 0