-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.sh
executable file
·411 lines (316 loc) · 9.24 KB
/
system.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#!/bin/bash
#
function dataSystem() {
# Date and time settings
export _date=`date '+%Y-%m-%d %H:%M:%S'`
export _day=`date '+%d'`
export _month=`date '+%B'`
export _year=`date '+%Y'`
# Local folder path
export _path=$(dirname ${0})
# system Info
export _author="Pires <https://github.com/apsantos-dev>"
export _description="Visual Studio Code Extensions"
export _license="The MIT License (MIT) <https://opensource.org/licenses/MIT>"
# global git
export _userName="Anderson Pires"
export _userEmail="developer@apsantos.com.br"
export _coreEditor="vi"
export _origin="git@github.com:apsantos-dev/vscode-extensions.git"
export _upstream="git@github.com:apsantos-dev/vscode-extensions.git"
# colors status: 0 off, 1 on
local _colorStatus=1
# this file
local _thisFile=${0##*/}
# Set the colors for displaying information
if [[ ${_colorStatus} != "0" ]]; then
_bk="\e[5m" # blink
_be="\e[38;5;6m" # blue
_gy="\e[30;1m" # gray
_gn="\e[0;32m" # green
_pe="\e[0;35m" # purple
_rd="\e[0;31m" # red
_we="\e[1;37m" # white
_yw="\e[1;33m" # yellow
_de="\e[0;34m" # darkBlue
_dy="\e[30;1m" # darkGray
_lb="\e[34;1m" # lightBlue
_lg="\e[37m" # lightGray
_ln="\e[32;1m" # lightGreen
_lp="\e[1;35m" # lightPurple
_lr="\e[1;31m" # lightRed
_dm="\e[2m" # dim
_ed="\e[m" # end
_he="\e[8m" # hide
_ic="\e[3m" # italic
_ld="\e[2m" # loading
_ue="\e[4m" # underline
fi
#
clear
#
viewMessage "${_dm}Processing ... ${_ed}"
#
requestNewTask
}
#
function inColors() {
#
if ( ! inColorsOptions ); then
errorFunction "Failed to start in colors options and formatting!"
fi
}
#
function inColorsOptions() {
#
validateMessage "Starting colors options and formatting"
#
requestNewTask
cat << EOF
$(echo -e "${_lg}Colors options and formatting - ${_ic}${_lb}${_month} ${_day}, ${_year} ${_ed}")
$(echo -e "${_lg}USAGE: ${_lg}OUTPUT: ${_ed}")
$(echo -e "${_lg}\${_be} ${_be}blue ${_ed}")
$(echo -e "${_lg}\${_gy} ${_gy}gray ${_ed}")
$(echo -e "${_lg}\${_gn} ${_gn}green ${_ed}")
$(echo -e "${_lg}\${_pe} ${_pe}purple ${_ed}")
$(echo -e "${_lg}\${_rd} ${_rd}red ${_ed}")
$(echo -e "${_lg}\${_we} ${_we}white ${_ed}")
$(echo -e "${_lg}\${_yw} ${_yw}yellow ${_ed}")
$(echo -e "${_lg}\${_de} ${_de}darkBlue ${_ed}")
$(echo -e "${_lg}\${_dy} ${_dy}darkGray ${_ed}")
$(echo -e "${_lg}\${_lb} ${_lb}lightBlue ${_ed}")
$(echo -e "${_lg}\${_lg} ${_lg}lightGray ${_ed}")
$(echo -e "${_lg}\${_ln} ${_ln}lightGreen ${_ed}")
$(echo -e "${_lg}\${_lp} ${_lp}lightPurple ${_ed}")
$(echo -e "${_lg}\${_lr} ${_lr}lightRed ${_ed}")
$(echo -e "${_lg}\${_bk} ${_bk}blink ${_ed}")
$(echo -e "${_lg}\${_dm} ${_dm}dim ${_ed}")
$(echo -e "${_lg}\${_ed} ${_ed}close command ${_ed}")
$(echo -e "${_lg}\${_he} used to hide element ${_ed}")
$(echo -e "${_lg}\${_ic} ${_ic}italic ${_ed}")
$(echo -e "${_lg}\${_ld} ${_ld}loading ${_ed}")
$(echo -e "${_lg}\${_ue} ${_ue}underline ${_ed}")
$(echo -e "${_lg}*************************************************************** ${_ed}")
EOF
}
#
function inGit() {
#
if ( ! inGitStart ); then
errorFunction "Failed to start Git in project!"
fi
#
requestNewTask
#
if ( ! inGitConfigGlobal ); then
errorFunction "Failed to configure Git globally!"
fi
#
requestNewTask
#
if ( ! inGitInitialCommit ); then
errorFunction "Failed to initial commit Git!"
fi
# View message when the task is complete!
feedbackTask "All tasks were successful!"
}
#
function inGitStart() {
#
validateMessage "Starting Git in the project"
#
rm -rf .git
#
git init
#
git remote add origin ${_origin}
#
git remote add upstream ${_upstream}
#
git checkout -b master
#
git fetch upstream
#
git merge upstream/master
# View message when the task is complete!
feedbackTask "Git has been started successfully!"
}
#
function inGitConfigGlobal() {
#
validateMessage "Configuring Git Globally"
#
git config --global user.name "${_userName}"
git config --global user.email "${_userEmail}"
git config --global core.editor "${_coreEditor}"
# View message when the task is complete!
feedbackTask "Git was configured successfully globally!"
}
# Initial commit of the system default files.
function inGitInitialCommit() {
#
validateMessage "Initial Commit Git"
#
# System Default Files
defaultFiles=(
"src/assets/doc/extensions.md"
".editorconfig"
".gitattributes"
".gitignore"
"CHANGELOG.md"
"CONTRIBUTING.md"
"LICENSE"
"README.md"
"structure.md"
"system.sh"
)
# Message for each file listed in the above variable: defaultFiles.
defaultFilesMessage=(
"These are extensions used in my day to day as a developer."
"Sets the encoding styles for publishers."
"Provides attributes for path names."
"Specifies files that will not be monitored by Git."
"All changes will be documented in this file."
"Explain how a participant should do things."
"Sets the type of license the project will have."
"Project details have been added."
"Current structure of files and folders."
".sh system for project management."
)
# count
count=( 0 )
# Commits each item in the array: defaultFiles.
for x in "${defaultFiles[@]}"
do
git add ${x}
git commit -m "${defaultFilesMessage[$count]}"
count=$(( count + 1 ))
done
# Adds a new TAG to the project.
git tag -a 1.0.0 -m "Release in: ${_month} ${_day}, ${_year}"
# Send the new branch to the HOST.
git push origin master -u
# Send the TAGS to the HOST.
git push origin --tags
# View message when the task is complete!
feedbackTask "The initial commit of the files was successful!"
}
#
#
function inHelp() {
#
validateMessage "General Commands Manual"
#
requestNewTask
#
cat << EOF
$(echo -e "${_lg}General Commands Manual - ${_ic}${_lb}${_month} ${_day}, ${_year} ${_ed}")
$(echo -e "${_lg}USAGE: ${_ed}")
$(echo -e "$ ${_be}sh ${_thisFile} [options] ${_ed}")
$(echo -e "${_lg}OPTIONS: ${_ed}")
$(echo -e "${_be}-c ${_lg}Displays color options ${_ed}")
$(echo -e "${_be}-g ${_lg}Start Git in the project and do initial commit ${_ed}")
$(echo -e "${_be}-h ${_lg}Help System ${_ed}")
$(echo -e "${_be}-i ${_lg}System Information ${_ed}")
$(echo -e "${_be}-u ${_lg}System update ${_ed}")
$(echo -e "${_ic}* The ${_be}'-u'${_ed}${_ic} option has not yet been implemented! ${_ed}")
$(echo -e "${_lg}*************************************************************** ${_ed}")
EOF
}
#
function inInfo() {
#
validateMessage "System Information"
#
requestNewTask
#
cat << EOF
$(echo -e "${_lg}System Information - ${_ic}${_lb}${_month} ${_day}, ${_year} ${_ed}")
$(echo -e "${_be}Author: ${_lg}${_author} ${_ed}")
$(echo -e "${_be}Description: ${_lg}${_description} ${_ed}")
$(echo -e "${_be}License: ${_lg}${_license} ${_ed}")
$(echo -e "${_lg}*************************************************************** ${_ed}")
EOF
}
#
function inUpdate() {
#
validateMessage "System Update"
#
requestNewTask
#
cat << EOF
$(echo -e "${_lg}System Update - ${_ic}${_lb}${_month} ${_day}, ${_year} ${_ed}")
$(echo -e "${_ic}* The ${_be}'-u'${_ed}${_ic} option has not yet been implemented! ${_ed}")
$(echo -e "${_lg}*************************************************************** ${_ed}")
EOF
}
#
function inInvalidOption() {
#
validateMessage "${_yw}Task Request Failed"
#
requestNewTask
#
cat << EOF
$(echo -e "${_ld}${_yw}Task Request Failed - ${_ic}${_lb}${_month} ${_day}, ${_year} ${_ed}")
$(echo -e "${_rd}The system did not find one of the parameters reported! \n See the complete list using the ${_be}'-h'${_rd} parameter! ${_ed}")
$(echo -e "${_lg}*************************************************************** ${_ed}")
EOF
}
#
function errorFunction() {
#
clear
#
viewMessage "${_rd}${@} ${_ed}"
#
exit 1
}
function feedbackTask() {
#
requestNewTask
#
viewMessage "${_gn}${@} ${_ed}"
}
#
function requestNewTask() {
#
sleep 1.5
#
clear
}
#
function validateMessage() {
#
if ( ! viewMessage "${_ld}${@} - Loading ... ${_ed}" ); then
errorFunction "Failed to load task: ${@}!"
fi
}
#
function viewMessage() {
#
echo -e "\n ${@} \r \n"
}
#
# Configures the system global variables and sets whether there will be color
# in the information display
dataSystem ${@}
# Get options
while getopts ":cghiu" flag; do
case $flag in
c) inColors ;;
g) inGit ;;
h) inHelp ;;
i) inInfo ;;
u) inUpdate ;;
*) inInvalidOption ;;
esac
# shift $(( OPTIND - 1 ))
done
# Checks if any parameter has been passed
[[ -z ${@} ]] && _defaultOption=1
# Performs a default task if no parameter is passed.
if [[ ${_defaultOption} == "1" ]]; then
inHelp
fi