blob: 618b530310b943973d944bfc1605aa01dc66758d (
plain)
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
|
#!/bin/bash
# This executable does nothing by itself. Setup links with:
# ln -s manyplayer next
# ln -s manyplayer same
# ln -s manyplayer guessfile
if [ "x${MANYPLAYER_DIR}" == "x" ] ; then
MANYPLAYER_DIR=~/.manyplayer
fi
exe=$(basename $0)
function check {
if [ ! -f ${MANYPLAYER_DIR}/cmd ] ; then
echo "No command in manyplayer config (${MANYPLAYER_DIR}/cmd)."
exit 1
fi
if [ ! -f ${MANYPLAYER_DIR}/last ] ; then
echo "Position unspecified (${MANYPLAYER_DIR}/cmd)."
exit 1
fi
if [ ! -f ${MANYPLAYER_DIR}/filename ] ; then
echo "Filename template unspecified (${MANYPLAYER_DIR}/cmd)."
exit 1
fi
}
function play_last_file {
local comm=$(<${MANYPLAYER_DIR}/cmd)
local this=$(<${MANYPLAYER_DIR}/last)
local filename=$(<${MANYPLAYER_DIR}/filename)
exec $comm "${filename/!/$this}"
}
function play_next_file {
local thelast=$(<${MANYPLAYER_DIR}/last)
local thenext=$(printf %02d $(($thelast + 1)))
echo -n $thenext > ${MANYPLAYER_DIR}/last
play_last_file
}
function guess_filename {
local guess=$(echo *$1*)
local name=${guess/$1/!}
echo -n $name > ${MANYPLAYER_DIR}/filename
if [ "x$2" == "x" ] ; then
echo -n 00 > ${MANYPLAYER_DIR}/last
else
echo -n $2 > ${MANYPLAYER_DIR}/last
fi
}
if [ "x$exe" == "xnext" ] ; then
check
play_next_file
elif [ "x$exe" == "xsame" ] ; then
check
play_last_file
elif [ "x$exe" == "xguessfile" ] ; then
if [ "x$1" == "x" ] ; then
echo "Need a guess statement, try '01'."
exit 1
else
guess_filename $1 $2
fi
else
echo "'$exe' doesn't look like a manyplayer command..."
exit 1
fi
|