-
Notifications
You must be signed in to change notification settings - Fork 0
/
yamss.sh
executable file
·308 lines (271 loc) · 9.27 KB
/
yamss.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
#!/usr/bin/env bash
#===============================================================================
#
# FILE: yamss.sh
#
# USAGE: ./yamss.sh
#
# DESCRIPTION: [Y]et [A]nother [M]atrix [S]hell [S]cript.
# This script shows a matrix like display in terminal.
# OPTIONS: -a, -c [num], -d, -h [num], -m [num], -q [let], -r, -s [num]
# REQUIREMENTS: bash, gnu awk, gnu bc
# BUGS: they will be discovered at random times
# NOTES: https://en.wikipedia.org/wiki/ANSI_escape_code
# AUTHOR: Cesar Bodden (), [email protected]
# ORGANIZATION: pissedoffadmins.com
# CREATED: 09/29/2016 05:14:34 PM EDT
# REVISION: 12
#===============================================================================
#################################
## globals that can be changed ##
#################################
ASYNC="false" ## default asynchronous mode
CHARS="1" ## default characters to use
MN_CLR="34" ## default main color
HL_CLR="37" ## default highlight color
SLEEP="0.1" ## default sleep interval
QUIT_LET="q" ## default quit / kill letter
RNBW_MODE="false" ## default rainbow mode
##########################################
## below this nothing should be changed ##
##########################################
export TERM=vt100
readonly PROGNAME=$(basename $0)
readonly PROGDIR=$(readlink -m $(dirname $0))
## on ctrl c - reset term and clear screen
trap 'echo -e "\033[2J" ; exit' 1 2 3 9 15
function main()
{
ROW=$(tput lines) ## total number of lines in term
COL=$(tput cols) ## total number of columnes in term
## \033 clear entire screen (ED)
## \033 hides the cursor (DECTCEM)
printf "%b" \
"\033[2J" \
"\033[?25l"
## set character type
case "${CHARS}" in
'1')
## regular characters
declare -g _LET=($(\
awk 'BEGIN{for(i=49;i<126;i++)printf "%c\n",i}'))
;;
'2')
## kanji
declare -g _LET=($(\
awk 'BEGIN{for(i=12032;i<12246;i++)printf "%c\n",i}'))
;;
'3')
## not kanji
declare -g _LET=($(\
awk 'BEGIN{for(i=128;i<600;i++)printf "%c\n",i}'))
;;
'4')
## blocks
declare -g _LET=($(\
awk 'BEGIN{for(i=9617;i<9620;i++)printf "%c\n",i}'))
esac
## sleep time array
declare -g _SLP=($(\
seq .01 .01 ${SLEEP}))
## color array for rainbow mode
declare -g _RNBW=($(\
seq 30 1 37))
}
function loop()
{
local _RND_COL=$(($RANDOM%$COL)) ## random tput col
local _RND_ROW=$(($RANDOM%$ROW)) ## random tput line
## enable / disable asynchronous mode
if [[ ${ASYNC} == "true" ]]
then
local _RND_SLP=${_SLP[RANDOM%${#_SLP[@]}]}
else
local _RND_SLP=${SLEEP}
fi
## enable / disable rainbow road mode
if [[ ${RNBW_MODE} == "true" ]]
then
MN_CLR=${_RNBW[RANDOM%${#_RNBW[@]}]}
HL_CLR=${_RNBW[RANDOM%${#_RNBW[@]}]}
fi
## count 1 - tput lines
for _LINE in $(seq 1 ${ROW})
do
local INDEX=$(($RANDOM%${#_LET[*]})) ## random letter index
local _PRN_LET=$(printf "%s" "${_LET[$INDEX]}") ## print letter
## \033 CUP
## \033 SGR (color blue (34m)) letter
## \033 CUP
## \033 SGR (color white (37m)) letter
printf "%b" \
"\033[$(($_LINE-1));${_RND_COL}H" \
"\033[${MN_CLR}m${_PRN_LET}" \
"\033[${_LINE};${_RND_COL}H" \
"\033[${HL_CLR}m"${_PRN_LET}
sleep ${_RND_SLP}
## if i is >= random tput line
if [[ ${_LINE} -ge ${_RND_ROW} ]]
then
## Moves the cursor to row n, column m
## CUP – Cursor Position
printf "%b" \
"\033[$(($_LINE-$_RND_ROW));${_RND_COL}H "
fi
done
## count 1-(random tput line) - tput line
for _RND_LINE in $(eval echo {$(($_RND_LINE-$_RND_ROW))..$ROW})
do
## Moves the cursor to row n, column m
## HVP – Horizontal and Vertical Position
printf "%b" \
"\033[${_RND_LINE};${_RND_COL}f "
sleep ${_RND_SLP}
done
}
function run()
{
{
loop
} & sleep ${SLEEP}
read -t $(\
echo "${SLEEP}/10" \
| bc -l) -s -n 1 KILL
if [[ ${KILL} == ${QUIT_LET} ]]
then
kill $(jobs -p)
reset
pkill -o -f "bash.*${PROGNAME}"
fi
}
function usage()
{
## usage / description function
clear
echo -e "
NAME
${PROGNAME} - matrix like shell script
SYNOPSIS
${PROGNAME} [OPTION]...
DESCRIPTION
[Y]et [A]nother [M]atrix [S]hell [S]cript.
This script shows a matrix like display in terminal.
OPTIONS
-a
This option sets asynchronous mode.
Default is disabled
-c [number]
This option sets the characters used for display.
Different characters listed in chart below.
Default is standard (1).
-d
This option runs everything in default settings.
This should be run by itself.
-h [number]
This option sets the highlite color according to
the color chart below.
Default is \033[37m37 (white)\033[0m
-m [number]
This option sets the main color according to
the color chart below.
Default is \033[34m34 (blue)\033[0m
-q [letter]
This option specifies what letter to use to quit
out of this script instead of using ctrl + c.
Default is q
-r
This option specifies rainbow road mode.
All main and highlite colors will be random from
the color chart below.
Default is disabled
-s [number]
This option sets drop speed.
Range is from 1 (fastest ) to 10 ( slowest )
Default is 1
CHARACTER CHART
Option [1]:
Standard: 123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]
^_abcdefghijklmnopqrstuvwxyz{|}
Option [2]:
Kanji: ⼀⼁⼂⼃⼄⼅⼆⼇⼈⼉⼊⼋⼌⼍⼎⼏⼐⼑⼒⼓⼔⼕
⼖⼗⼘⼙⼚⼛⼜⼝⼞⼟⼠⼡⼢⼣⼤⼥⼦⼧⼨⼩⼪⼫
⼬⼭⼮⼯⼰⼱⼲⼳⼴⼵⼶⼷⼸⼹⼺⼻⼼⼽⼾⼿⽀⽁
⽂⽃⽄⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗
⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭
⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿⾀⾁⾂⾃
⾄⾅⾆⾇⾈⾉⾊⾋⾌⾍⾎⾏⾐⾑⾒⾓⾔⾕⾖⾗⾘⾙
⾚⾛⾜⾝⾞⾟⾠⾡⾢⾣⾤⾥⾦⾧⾨⾩⾪⾫⾬⾭⾮⾯
⾰⾱⾲⾳⾴⾵⾶⾷⾸⾹⾺⾻⾼⾽⾾⾿⿀⿁⿂⿃⿄⿅
⿆⿇⿈⿉⿊⿋⿌⿍⿎⿏⿐⿑⿒⿓⿔⿕
Option [3]:
Misc: ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍ
ÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øù
úûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥ
ĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐő
ŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽ
žſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩ
ƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕ
ǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴǵǶǷǸǹǺǻǼǽǾǿȀȁ
ȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȜȝȞȟȠȡȢȣȤȥȦȧȨȩȪȫȬȭ
ȮȯȰȱȲȳȴȵȶȷȸȹȺȻȼȽȾȿɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏɐɑɒɓɔɕɖɗ%
Option [4]:
Blocks: ░▒▓
COLOR CHART
30 Black \033[30mBlack\033[0m
31 Red \033[31mRed\033[0m
32 Green \033[32mGreen\033[0m
33 Yellow \033[33mYellow\033[0m
34 Blue \033[34mBlue\033[0m
35 Magenta \033[35mMagenta\033[0m
36 Cyan \033[36mCyan\033[0m
37 White \033[37mWhite\033[0m
"
exit 0
}
## option selection
while getopts "ac:dh:m:q:rs:" OPT
do
case "${OPT}" in
'a')
ASYNC="true"
;;
'c')
CHARS=${OPTARG}
;;
'd')
true
;;
'h')
HL_CLR=${OPTARG}
;;
'm')
MN_CLR=${OPTARG}
;;
'q')
QUIT_LET=${OPTARG}
;;
'r')
RNBW_MODE="true"
;;
's')
SLEEP=$(echo "${OPTARG} / 10" | bc -l)
;;
*)
usage \
| less
exit 0
;;
esac
done
if [[ ${OPTIND} -eq 1 ]]
then
usage \
| less
exit 0
fi
shift $((OPTIND-1))
main
while true
do
run
done