summaryrefslogtreecommitdiff
path: root/twopane.bash
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2024-08-11 18:00:40 -0400
committerAndrew Cady <d@jerkface.net>2024-08-11 18:00:40 -0400
commitdb3e063b6b12cb4e0ef44c4cba5962aa391560b1 (patch)
treeeffb5ab5d2e21a9a5026477ab66eba06a19eb7d6 /twopane.bash
parent232c3674aa7cf6606329f03ac8ce86b1eec8dbcc (diff)
all bugs have been removed
Diffstat (limited to 'twopane.bash')
-rwxr-xr-xtwopane.bash92
1 files changed, 72 insertions, 20 deletions
diff --git a/twopane.bash b/twopane.bash
index 8417022..2aacab2 100755
--- a/twopane.bash
+++ b/twopane.bash
@@ -7,9 +7,14 @@ PROGNAME=${0##*/}
7 7
8BOT_SIZE=8 8BOT_SIZE=8
9BOT_TITLE=input 9BOT_TITLE=input
10BOT_CMD=start 10BOT_CMD=sendstream
11TOP_CMD='PS1="$TOP_TITLE\$ " bash --noprofile --norc -i' 11if [ $# = 0 ]
12TOP_TITLE=output 12then
13 TOP_CMD="$SHELL -i"
14else
15 TOP_CMD=$*
16fi
17TOP_TITLE=$TOP_CMD
13 18
14TWOPANE=$(mktemp -d) 19TWOPANE=$(mktemp -d)
15export TWOPANE TOP_CMD BOT_CMD TOP_TITLE BOT_TITLE BOT_SIZE 20export TWOPANE TOP_CMD BOT_CMD TOP_TITLE BOT_TITLE BOT_SIZE
@@ -26,8 +31,13 @@ save_screenrc()
26} 31}
27 32
28save_screenrc <<'.' 33save_screenrc <<'.'
34# Disable keybindings.
29unbindall 35unbindall
30escape \0\0 36escape \0\0
37# Disable messages. This is needed for screen -X/-Q to work reasonably.
38msgwait 0
39msgminwait 0
40
31caption string '%t' 41caption string '%t'
32layout new 42layout new
33split 43split
@@ -38,34 +48,35 @@ screen -ln -t "$BOT_TITLE" 0 bash --noprofile --rcfile "$TWOPANE"/bashrc -i
38source "$TWOPANE"/screenrc.startpane 48source "$TWOPANE"/screenrc.startpane
39. 49.
40 50
41save_screenrc 'startpane' <<'.' 51save_screenrc 'startpane' <<.
42focus top 52focus top
43screen -ln -t "$TOP_TITLE" 1 sh -c "$TOP_CMD" 53screen -ln -t "\$TOP_TITLE" 1 $TOP_CMD
44exec .!. socat -u UNIX-RECV:"$TWOPANE"/socket STDOUT 54exec .!. sh -c 'socat -u UNIX-RECV:"\$TWOPANE"/socket STDOUT & socat -u STDIN,rawer UNIX-SEND:"\$TWOPANE"/socket'
45title 'output' 55title 'output'
46focus bottom 56focus bottom
47layout save 0 57layout save 0
48. 58.
49 59
50save_screenrc 'restart' <<. 60save_screenrc 'restart' <<.
51layout new 61focus top
52split 62screen -ln -t "\$TOP_TITLE" 1 $TOP_CMD
63exec .!. sh -c 'socat -u UNIX-RECV:"\$TWOPANE"/socket STDOUT & socat -u STDIN,rawer UNIX-SEND:"\$TWOPANE"/socket'
64title 'output'
53focus bottom 65focus bottom
54resize $BOT_SIZE
55select 0
56title 'input'
57
58source "$TWOPANE"/screenrc.startpane
59. 66.
60 67
61restart() 68restart()
62{ 69{
70 while screen -p1 -Q info
71 do
72 screen -p1 -X kill
73 done
63 screen -X source "$TWOPANE"/screenrc.restart 74 screen -X source "$TWOPANE"/screenrc.restart
64} 75}
65sendp() 76sendp()
66{ 77{
67 trap "kill -SIGUSR1 $1" EXIT 78 trap "kill -SIGUSR1 ${1:-$$}" EXIT
68 socat -u STDIN UNIX-SENDTO:"$TWOPANE"/socket || restart 79 socat -u STDIN UNIX-SENDTO:"$TWOPANE"/socket 2>&20 || restart
69} 80}
70sendc() 81sendc()
71{ 82{
@@ -98,14 +109,47 @@ raw()
98 stty "${stty_opts[@]}" 109 stty "${stty_opts[@]}"
99} 110}
100 111
112:()
113{
114 if [ "$#" -gt 0 ]
115 then
116 printf '%s: %s\r\n' "$0" "$*" >&2
117 fi
118}
119
101start() 120start()
102{ 121{
103 trap ': SIGPIPE ${SOCAT[@]@A}' SIGPIPE 122 socat_stty_opts=(
104 trap ': SIGCHLD ${SOCAT[@]@A}' SIGCHLD 123 echo=1
105 trap ': SIGUSR1 ${SOCAT[@]@A}; SOCAT=()' SIGUSR1 124 echoctl=1
125 intr=0
126 quit=0
127 eof=0
128 start=0
129 stop=0
130 susp=0
131 lnext=0
132 )
133 stty=$(printf %s, "${socat_stty_opts[@]}")
134 while ! socat -u \
135 STDIN,rawer,"${stty}" \
136 UNIX-SENDTO:"$TWOPANE"/socket
137 do
138 restart
139 done
140}
141
142sendstream()
143{
144 #trap ': SIGPIPE ;' SIGPIPE
145 #trap ': SIGCHLD ;' SIGCHLD
146 trap '' SIGPIPE SIGCHLD
147 trap 'SOCAT=(); RETRY=$REPLY;' SIGUSR1
106 raw 148 raw
107 while read -r -N1 || [ $? -gt 128 ] 149 while [ "$RETRY" ] || read -t 0.1 -r -N1 || [ $? -gt 128 ]
108 do 150 do
151 REPLY=$RETRY$REPLY
152 RETRY=
109 if [ "$REPLY" ] 153 if [ "$REPLY" ]
110 then 154 then
111 sendc "$REPLY" 155 sendc "$REPLY"
@@ -120,7 +164,15 @@ set -o pipefail
120shopt -s lastpipe 164shopt -s lastpipe
121trap "screen -X quit" EXIT 165trap "screen -X quit" EXIT
122$(declare -f) 166$(declare -f)
123export PS1="$BOT_TITLE\$ " 167export PS1="\$BOT_TITLE\$ "
168
169if [ "\$SHOW_SOCAT_ERRORS" ]
170then
171 exec 20>&2
172else
173 exec 20>/dev/null
174fi
175
124\$BOT_CMD 176\$BOT_CMD
125. 177.
126 178