-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplay.sh
executable file
·69 lines (60 loc) · 1.01 KB
/
play.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
#!/bin/bash
clear
SLEEP=
TIME=300000
SED=`which sed`
# Check for sleep function
usleep $TIME 2>/dev/null
if [ $? == 0 ]
then
SLEEP=usleep
else
# Chech for floating point sleep
sleep 0.$TIME 2>/dev/null
if [ $? == 0 ]
then
SLEEP=sleep
TIME=0.$TIME
else
echo "Sleep with floating point or usleep don't found"
exit
fi
fi
# Check sed for -u
$SED -u '' /dev/null 2>/dev/null
# Try to use gsed instead
if [ $? != 0 ]
then
gsed -u '' /dev/null 2>/dev/null
if [ $? == 0 ]
then
SED=gsed
else
echo "Your sed isn't compatible with game"
exit
fi
fi
# Creating fifo for input
rm -f gravity-fifo;
mkfifo gravity-fifo;
# run game
$SED -Enf gravity.sed gravity-fifo &
# Prevent closing after echo
sleep 99999999 > gravity-fifo &
echo > gravity-fifo
# clock
while true
do
echo t > gravity-fifo
$SLEEP $TIME
done &
exec 2> /dev/null
# Pass key press to game
(while true
do
read -s -n 1 key
echo $key
[[ $key == "q" ]] && pkill -P $$
done) | $SED -u -e '/t/d' > gravity-fifo
# finish game
pkill -P $$