-
Notifications
You must be signed in to change notification settings - Fork 0
/
sedtris.sh
48 lines (44 loc) · 891 Bytes
/
sedtris.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
#!/usr/bin/env bash
# Bash script to make playing Sedtris more comfortable.
# It presses "enter" automatically once in a second and after
# every player's move. It also adds an invisible random input
# to improve randomness.
#
# Based on playsed.sh by Aurelio Marinho Jargas http://sed.sf.net/grabbag/scripts/playsed.sh.txt
mytime="`date +%s`"
IFS=''
CMD=''
TMP=''
export LC_ALL="C"
(while true;
do
read -s -t 1 -n 1 TMP
RES=$?
CMD="$CMD$TMP"
if [ "$CMD" == '' ]
then
read -s -n 1 TMP; CMD="$CMD$TMP";
if [ "$CMD" == '[' ]
then
read -s -n 1 TMP; CMD="$CMD$TMP";
fi
fi
if [ $RES -eq 0 ]
then
echo "$CMD"
fi
CMD=''
TMP=''
mytimenew="`date +%s`"
if [ "$mytimenew" != "$mytime" ]
then
let "temp=($RANDOM/10)%7"
if [ $temp == 1 ]
then
echo $temp
else
echo
fi
mytime=$mytimenew
fi
done) | sed -nf `dirname $0`/sedtris.sed