From 6232b624e10c91c8dd37206147c3672cdccd4836 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Tue, 27 Aug 2024 21:32:45 -0400 Subject: the magic breaks top restarts somehow?? --- src/twopane.bash | 57 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file 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 with_screen_pane() { - (( $# > 1 )) || return + (( $# >= 2 )) || return declare -i PANE="$1" LOCK (( PANE > 0 )) || return ( flock $LOCK - "$2" "$1" "${@:3}" + "${@:2}" ) {LOCK}>"$TWOPANE"/pane$PANE } @@ -162,7 +162,7 @@ start_screen_pane() fi TOP_TITLE="Command: ${*@Q}" screen -X focus top - screen -X screen -ln -t "$TOP_TITLE" 1 "$@" + screen -X screen -ln -t "$TOP_TITLE" "$PANE" "$@" start_screen_pane_subprocess } @@ -170,7 +170,7 @@ start_screen_pane_subprocess() { (( PANE > 0 )) || return subproc_command=( - exec -a top-pane-tty-forward + exec -a gnuscreen-input-filter socat UNIX-LISTEN:"$TWOPANE"/socket STDIN,cfmakeraw,opost=1,onlcr=1!!STDOUT @@ -305,6 +305,35 @@ TOP_PANE() esac } +magic_fifo() +{ + # Some bash magic from superuser.com. + # Use two PIDs instead of one inode to make fifo. (Not just + # less expensive but more robust, except! uses Linux procfs.) + # https://superuser.com/questions/184307/bash-create-anonymous-fifo + declare -n fd_out="$1" + local fd_in reader writer + { + sleep 1 | sleep 1 & + reader=$! + writer=$(jobs -p %+) + disown + } &>/dev/null + exec {fd_out}>/proc/$writer/fd/1 {fd_in}"$fifo" + rm "$fifo" + quiet_bg "${@:2}" <&"$fd_out" +} + connect_sink() { (( $# > 0 )) || set -- SINK @@ -316,7 +345,13 @@ connect_sink() return fi i "sink starting: ${!fd}" - exec {fd}> >("${@:2}") + + if false && mountpoint -q /proc + then + magic_fifo fd "${@:2}" + else + ordinary_fifo fd "${@:2}" + fi pid=$! } @@ -349,10 +384,14 @@ quiet_bg() # write to stdout # write to $TOP_PANE_OUT # I.e.: -# read from /dev/tty -# read from the socat-coproc-forwarded /dev/tty in the top pane. -# write to /dev/tty -# write to the socat-coproc-forwarded /dev/tty in the top pane. +# read from /dev/tty on stdin +# read from the socat-coproc forwarding the top pane's tty input. +# write to /dev/tty on stdout +# write to the socat-coproc forwarding tty input into the top pane. +# +# For the network it is just an echo, +# here we could place an input filter, +# but we have none. echo_sender() { (exec -a echo_sender socat - fd:${TOP_PANE_IN?$0: Internal error}!!-) | -- cgit v1.2.3