summaryrefslogtreecommitdiff
path: root/twopane.bash
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2024-08-12 22:13:35 -0400
committerAndrew Cady <d@jerkface.net>2024-08-12 22:13:35 -0400
commite4676918d5444330a31e99267f2c6651f473616f (patch)
treec470e903b06df5856c032ca0b1a088a1b814b2d6 /twopane.bash
parent824eaf9a3752acde57f6d31f782c6be8f0747647 (diff)
restarting better
Diffstat (limited to 'twopane.bash')
-rwxr-xr-xtwopane.bash45
1 files changed, 27 insertions, 18 deletions
diff --git a/twopane.bash b/twopane.bash
index f1807ea..b53be1a 100755
--- a/twopane.bash
+++ b/twopane.bash
@@ -44,24 +44,33 @@ split
44focus bottom 44focus bottom
45resize $BOT_SIZE 45resize $BOT_SIZE
46screen -ln -t "$BOT_TITLE" 0 bash --noprofile --rcfile "$TWOPANE"/bashrc -i 46screen -ln -t "$BOT_TITLE" 0 bash --noprofile --rcfile "$TWOPANE"/bashrc -i
47source "$TWOPANE"/screenrc.startpane
48layout save 0 47layout save 0
49. 48.
50 49
51save_screenrc 'startpane' <<. 50kill_top()
52focus top
53screen -ln -t "\$TOP_TITLE" 1 $TOP_CMD
54exec .!. sh -c 'socat UNIX-LISTEN:"\$TWOPANE"/socket STDIN,rawer!!STDOUT'
55focus top
56.
57
58restart_top()
59{ 51{
60 while screen -p1 -Q info >/dev/null 52 while screen -p1 -Q info >/dev/null
61 do 53 do
62 screen -p1 -X kill 54 screen -p1 -X kill
63 done 55 done
64 screen -X source "$TWOPANE"/screenrc.startpane 56}
57
58start_top()
59{
60 if [ $# -gt 0 ]
61 then
62 TOP_CMD=$*
63 TOP_TITLE="Command: $TOP_CMD"
64 fi
65 screen -X focus top
66 screen -X screen -ln -t "$TOP_TITLE" 1 $TOP_CMD
67 screen -p1 -X exec .!. sh -c 'exec socat UNIX-LISTEN:"$TWOPANE"/socket STDIN,rawer!!STDOUT'
68}
69
70restart_top()
71{
72 kill_top
73 start_top $*
65} 74}
66 75
67socat_connect() 76socat_connect()
@@ -76,6 +85,7 @@ connect()
76 case $# in 85 case $# in
77 2 ) declare -n std0="$1" std1="$2"; local pid ;; 86 2 ) declare -n std0="$1" std1="$2"; local pid ;;
78 3 ) declare -n pid="$1" std0="$2" std1="$3" ;; 87 3 ) declare -n pid="$1" std0="$2" std1="$3" ;;
88 0 ) local std0 std1 pid ;;
79 * ) exit 1 ;; 89 * ) exit 1 ;;
80 esac 90 esac
81 std0=${3:-200} 91 std0=${3:-200}
@@ -113,10 +123,11 @@ start()
113{ 123{
114 if [ "$STARTED" ] 124 if [ "$STARTED" ]
115 then 125 then
116 restart_top 126 kill_top
117 else 127 else
118 STARTED=y 128 STARTED=y
119 fi 129 fi
130 start_top $*
120 socat_stty_opts=( 131 socat_stty_opts=(
121 rawer 132 rawer
122 echo=0 133 echo=0
@@ -208,16 +219,14 @@ our_bashrc_main()
208 set -o pipefail 219 set -o pipefail
209 shopt -s lastpipe 220 shopt -s lastpipe
210 trap "screen -X quit" EXIT 221 trap "screen -X quit" EXIT
211 export PS1="\$BOT_TITLE\$ " 222 export PS1="$BOT_TITLE\\\$ "
212 if [ "\$SHOW_SOCAT_ERRORS" ]
213 then
214 exec 20>&2
215 else
216 exec 20>/dev/null
217 fi
218} 223}
219 224
220save_file bashrc <<. 225save_file bashrc <<.
226${TOP_CMD@A}
227${BOT_CMD@A}
228${TOP_TITLE@A}
229${BOT_TITLE@A}
221$(declare -f) 230$(declare -f)
222our_bashrc_main 231our_bashrc_main
223\$BOT_CMD 232\$BOT_CMD