-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsjfs-chat
executable file
·66 lines (57 loc) · 1.72 KB
/
sjfs-chat
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
#!/usr/bin/env rc
# Ctrl-D to end
flag e +
~ $DEBUG ?* && flag x +
usage='usage: ' ^ `{basename $0} ^ ' [-dsu] [-c | -b buddy]
-c: chat in current directory, expecting in and out files to exist
-b: chat with specified buddy
See sj(1) for explanation of options d, s, and u.
Environment variables: all from sj(1) and style, color, note_time'
# Unset configuration variable to disable feature
# style: for tput, e.g. bold, dim, blink, smul (underlined), rev (reverse),
# smso (standout)
# color: for tput setaf, e.g. 1-7
~ $color ?* || color=1
# number of milliseconds for the notify-send timeout
~ $note_time ?* || note_time=500
current_dir='' # initialize variables
buddy=''
state=''
for (arg) {
if(~ $state ?*) {
switch($state) {
case -d; SJ_DIR=$arg
case -s; SJ_SERVER=$arg
case -u; SJ_USER=$arg
case -b; buddy=$arg
}
state=''
}
if not {
switch($arg) {
case -[dsub]; state=$arg
case -c; current_dir=yes
case *
printf '%s: invalid option: %s\n%s\n' `{basename $0} $arg $usage
exit 1
}
}
}
if(! ~ $current_dir ?*) {
~ $SJ_DIR ?* || { echo Directory is needed via -d or SJ_DIR; exit 1; }
~ $buddy ?* || { echo Buddy is needed via -b; exit 1; }
cd $SJ_DIR/$buddy || { echo cannot cd to $SJ_DIR/$buddy; exit 1; }
}
[ -e out ] || { echo out file required; exit 1; }
[ -p in ] || { echo in file required and must be a named pipe; exit 1; }
cat out # show the conversation so far
sjfs-monitor-outfile out &
bg_job=$apid
fn sigint { kill -TERM -$bg_job } # kill the background job
fn sigquit { kill -TERM -$bg_job }
fn sighup { kill -TERM -$bg_job }
fn sigterm { kill -TERM -$bg_job }
fn sigexit { kill -TERM -$bg_job }
# Ctrl-D to end
while (line | tr -d '\n' >> in) ;
kill -TERM -$bg_job # kill the background job