@@ -24,6 +24,19 @@ trap '_es=${?};
24
24
25
25
# shellcheck disable=SC1091
26
26
source .env
27
+
28
+ # https://en.wikipedia.org/wiki/ANSI_escape_code
29
+ E0=" $( printf " \033[0m" ) " # reset
30
+ E1=" $( printf " \033[1m" ) " # bold
31
+ E7=" $( printf " \033[7m" ) " # invert
32
+ E30=" $( printf " \033[30m" ) " # black foreground
33
+ E31=" $( printf " \033[31m" ) " # red foreground
34
+ E33=" $( printf " \033[33m" ) " # yellow foreground
35
+ E36=" $( printf " \033[36m" ) " # cyan foreground
36
+ E90=" $( printf " \033[90m" ) " # bright black (gray) foreground
37
+ E97=" $( printf " \033[97m" ) " # bright white foreground
38
+ E100=" $( printf " \033[100m" ) " # bright black (gray) background
39
+ E107=" $( printf " \033[107m" ) " # bright white background
27
40
OPT_DATE_FORMAT=Y-m-d
28
41
OPT_TIME_FORMAT=' H:i'
29
42
OPT_DEFAULT_COMMENT_STATUS=closed
@@ -49,10 +62,22 @@ WEB_WP_URL=http://localhost:8080
49
62
50
63
# ### FUNCTIONS ################################################################
51
64
65
+ format_list () {
66
+ local _header_match _header_replace
67
+ _h=" ${E97}${E100} "
68
+ _header_match=' (^name *) (status *) (update *) (version)'
69
+ _header_replace=" ${_h} \1${E0} ${_h} \2${E0} ${_h} \3${E0} ${_h} \4${E0} "
70
+ sed -u -E \
71
+ -e" s/${_header_match} /${_header_replace} /" \
72
+ -e" s/(^.* inactive .*$)/${E90} \1${E0} /" \
73
+ -e" s/( active .*)( available )/\1${E33} \2${E0} /" \
74
+ -e" s/( active .*)( none )/\1${E90} \2${E0} /"
75
+ }
76
+
52
77
53
78
activate_plugins () {
54
- local _plugin
55
- header ' Activate WordPress plugins'
79
+ local _bold _plugin _reset
80
+ header ' Activate plugins'
56
81
for _plugin in ${PLUGINS_ACTIVATE}
57
82
do
58
83
if wpcli --no-color --quiet plugin is-active " ${_plugin} " & > /dev/null
@@ -62,13 +87,16 @@ activate_plugins() {
62
87
wpcli plugin activate " ${_plugin} "
63
88
fi
64
89
done
90
+ wpcli plugin list --format=csv \
91
+ | column -s' ,' -t \
92
+ | format_list
65
93
echo
66
94
}
67
95
68
96
69
97
activate_themes () {
70
98
local _theme
71
- header ' Activate WordPress themes'
99
+ header ' Activate themes'
72
100
for _theme in ${THEMES_ACTIVATE}
73
101
do
74
102
if wpcli --no-color --quiet theme is-active " ${_theme} " & > /dev/null
@@ -78,13 +106,20 @@ activate_themes() {
78
106
wpcli theme activate " ${_theme} "
79
107
fi
80
108
done
109
+ wpcli theme list --format=csv \
110
+ | column -s' ,' -t \
111
+ | format_list
81
112
echo
82
113
}
83
114
84
115
85
116
composer_install () {
86
117
header ' Composer install'
87
- docker compose run --rm composer install 2> /dev/null
118
+ docker compose run --rm composer install --ansi 2>&1 \
119
+ | sed \
120
+ -e' /Container.*Running$/d' \
121
+ -e' /is looking for funding./d' \
122
+ -e' /Use the `composer fund` command/d'
88
123
echo
89
124
}
90
125
@@ -94,21 +129,21 @@ container_info() {
94
129
header ' Container info'
95
130
96
131
# composer
97
- printf " \033[1m%s\033[0m container - %s\n" \
132
+ printf " ${E1} %s ${E0} container - %s\n" \
98
133
' composer' ' A Dependency Manager for PHP'
99
134
container_print ' Composer version' " $( docker compose run --rm composer \
100
135
--no-ansi --version 2> /dev/null | sed -e' s/^Composer version //' ) "
101
136
echo
102
137
103
138
# web
104
- printf " \033[1m%s\033[0m container - %s\n" ' web' ' WordPress'
139
+ printf " ${E1} %s ${E0} container - %s\n" ' web' ' WordPress'
105
140
print_var WEB_WP_URL
106
141
print_var WEB_WP_DIR
107
142
container_print ' WordPress version:' " $( wpcli core version) "
108
143
echo
109
144
110
145
# wordpress-cli
111
- printf " \033[1m%s\033[0m container - %s\n" \
146
+ printf " ${E1} %s ${E0} container - %s\n" \
112
147
' wordpress-cli' ' The command line interface for WordPress'
113
148
IFS=$' \n '
114
149
for _line in $( wpcli --info | sort)
@@ -125,7 +160,34 @@ container_info() {
125
160
126
161
127
162
container_print () {
128
- printf " \033[36m%19s\033[0m %s\n" " ${1} " " ${2} "
163
+ printf " ${E36} %19s${E0} %s\n" " ${1} " " ${2} "
164
+ }
165
+
166
+
167
+ database_check () {
168
+ header ' Check database'
169
+ wpcli db check --color \
170
+ | sed -e' /^wordpress[.]wp_.*OK$/d'
171
+ echo
172
+ }
173
+
174
+
175
+ database_optimize () {
176
+ header ' Optimize database'
177
+ # Only show errors and summary
178
+ wpcli db optimize --color \
179
+ | sed \
180
+ -e' /^wordpress[.]wp_/d' \
181
+ -e' /Table does not support optimize/d' \
182
+ -e' /^status : OK/d'
183
+ echo
184
+ }
185
+
186
+
187
+ database_update () {
188
+ header ' Update database'
189
+ wpcli core update-db
190
+ echo
129
191
}
130
192
131
193
@@ -144,14 +206,14 @@ enable_permalinks() {
144
206
145
207
error_exit () {
146
208
# Echo error message and exit with error
147
- echo -e " \033[31mERROR:\033[0m ${* } " 1>&2
209
+ echo -e " ${E31} ERROR: ${E0} ${* } " 1>&2
148
210
exit 1
149
211
}
150
212
151
213
152
214
header () {
153
215
# Print 80 character wide black on white heading with time
154
- printf " \033[1m\033[7m %-71s$( date ' +%T' ) \033[0m \n" " ${@ } "
216
+ printf " ${E30}${E107} %-71s$( date ' +%T' ) ${E0} \n" " ${@ } "
155
217
}
156
218
157
219
@@ -187,26 +249,18 @@ install_wordpress() {
187
249
188
250
no_op () {
189
251
# Print no-op message"
190
- printf " \033[1m\033[30mno-op: %s\033[0m\n" " ${@ } "
191
- }
192
-
193
-
194
- optimize_tables () {
195
- header ' Optimize WordPress database tables'
196
- wpcli db optimize --color \
197
- | sed -e' /Table does not support optimize/d' -e' /^status : OK/d'
198
- echo
252
+ printf " ${E90} no-op: %s${E0} \n" " ${@ } "
199
253
}
200
254
201
255
202
256
print_var () {
203
- printf " \033[36m %19s\033[0m %s\n" " ${1} :" " ${! 1} "
257
+ printf " ${E36} %19s${E0} %s\n" " ${1} :" " ${! 1} "
204
258
}
205
259
206
260
207
261
remove_themes () {
208
262
local _theme
209
- header ' Remove extraneous WordPress themes'
263
+ header ' Remove extraneous themes'
210
264
for _theme in ${THEMES_REMOVE}
211
265
do
212
266
if ! wpcli --no-color --quiet theme is-installed " ${_theme} " \
@@ -221,9 +275,9 @@ remove_themes() {
221
275
}
222
276
223
277
224
- update_wordpress_options () {
278
+ update_options () {
225
279
local _date_format _default_comment_status _noop _time_format
226
- header ' Update WordPress options'
280
+ header ' Update options'
227
281
228
282
_date_format=$( wpcli option get date_format)
229
283
if [[ " ${OPT_DATE_FORMAT} " != " ${_date_format} " ]]
@@ -258,20 +312,6 @@ update_wordpress_options() {
258
312
}
259
313
260
314
261
- wordpress_update_db () {
262
- header ' Update WordPress database'
263
- wpcli core update-db
264
- echo
265
- }
266
-
267
-
268
- wordpress_db_check () {
269
- header ' Check WordPress database'
270
- wpcli db check
271
- echo
272
- }
273
-
274
-
275
315
wordpress_status () {
276
316
header ' Show maintenance mode status to expose any PHP Warnings'
277
317
wpcli maintenance-mode status
@@ -296,12 +336,12 @@ wpcli() {
296
336
container_info
297
337
composer_install
298
338
install_wordpress
299
- update_wordpress_options
339
+ update_options
300
340
remove_themes
301
341
activate_plugins
302
342
activate_themes
303
343
enable_permalinks
304
- wordpress_update_db
305
- optimize_tables
306
- wordpress_db_check
344
+ database_update
345
+ database_optimize
346
+ database_check
307
347
wordpress_status
0 commit comments