-
Notifications
You must be signed in to change notification settings - Fork 1
/
Exec
executable file
·76 lines (60 loc) · 1.62 KB
/
Exec
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
#!/bin/sh
set -e
if [ "$1" = "-h" ] && [ "$2" = "" ]; then
p=`basename $0`
s=`echo "$p" | sed 's/./ /g'`
cat <<EOF
NAME
$p
SYNOPSYS
$p [-h]
$p [-t [-a|id|pattern]] [-e [-a|id|pattern]]<cmd>
$s [-o [-a|id|pattern]] [-p outp] [-q errp] [-r both] <cmd>
DESCRIPTION
$p runs a command, sending stdout/stderr to acme buffers,
defaulting to +Buffer.
The buffers are automatically cleaned before hand.
-t selects stdout buffer, forwarding [-a|id|pattern] to Getids
-t selects stderr buffer, forwarding [-a|id|pattern] to Getids
-o is a shortcut to set both -t and -e.
-p and -q allows to pipe stdout/stderr through the given shell
commands, before forwarding the result to To, which will be in
charge of writing the content to an acme(1) buffer.
-r allows to set both outp and errp at once.
EOF
exit 0
fi
outp=cat
errp=cat
while getopts "t:e:o:p:q:r:" opt; do
case "$opt" in
t) to=$OPTARG ;;
e) err=$OPTARG ;;
o) to=$OPTARG; err=$OPTARG ;;
p) outp="$OPTARG" ;;
q) errp="$OPTARG" ;;
r) outp="$OPTARG"; errp="$OPTARG" ;;
esac
done
shift $((OPTIND-1))
if [ -z "$to" ]; then to=-a; fi
if [ -z "$err" ]; then err=-a; fi
if [ -z "$1" ]; then
echo "Exec [-t stdout] [-e stderr] [-o both] [-p outp] [-q errp] [-r both] <command>" | To $err
exit 1
fi
# Having two To on the same buffer would mess things up
# because To clean window beforehand.
#
# We're comparing pointers, but good enough in practice.
if [ "$err" = "$to" ]; then
{
{
eval "$*" </dev/stdin 2>&3 | eval "$outp"
} 3>&1 | eval "$errp"
} | To -c $to
else
{
eval "$*" </dev/stdin 2>&3 | eval "$outp" | To -c $to
} 3>&1 | eval "$errp" | To -c $err
fi