-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsj-many-windows
executable file
·93 lines (84 loc) · 2.43 KB
/
sj-many-windows
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
#!/usr/bin/env rc
flag e +
~ $DEBUG ?* && flag x +
~ $te ?* || te=st # terminal emulator, e.g. xterm, st, rxvt
state=''
for (arg) {
if (~ $state ?*) {
switch($state) {
case -d; SJ_DIR=$arg
case -u; SJ_USER=$arg
case -r; SJ_RESOURCE=$arg
case -s; SJ_SERVER=$arg
case *; echo invalid state; exit 1
}
state=''
}
if not {
switch($arg) {
case -[durs]; state=$arg
case -D;
case *;
printf '%s: invalid option: %s\n' `{basename $0} $arg;
exit 1;
}
}
}
~ $SJ_DIR ?* || { echo SJ_DIR is not defined; exit 1; }
cd $SJ_DIR || { echo cannot cd to "$SJ_DIR"; exit 1; }
jid=$SJ_USER@$SJ_SERVER
true $jid #this shows variable when DEBUG is set
fn sigint { for (job in $bg_jobs) kill -TERM -$job; exit 1 }
fn sigquit { for (job in $bg_jobs) kill -TERM -$job; exit 2 }
fn sighup { for (job in $bg_jobs) kill -TERM -$job; exit 3 }
fn sigterm { for (job in $bg_jobs) kill -TERM -$job; exit 4 }
fn sigexit { for (job in $bg_jobs) kill -TERM -$job; exit 5 }
bg_jobs=()
$te -T 'connect - '$jid -e sjfs-connect $* &
bg_jobs=($bg_jobs $apid)
echo After you enter your password in the connect window, hit enter here ...
line >/dev/null
echo Announcing presence
presence -d $SJ_DIR
$te -T 'buddies - '$jid -e watch -d sjfs-online-buddies -d $SJ_DIR &
bg_jobs=($bg_jobs $apid)
$te -T 'monitor-all - '$jid -e sjfs-monitor-all-chats -d $SJ_DIR -u $SJ_USER -s $SJ_SERVER &
bg_jobs=($bg_jobs $apid)
# prepare for runit
echo '#!/usr/bin/env rc
'$te' -T `{basename `{pwd}} -e sjfs-chat -c -u '$SJ_USER' -s '$SJ_SERVER > run
chmod u+x run
outs1=`{find . -name out | sort}
for (o in $outs1) {
dir=`{dirname $o}
touch $dir/down
test -e $dir/run || ln -s ../run $dir
runsv $dir &
bg_jobs=($bg_jobs $apid)
tail -f -n0 $o | while (line) {
sv once $dir
} &
bg_jobs=($bg_jobs $apid)
}
while (true) {
# The only purpose of entr here is to wait for a change in the current
# directory; the first true is because entr needs a utility; the second
# true is to prevent an error in the script since entr will return 2
find . -type d | entr -pd true || true
outs2=`{find . -name out | sort}
if ( ! ~ $"outs1 $"outs2 ) {
new_outs=`{comm -13 <{for (s in $outs1) echo $s} <{for (s in $outs2) echo $s} }
for (o in $new_outs) {
dir=`{dirname $o}
touch $dir/down
[ -e $dir/run ] || ln -s ../run $dir
runsv $dir &
bg_jobs=($bg_jobs $apid)
tail -f -n0 $o | while (line) {
sv once $dir
} &
bg_jobs=($bg_jobs $apid)
}
outs1=$outs2
}
}