-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_oneko.sh
More file actions
executable file
·308 lines (262 loc) · 5.56 KB
/
random_oneko.sh
File metadata and controls
executable file
·308 lines (262 loc) · 5.56 KB
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
#!bash
###
### created: 2019-Aug-16 S.A. Birl https://github.com/sbirl/random_oneko
### updated: 2019-Sep-13
###
### oneko --help --or-- man oneko
###
### GNU: shuf -i 1-100 -n 1
### BSD: jot -r 1 1-100
###
RNG="shuf -n 1 -i"
#RNG="jot -r 1"
###
###
### Logging
LOG="/tmp/oneko"
###
PATH=$PATH:/usr/games
declare -a Characters # Array of Character details
declare -a Names # Array of Character names
Usage()
{
echo "Usage: $0 [1-9]"
exit 0
}
#ENDS Usage()
PickCharacter()
{
### I left out -tora
NUM=`$RNG 0-3`
echo " NUM=$NUM [0-3]" >> $LOG
if [ 0 -eq $NUM ]
then
CHAR="neko"
elif [ 1 -eq $NUM ]
then
CHAR="dog"
elif [ 2 -eq $NUM ]
then
CHAR="sakura"
elif [ 3 -eq $NUM ]
then
CHAR="tomoyo"
fi
echo " CHAR is $CHAR" >> $LOG
CHAR="-${CHAR}"
}
#ENDS PickCharacter()
PickFGColor()
{
NUM=`$RNG 0-6`
if [ 0 -eq $NUM ]
then
FG="black"
elif [ 1 -eq $NUM ]
then
FG="red"
elif [ 2 -eq $NUM ]
then
FG="green"
elif [ 3 -eq $NUM ]
then
FG="orange"
elif [ 4 -eq $NUM ]
then
FG="blue"
elif [ 5 -eq $NUM ]
then
FG="purple"
elif [ 6 -eq $NUM ]
then
FG="white"
fi
echo " NUM=$NUM [0-6]" >> $LOG
echo " FG is $FG" >> $LOG
}
#ENDS PickFGColor()
### I know that you can pass HTML-style colors (ie: #FF0000)
### for both foreground/background, but I wanted to keep the colors
### simple to limit annoying color clashes.
PickBGColor()
{
BG=$FG
while [ "$BG" == "$FG" ]
do
NUM=`$RNG 0-6`
if [ 0 -eq $NUM ]
then
BG="black"
elif [ 1 -eq $NUM ]
then
BG="red"
elif [ 2 -eq $NUM ]
then
BG="green"
elif [ 3 -eq $NUM ]
then
BG="orange"
elif [ 4 -eq $NUM ]
then
BG="blue"
elif [ 5 -eq $NUM ]
then
BG="purple"
elif [ 6 -eq $NUM ]
then
BG="white"
fi
done
echo " NUM=$NUM [0-6]" >> $LOG
echo " BG is $BG" >> $LOG
}
#ENDS PickBGColor()
PickFocus()
{
### If -tofocus, character runs along top
### of active window to follow mouse.
### Otherwise, character runs all over
### the screen chasing the mouse.
if [ 1 -eq $LeaderM ]
then
echo " LeaderM position filled. NUM=1" >> $LOG
NUM=1
elif [ 1 -eq $LeaderW ]
then
echo " LeaderW position filled. NUM=0" >> $LOG
NUM=0
else
NUM=`$RNG 0-1`
fi
echo " NUM=$NUM [0-1]" >> $LOG
if [ 1 -eq $NUM ]
then
LeaderW=1
WINDOW="-tofocus "
echo " Window leader." >> $LOG
elif [ 0 -eq $NUM ]
then
LeaderM=1
echo " Mouse leader." >> $LOG
fi
echo " LeaderM=$LeaderM" >> $LOG
echo " LeaderW=$LeaderW" >> $LOG
}
#ENDS PickFocus()
PickIdle()
{
### The man page describes -idle as "the threshold of
### the speed which ''mouse'' running away to wake cat up."
### But is that in pixels? pixels per second? I dunno.
###
### I know a smaller idle value results in the leaders
### reacting to mouse movement MUCH faster than I like.
### I tried a value of 1000, but that resulted in very
### little movement, so I stayed with a value in the low
### one-hundreds for the leader(s).
### When idle=100 sometimes I can carefully move my mouse
### across the entire screen without alerting the leaders.
###
### But I like the idea of giving each character their own
### idle value so that they dont all react at once.
IdleMin=0
IdleMax=110
if [ $# -eq 1 ]
then
IdleMax=$1
elif [ $# -eq 2 ]
then
IdleMin=$1
IdleMax=$2
fi
IDLE=`$RNG ${IdleMin}-${IdleMax}`
echo " IDLE=$IDLE [${IdleMin}-${IdleMax}]" >> $LOG
}
#ENDS PickIdle()
PickLeader()
{
### I was going to have a follower choose a random character
### but then I ran into 2+ followers choosing the same
### character and sitting on top of each other.
###
### (Hmmm, maybe if I used -position as well ...)
# NUM=`$RNG 1-$((COUNT -1))`
# FOLLOW="${Names[$NUM]}"
### I changed it so that a follower just runs after the
### character that was created before it.
FOLLOW="${Names[$(($COUNT -1))]}"
}
#ENDS PickLeader()
if [ $# -ne 1 ]
then
Usage
fi
One=$1
Acceptable='^[1-9]$'
if ! [[ $One =~ $Acceptable ]]
then
echo "'$One' is not a number between 1 and 9."
Usage
fi
### We pick up to 9 instances to execute too many characters
### clutter the screen and it's hard to work with.
MAX=`$RNG 1-$One`
#MAX=$One
### Cant have too many leaders running around; they characters have
### a tendency to run over top of each over. So pick 1 leader to
### follow the mouse, and 1 to run along the top of the window.
### Then the followers can chase after the leaders.
LeaderW=0
LeaderM=0
echo "Number of instances: $MAX" > $LOG
COUNT=1
while [ $COUNT -le $MAX ]
do
echo "=== Character $COUNT of $MAX ==========" >> $LOG
### Character #1 is always a leader because
### it has no one to follow.
if [ 1 -eq $COUNT ]
then
echo " COUNT=1; Forced Leader" >> $LOG
NUM=1
elif [ $LeaderW -eq 1 ] && [ $LeaderM -eq 1 ]
then
echo " Leader positions filled; Forced 0." >> $LOG
NUM=0
else
echo " LeaderM=$LeaderM" >> $LOG
echo " LeaderW=$LeaderW" >> $LOG
NUM=`$RNG 0-1`
fi
FG=""
BG=""
WINDOW=""
FOLLOW=""
if [ $NUM -eq 1 ]
then
echo "Leader" >> $LOG
PickCharacter
PickFGColor
PickBGColor
PickFocus
PickIdle 100 110
Characters[$COUNT]="-name 'oneko${COUNT}' $CHAR -fg $FG -bg $BG ${WINDOW}-idle $IDLE " >> $LOG
else
echo "Follower" >> $LOG
PickCharacter
PickFGColor
PickBGColor
PickLeader
PickIdle 0 30
Characters[$COUNT]="-name 'oneko${COUNT}' $CHAR -fg $FG -bg $BG -toname '$FOLLOW' -idle $IDLE " >> $LOG
fi
Names[$COUNT]="oneko${COUNT}"
echo >> $LOG
echo "onkeo ${Characters[$COUNT]}" >> $LOG
oneko ${Characters[$COUNT]} &
echo >> $LOG
COUNT=$(($COUNT + 1))
done
echo "less $LOG"
###
#EOF