-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaaa-class
executable file
·383 lines (300 loc) · 6.94 KB
/
aaa-class
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
###############################################################
#
# A A A
#
#
# ANSI-INVERT
# echo -e -n '\033[7m'
# echo -e -n '\033[0m'
# ANSI YELLOW -and- RESET
# echo -e -n '\033[0;33m'
# echo -e -n ">docker-kill ~ dk kl"
# echo -e -n '\033[0m'
echo AAA *sh/Library
echo AAA/ZEE/2023
echo
# define functions/methods/... and continue at bottom
aaa-!(){
echo Scripts#
echo ----------------------------------------
ls -la $aaa_scripts/$1*
echo
echo Scripts#
echo ----------------------------------------
ls -la $aaa_scriptsX/$1*
echo
}
#
#
# 2DO***
aaa-al() { aaa-all $@; return $?; }
aaa-all(){
echo 2DO***
echo show all alias/functions/scripts/...
echo show all variables/configs/...
return $?;
}
# FIND CLASSES <*>- -OR- <*>-class
#
# 2REFACTOR***
aaa-cl() { aaa-classes $@; return $?; }
aaa-classes(){
# ls -la --color /DAT/#scripts/*-;
# for x in $AAAScripts/*-; do echo $(basename $x); done
for x in $AAAScripts/*-; do echo ${x#/*/*/*}; done
return $?;
}
# LIST AVAILABLE SCRIPS/METHODS/ACTIONS/ALIAS/...
# for the argumented class
#
aaa-code(){
# if no argument then exit error 1
if [ -z $1 ]; then
echo Syntax: aaa-code ?class
return 1
fi
# AAA
echo -e -n '\033[1;32m'
echo -e AAA
echo -e -n '\033[0;33m'
echo "* aaa-class <method> <args...> -to- invoke class/method"
echo "* <class>-help -is- static edited help text"
echo "* <oo> <mm> <args...> -as- quick short form..."
echo
# ALIAS
echo -e -n '\033[1;32m'
echo -e Alias
echo -e -----
echo -e -n '\033[0;37m'
echo ATT*** bash do not propagate ALIAS to non-interactive shells...
compgen -A alias
echo
# FUNCTIONS/help
echo -e -n '\033[1;32m'
echo -e Functions
echo -e ---------
echo -e -n '\033[0;37m'
#invoke *-class help
#$1class help
compgen -A function | grep -i $1
echo
# SCRIPTS
echo -e -n '\033[1;32m'
echo -e Scripts
echo -e -------
echo -e -n '\033[0;37m'
ls -la $AAAScripts/$1*
}
# DATES
#
#
aaa-date(){
date
date +%Y%m%d-%H%M%S
date +%W
}
# EDIT
#
#
aaa-edit(){
local x=
# DIALOG-OPTIONS
echo \(1\) autoexec
echo \(2\) aaa-
echo \(3\) aaa-class
echo \(0\) \<exit\>
echo
while [[ ! "1230" =~ $x ]]; do
read -p "?" -t 10 -n 1 -i 1 x
done;
case ${x}
in
1) nano $AAAScripts/autoexec;;
2) nano $AAAScripts/aaa-;;
3) nano $AAAScripts/aaa-class;;
4) echo;;
esac
}
# help/functions
#
# REFACTOR***
aaa-hh(){ aaa-help $@; return $?; }
aaa-help(){
echo -e -n '\033[1;36m'
cat<<EOF
aaa-! !
aaa-000 --
aaa-all al
aaa-edit ed edit system files
aaa-help hh this...
aaa-list ls Show related actions in Alias/Functions/Scripts
aaa-log -- show logo/banner
aaa-me me try to show ???AAAScriptsX/me-aaa
aaa-message ms show message
aaa-parse --
aaa-scripts sc
aaa-scriptsX sx
aaa-state st State...
aaa-status ss Status...
aaa-xxx xx
EOF
echo -e -n '\033[0;37m'
}
# LOGO
#
# REFACTOR*** stty/size full-line
aaa-log(){
echo '/////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
echo ' / \ '
echo ' / /\ \ '
echo ' / / \ \ '
echo ' \/____\/ '
echo ' \ / ZEE/2020 '
echo ' \ / '
echo '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////'
# 2DO***
# if $aaa_log then log to $aaa_log...
# if arguments print them line-by-line...
}
#
#
# ?REPLACE aaa-scripts??
aaa-ls(){ aaa-list $@; return $?; }
aaa-list(){
aaa-code aaa-;
return $?;
}
# if exist a file $AAAScriptsX/me-$1 then show it
# if $1 is null assume "aaa"
#
aaa-me() {
local x=$1;
# if [ -f $AAAScriptsX/me-$x ]; then cat $AAAScriptsX/me-$x; fi;
ls -la --color $AAAScriptsX/me-$x*;
return $?;
}
# Message
#
# REFACTOR***
aaa-ms(){ aaa-message $@; return $?; }
aaa-message(){
echo -e $*;
return $?;
}
# used in <class>- scripts
# like aaa-* -or- service-*
#
# $1 is the invoker class id
# $2 if not present list the actions/methods/scripts
# $2 if present call the action of the originator class (can be abbreviation as docker/dk)
# 3..* arguments to pass allong...
#
# ATT***
# avoid ALIAS because they are not expanded to non-interactive shells
#
# SAMPLES***
# aaa-parse /DAT/#scripts/aaa-
#
aaa-parse(){
# if no arguments... no need to parse...
if [ -z $1 ]; then
echo aaa-parse/function... no arguments...
return 255;
fi;
# get class name from $0 path...
local x=${0##*/}; x=${x%.*};
# if action/method has no arguments then show scripts/functions/alias
# get script name from path and strip-off extension
# use $1 to get action...
if [ -z $2 ]; then aaa-code $x; return 0; fi;
# if action/method is argumented
local xx=$x$2
# consume/drop
# drop $1/file-or-alias and $2/action-or-method
shift
shift
# FUNCTION
# "" to prevent null type
if [ "$(type -t $xx )" == "function" ]; then
$xx $*;
return $?;
fi;
# SCRIPT
# REFACTOR*** agnosticize <extension> (.sh .py ...)
# resolve to it... and return
if [ -x $AAAScripts/$xx ]; then
$xx $*;
return $?;
fi;
# REFACTOR*** for aaa-message
aaa-message "" "\n\t" "ERROR***" "\n\t" "no script or alias..." "\n\t" $xx
return 255;
}
#
#
#
aaa-st() { aaa-state $@; return $?; }
aaa-state() {
# could consume $1 to $x and shift
# if futher arguments were significant...
echo ----------------------------------------[ PATH ]
echo $PATH
echo
echo ----------------------------------------[ AAA* ]
echo $AAALinks \| $AAALinksX
echo $AAAScripts \| $AAAScriptsX
echo
return $?;
}
#
#
#
aaa-ss() { aaa-status $@; return $?; }
aaa-status() {
# 2DO***
# show resume of cpu/mem/disk os/user/processes/...
source /DAT/#scripts/service-class
service-status $@;
return $?;
}
aaa-va() { aaa-variables $@; return $?; }
aaa-variables() {
# 2DO***
declare -x | grep -i aaa | tr -d "declare \-x "
# compgen -v | grep -i aaa
return $?;
}
#
#
# ?rename to aaa-info? aaa-test?? aaa-? ???
aaa-xx() { aaa-xxx $@; return $?; }
aaa-xxx() {
# get calling scripts name...
# can be called from any script
local x=${0##*/}; x=${x%.*}; x=$x$2;
echo
echo AAA-Analysis \($x/$( type -t $x )\)
echo
echo \$\0 -is- $0
echo \$\@ -is- $@
echo \$\* -is- $*
echo
echo "$@" -from- \"\$\@\"
echo "$*" -from- \"\$\*\"
echo
echo [ basename/dirname ]
basename $0
# basename $0 .sh
dirname $0
echo
echo [ POSIX leaf/no-extension ]
# POSIX string manipulations
echo ${0##*/}
echo ${0%.*}
return $?;
}
# fallback to call class methods
# without pass through aaa-parse
# do not uncomment in aaa-
# because the source(ing) in other classes cause odd behaviour
# if [ ! -z $1 ]; then service-$@; fi;