-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdemos.rc
316 lines (256 loc) · 11.5 KB
/
demos.rc
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
#!/bin/bash
## - Functions: -------------------------------------------------------
die() { echo -e "$0: die - $*" >&2; exit 1; }
PROMPTS=${PROMPTS:=1}
USECOLOR=${USECOLOR:=1}
READ_OPTIONS() {
[ $PROMPTS -eq 0 ] && return 0
while true; do
echo -n "Press <return> "
read DUMMY
[ "${DUMMY#!!}" != "${DUMMY}" ] && {
echo "-- $LASTCMD"
eval $LASTCMD
continue
}
if [ "${DUMMY#!}" != "${DUMMY}" ];then
if [ "${DUMMY#!*}" != "${DUMMY#!}" ];then
local CMD=${DUMMY#!}
bash -x $CMD
else
PS1='debug \u@\h \w> ' bash
fi
continue
fi
[ "${DUMMY}" = "q" ] && exit 0
[ "${DUMMY}" = "Q" ] && exit 0
[ "${DUMMY}" = "s" ] && return 1
[ "${DUMMY}" = "S" ] && return 1
[ "${DUMMY#vf*}" != "${DUMMY}" ] && vi $CURRENT_FILE
[ "${DUMMY#vp*}" != "${DUMMY}" ] && RUN kubectl get $CURRENT_POD
[ "${DUMMY#dp*}" != "${DUMMY}" ] && RUN kubectl describe $CURRENT_POD
[ "${DUMMY#vd*}" != "${DUMMY}" ] && RUN kubectl get $CURRENT_DEPLOY
[ "${DUMMY#dd*}" != "${DUMMY}" ] && RUN kubectl describe $CURRENT_DEPLOY
[ -z "${DUMMY}" ] && return 0
done
# # HELP:
# # [ "${DUMMY#h*}" != "${DUMMY}" ] && Show opts, re-read DUMMY
# return 0
}
SECTION1() {
PROMPTS=1
[ "$1" = "-np" ] && { shift; PROMPTS=0; }
echo; echo "======== $*"
READ_OPTIONS
}
SECTION2() {
PROMPTS=1
[ "$1" = "-np" ] && { shift; PROMPTS=0; }
echo; echo "---- $*"
READ_OPTIONS
}
RUN() {
PROMPTS=1
[ "$1" = "-np" ] && { shift; PROMPTS=0; }
echo;
YELLOW "-- $*"; echo
READ_OPTIONS
#eval "$*";
#[ $? -eq 0 ] && $*
[ $? -eq 0 ] && eval "$*"
local RET=$?
LASTCMD=$*
return $RET
}
NORUN_PRESS() {
CPRESS "YELLOW" "-- $*";
#eval "$*";
}
RUN_PRESS() {
CPRESS "YELLOW" "-- $*";
eval "$*";
}
## -- COLOUR VARIABLES -----------------------------------------------
# NORMAL; BOLD; INVERSE;
if [ $USECOLOR -ne 0 ]; then
BLACK='\e[00;30m'; B_BLACK='\e[01;30m'; BG_BLACK='\e[07;30m'
WHITE='\e[00;37m'; B_WHITE='\e[01;37m'; BG_WHITE='\e[07;37m'
RED='\e[00;31m'; B_RED='\e[01;31m'; BG_RED='\e[07;31m'
GREEN='\e[00;32m'; B_GREEN='\e[01;32m' BG_GREEN='\e[07;32m'
YELLOW='\e[00;33m'; B_YELLOW='\e[01;33m' BG_YELLOW='\e[07;33m'
BLUE='\e[00;34m' B_BLUE='\e[01;34m' BG_BLUE='\e[07;34m'
MAGENTA='\e[00;35m' B_MAGENTA='\e[01;35m' BG_MAGENTA='\e[07;35m'
CYAN='\e[00;36m' B_CYAN='\e[01;36m' BG_CYAN='\e[07;36m'
else
BLACK=''; B_BLACK=''; BG_BLACK=''
WHITE=''; B_WHITE=''; BG_WHITE=''
RED=''; B_RED=''; BG_RED=''
GREEN=''; B_GREEN='' BG_GREEN=''
YELLOW=''; B_YELLOW='' BG_YELLOW=''
BLUE='' B_BLUE='' BG_BLUE=''
MAGENTA='' B_MAGENTA='' BG_MAGENTA=''
CYAN='' B_CYAN='' BG_CYAN=''
fi
NORMAL='\e[00m'
## -- COLOUR FUNCTIONS -----------------------------------------------
_colour=$NORMAL
I_colour=$NORMAL
#_LAST_colour=$NORMAL
BLACK() { local l_f1_LAST_colour=$_colour; _colour=$BLACK; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f1_LAST_colour; echo -en $_colour; echo -n "$*"; }
WHITE() { local l_f2_LAST_colour=$_colour; _colour=$WHITE; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f2_LAST_colour; echo -en $_colour; echo -n "$*"; }
RED() { local l_f3_LAST_colour=$_colour; _colour=$RED; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f3_LAST_colour; echo -en $_colour; echo -n "$*"; }
GREEN() { local l_f4_LAST_colour=$_colour; _colour=$GREEN; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f4_LAST_colour; echo -en $_colour; echo -n "$*"; }
YELLOW() { local l_f5_LAST_colour=$_colour; _colour=$YELLOW; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f5_LAST_colour; echo -en $_colour; echo -n "$*"; }
BLUE() { local l_f6_LAST_colour=$_colour; _colour=$BLUE; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f6_LAST_colour; echo -en $_colour; echo -n "$*"; }
MAGENTA() { local l_f7_LAST_colour=$_colour; _colour=$MAGENTA; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f7_LAST_colour; echo -en $_colour; echo -n "$*"; }
CYAN() { local l_f8_LAST_colour=$_colour; _colour=$CYAN; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f8_LAST_colour; echo -en $_colour; echo -n "$*"; }
B_BLACK() { local l_f1_LAST_colour=$_colour; _colour=$B_BLACK; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f1_LAST_colour; echo -en $_colour; echo -n "$*"; }
B_WHITE() { local l_f2_LAST_colour=$_colour; _colour=$B_WHITE; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f2_LAST_colour; echo -en $_colour; echo -n "$*"; }
B_RED() { local l_f3_LAST_colour=$_colour; _colour=$B_RED; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f3_LAST_colour; echo -en $_colour; echo -n "$*"; }
B_GREEN() { local l_f4_LAST_colour=$_colour; _colour=$B_GREEN; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f4_LAST_colour; echo -en $_colour; echo -n "$*"; }
B_YELLOW() { local l_f5_LAST_colour=$_colour; _colour=$B_YELLOW; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f5_LAST_colour; echo -en $_colour; echo -n "$*"; }
B_BLUE() { local l_f6_LAST_colour=$_colour; _colour=$B_BLUE; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f6_LAST_colour; echo -en $_colour; echo -n "$*"; }
B_MAGENTA() { local l_f7_LAST_colour=$_colour; _colour=$B_MAGENTA; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f7_LAST_colour; echo -en $_colour; echo -n "$*"; }
B_CYAN() { local l_f8_LAST_colour=$_colour; _colour=$B_CYAN; echo -en $_colour; echo -n "$1"; shift ; _colour=$l_f8_LAST_colour; echo -en $_colour; echo -n "$*"; }
I_BLACK() { local l_f1_LAST_colour=$I_colour; I_colour=$BLACK; echo -en $I_colour; echo -n "$1"; shift ; I_colour=$l_f1_LAST_colour; echo -en $_colour; echo -n "$*"; }
I_WHITE() { local l_f2_LAST_colour=$I_colour; I_colour=$WHITE; echo -en $I_colour; echo -n "$1"; shift ; I_colour=$l_f2_LAST_colour; echo -en $_colour; echo -n "$*"; }
I_RED() { local l_f3_LAST_colour=$I_colour; I_colour=$RED; echo -en $I_colour; echo -n "$1"; shift ; I_colour=$l_f3_LAST_colour; echo -en $_colour; echo -n "$*"; }
I_GREEN() { local l_f4_LAST_colour=$I_colour; I_colour=$GREEN; echo -en $I_colour; echo -n "$1"; shift ; I_colour=$l_f4_LAST_colour; echo -en $_colour; echo -n "$*"; }
I_YELLOW() { local l_f5_LAST_colour=$I_colour; I_colour=$YELLOW; echo -en $I_colour; echo -n "$1"; shift ; I_colour=$l_f5_LAST_colour; echo -en $_colour; echo -n "$*"; }
I_BLUE() { local l_f6_LAST_colour=$I_colour; I_colour=$BLUE; echo -en $I_colour; echo -n "$1"; shift ; I_colour=$l_f6_LAST_colour; echo -en $_colour; echo -n "$*"; }
I_MAGENTA() { local l_f7_LAST_colour=$I_colour; I_colour=$MAGENTA; echo -en $I_colour; echo -n "$1"; shift ; I_colour=$l_f7_LAST_colour; echo -en $_colour; echo -n "$*"; }
I_CYAN() { local l_f8_LAST_colour=$I_colour; I_colour=$CYAN; echo -en $I_colour; echo -n "$1"; shift ; I_colour=$l_f8_LAST_colour; echo -en $_colour; echo -n "$*"; }
NORMAL() { echo -en $NORMAL; }
## -- HELPER FUNCTIONS -----------------------------------------------
# Highlight text
HL_OLD() { YELLOW "$*"; }
HL() {
case "$1" in
-green) shift; GREEN "$*";;
-red) shift; RED "$*";;
-blue) shift; BLUE "$*";;
-cyan) shift; CYAN "$*";;
-magenta) shift; MAGENTA "$*";;
-yellow) shift; YELLOW "$*";;
*) YELLOW "$*";;
esac
}
# Highlight text ("1st argument" only)
HL1() {
case $1 in
-green|-red|-blue|-cyan|-magenta|-yellow) HL $1 "$2"; shift;;
*) YELLOW "$1";;
esac
shift;
echo -n "$*";
}
#HL1 "A TEST \$USECOLOR=$USECOLOR"
# DEMO_HEADER: Show section (first arg in green), then prompt for input
DEMO_HEADER() { echo;echo; GREEN "$1"; shift; echo "$*"; PRESS ""; }
STEP_HEADER() { echo; GREEN "$1"; shift; echo "$*"; }
#
# Function: PRESS <prompt>
# Prompt user to PRESS <return> to continue
# Exit if the user enters q or Q
#
PRESS() {
echo; echo $*
READ_OPTIONS
}
CPRESS() {
echo
case $1 in
RED) shift; RED "$*"; echo;;
GREEN) shift; GREEN "$*"; echo;;
YELLOW) shift; YELLOW "$*"; echo;;
BLUE) shift; BLUE "$*"; echo;;
MAGENTA) shift; MAGENTA "$*"; echo;;
CYAN) shift; CYAN "$*"; echo;;
*) shift; echo "$*"; echo;;
esac
READ_OPTIONS
}
#
# function YESNO <question> [<default>]
# e.g. use as:
# YESNO "Edit reminder file?" && vi $reminder_file_tomerge
#
YESNO() {
resp=""
default=""
[ ! -z "$2" ] && default="$2"
while [ 1 ]; do
if [ ! -z "$default" ];then
YELLOW "$1" " [yYnNqQ] [$default]:"
read resp
[ -z "$resp" ] && resp="$default"
else
YELLOW "$1" " [yYnNqQ]:"
read resp
fi
[ \( "$resp" = "q" \) -o \( "$resp" = "Q" \) ] && exit 0
[ \( "$resp" = "y" \) -o \( "$resp" = "Y" \) ] && return 0
[ \( "$resp" = "n" \) -o \( "$resp" = "N" \) ] && return 1
done
}
COLOUR_ALL_STDIN() {
echo -en $1; cat; echo -en $NORMAL
echo
}
COLOUR_ALL_TEXT() {
echo -en $1; cat; echo -en $NORMAL
echo
}
COLOUR_STDIN() {
#echo -e $(echo "%GREEN%test%RED%TEST%NORMAL%test%YELLOW%YELLOW\r\nSOME MORE TEXT" | sed -e "s/%GREEN%/\\${GREEN}/g" -e "s/%RED%/\\${RED}/g" -e "s/%NORMAL%/\\${NORMAL}/g" -e "s/%YELLOW%/\\\e[1;33m/g" -e "s/$/\\${NORMAL}/g")
#-e "s/ *%_/%/g" \
#-e "s/_% /%/g" \
sed \
-e "s/ %BLACK% /\\${BLACK}/g" \
-e "s/ %WHITE% /\\${WHITE}/g" \
-e "s/ %RED% /\\${RED}/g" \
-e "s/ %GREEN% /\\${GREEN}/g" \
-e "s/ %YELLOW% /\\${YELLOW}/g" \
-e "s/ %BLUE% /\\${BLUE}/g" \
-e "s/ %MAGENTA% /\\${MAGENTA}/g" \
-e "s/ %CYAN% /\\${CYAN}/g" \
\
-e "s/ %NORMAL% /\\${NORMAL}/g" \
-e "s/$/\\${NORMAL}/g"
}
COLOUR_ARGS() {
echo -e $(echo "$*" | COLOUR_STDIN)
}
#echo -e $(echo "%GREEN%test%RED%TEST%NORMAL%test%YELLOW%YELLOW\r\nSOME MORE TEXT" | COLOUR_STDIN)
DEMOS() {
echo "# -- multi-coloured line then normal:"
RED "Hello world "; YELLOW "from "; BLUE "Docker"; echo
echo NORMAL
HL "SOME TEXT in YELLOW"; echo; echo NORMAL
HL1 "FIRST WORDS" " in YELLOW"; echo; echo NORMAL
YELLOW "FIRST WORDS"; echo -n " in YELLOW"; echo; echo NORMAL
DEMO_HEADER "DEMO:" " Hello world"
STEP_HEADER "Step1:" " Hello world"
STEP_HEADER "Step2: Hello world"
RUN_PRESS "ls /tmp"
YESNO "Should I do this thing?" && \
GREEN "YES" " - you should" || RED "NO" " - you shouldn't"
echo
echo "Here is some red text
all of it
" | COLOUR_ALL_STDIN $RED
echo "BACK TO NORMAL"
echo "Here is some green text
all of it
" | COLOUR_ALL_STDIN $GREEN
echo "BACK TO NORMAL"
echo "Here is some background_magenta text
all of it
" | COLOUR_ALL_STDIN $BG_MAGENTA
echo "BACK TO NORMAL"
COLOUR_ARGS " %RED% Red %GREEN% Green %BLUE% Blue %YELLOW% Yellow %MAGENTA% Magenta %CYAN% Cyan %NORMAL% test %YELLOW% YELLOW\r\nSOME MORE TEXT"
echo "BACK TO NORMAL"
COLOUR_ARGS " %RED% Red %GREEN% Green %BLUE% Blue %YELLOW% Yellow %MAGENTA% Magenta %CYAN% Cyan %NORMAL% test %YELLOW% YELLOW\r\nSOME MORE TEXT"
echo "BACK TO NORMAL"
}
# DEMOS