diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/twopane.bash | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/src/twopane.bash b/src/twopane.bash index 6003b8e..fe61dc2 100755 --- a/src/twopane.bash +++ b/src/twopane.bash | |||
@@ -120,12 +120,12 @@ layout save 0 | |||
120 | 120 | ||
121 | with_screen_pane() | 121 | with_screen_pane() |
122 | { | 122 | { |
123 | (( $# > 1 )) || return | 123 | (( $# >= 2 )) || return |
124 | declare -i PANE="$1" LOCK | 124 | declare -i PANE="$1" LOCK |
125 | (( PANE > 0 )) || return | 125 | (( PANE > 0 )) || return |
126 | ( | 126 | ( |
127 | flock $LOCK | 127 | flock $LOCK |
128 | "$2" "$1" "${@:3}" | 128 | "${@:2}" |
129 | ) {LOCK}>"$TWOPANE"/pane$PANE | 129 | ) {LOCK}>"$TWOPANE"/pane$PANE |
130 | } | 130 | } |
131 | 131 | ||
@@ -162,7 +162,7 @@ start_screen_pane() | |||
162 | fi | 162 | fi |
163 | TOP_TITLE="Command: ${*@Q}" | 163 | TOP_TITLE="Command: ${*@Q}" |
164 | screen -X focus top | 164 | screen -X focus top |
165 | screen -X screen -ln -t "$TOP_TITLE" 1 "$@" | 165 | screen -X screen -ln -t "$TOP_TITLE" "$PANE" "$@" |
166 | start_screen_pane_subprocess | 166 | start_screen_pane_subprocess |
167 | } | 167 | } |
168 | 168 | ||
@@ -170,7 +170,7 @@ start_screen_pane_subprocess() | |||
170 | { | 170 | { |
171 | (( PANE > 0 )) || return | 171 | (( PANE > 0 )) || return |
172 | subproc_command=( | 172 | subproc_command=( |
173 | exec -a top-pane-tty-forward | 173 | exec -a gnuscreen-input-filter |
174 | socat | 174 | socat |
175 | UNIX-LISTEN:"$TWOPANE"/socket | 175 | UNIX-LISTEN:"$TWOPANE"/socket |
176 | STDIN,cfmakeraw,opost=1,onlcr=1!!STDOUT | 176 | STDIN,cfmakeraw,opost=1,onlcr=1!!STDOUT |
@@ -305,6 +305,35 @@ TOP_PANE() | |||
305 | esac | 305 | esac |
306 | } | 306 | } |
307 | 307 | ||
308 | magic_fifo() | ||
309 | { | ||
310 | # Some bash magic from superuser.com. | ||
311 | # Use two PIDs instead of one inode to make fifo. (Not just | ||
312 | # less expensive but more robust, except! uses Linux procfs.) | ||
313 | # https://superuser.com/questions/184307/bash-create-anonymous-fifo | ||
314 | declare -n fd_out="$1" | ||
315 | local fd_in reader writer | ||
316 | { | ||
317 | sleep 1 | sleep 1 & | ||
318 | reader=$! | ||
319 | writer=$(jobs -p %+) | ||
320 | disown | ||
321 | } &>/dev/null | ||
322 | exec {fd_out}>/proc/$writer/fd/1 {fd_in}</proc/$reader/fd/0 | ||
323 | quiet_bg "${@:2}" <&"$fd_in" | ||
324 | } | ||
325 | |||
326 | ordinary_fifo() | ||
327 | { | ||
328 | declare -n fd_out="$1" | ||
329 | local fifo | ||
330 | fifo=$TWOPANE/sink_${!fd}.fifo | ||
331 | mkfifo "$fifo" | ||
332 | exec {fd_out}<>"$fifo" | ||
333 | rm "$fifo" | ||
334 | quiet_bg "${@:2}" <&"$fd_out" | ||
335 | } | ||
336 | |||
308 | connect_sink() | 337 | connect_sink() |
309 | { | 338 | { |
310 | (( $# > 0 )) || set -- SINK | 339 | (( $# > 0 )) || set -- SINK |
@@ -316,7 +345,13 @@ connect_sink() | |||
316 | return | 345 | return |
317 | fi | 346 | fi |
318 | i "sink starting: ${!fd}" | 347 | i "sink starting: ${!fd}" |
319 | exec {fd}> >("${@:2}") | 348 | |
349 | if false && mountpoint -q /proc | ||
350 | then | ||
351 | magic_fifo fd "${@:2}" | ||
352 | else | ||
353 | ordinary_fifo fd "${@:2}" | ||
354 | fi | ||
320 | pid=$! | 355 | pid=$! |
321 | } | 356 | } |
322 | 357 | ||
@@ -349,10 +384,14 @@ quiet_bg() | |||
349 | # write to stdout | 384 | # write to stdout |
350 | # write to $TOP_PANE_OUT | 385 | # write to $TOP_PANE_OUT |
351 | # I.e.: | 386 | # I.e.: |
352 | # read from /dev/tty | 387 | # read from /dev/tty on stdin |
353 | # read from the socat-coproc-forwarded /dev/tty in the top pane. | 388 | # read from the socat-coproc forwarding the top pane's tty input. |
354 | # write to /dev/tty | 389 | # write to /dev/tty on stdout |
355 | # write to the socat-coproc-forwarded /dev/tty in the top pane. | 390 | # write to the socat-coproc forwarding tty input into the top pane. |
391 | # | ||
392 | # For the network it is just an echo, | ||
393 | # here we could place an input filter, | ||
394 | # but we have none. | ||
356 | echo_sender() | 395 | echo_sender() |
357 | { | 396 | { |
358 | (exec -a echo_sender socat - fd:${TOP_PANE_IN?$0: Internal error}!!-) | | 397 | (exec -a echo_sender socat - fd:${TOP_PANE_IN?$0: Internal error}!!-) | |