-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsjfs-editor-chat
executable file
·50 lines (46 loc) · 1.25 KB
/
sjfs-editor-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
#!/usr/bin/env rc
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)'
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; }
tmpfile=`{mktemp} || exit 1
cat out >> $tmpfile
printf '- - -\n\n' >> $tmpfile
printf '%s\n' $tmpfile | entr -p rc -c 'awk ''NF{p=$0}END{print p}'' '$tmpfile' | tr -d ''\n''>> in' &
bg_job=$apid
$EDITOR $tmpfile
rm $tmpfile
kill -$apid