summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2024-08-13 16:53:29 -0400
committerAndrew Cady <d@jerkface.net>2024-08-13 16:53:29 -0400
commit2455cea6629bf54c35cb0cdc590b0174c4d1f8f2 (patch)
tree7b089606e5204d8d72e52cf9f346abb45215caea
parent5bacc03a5bb334649683b4625cc3ad85b8073632 (diff)
up-to-date bash can choose a new fd automatically!
-rwxr-xr-xtwopane.bash11
1 files changed, 4 insertions, 7 deletions
diff --git a/twopane.bash b/twopane.bash
index 2a530db..0001f60 100755
--- a/twopane.bash
+++ b/twopane.bash
@@ -119,15 +119,12 @@ connect()
119 return 1 119 return 1
120 ;; 120 ;;
121 esac 121 esac
122 std0=${1:-200}
123 std1=${2:-201}
124 if ! [ "${SOCAT[0]}" ] 122 if ! [ "${SOCAT[0]}" ]
125 then 123 then
126 disconnect $std0 $std1
127 coproc SOCAT { socat_connect; } 124 coproc SOCAT { socat_connect; }
128 fi 125 fi
129 pid=${SOCAT_PID} 126 pid=${SOCAT_PID}
130 eval "exec ${std0}<&${SOCAT[0]} ${std1}>&${SOCAT[1]}" 127 eval "exec {std0}<&${SOCAT[0]} {std1}>&${SOCAT[1]}"
131} 128}
132 129
133sendc() 130sendc()
@@ -144,7 +141,7 @@ send()
144 141
145disconnect() 142disconnect()
146{ 143{
147 eval "exec ${1:-200}<&- ${2:-201}>&-" 144 [ "$1" -a "$2" ] && eval "exec $1<&- $2>&-"
148 wait -f "$SOCAT_PID" 2>/dev/null 145 wait -f "$SOCAT_PID" 2>/dev/null
149} 146}
150 147
@@ -215,7 +212,7 @@ focus()
215 212
216output_filter() 213output_filter()
217{ 214{
218 exec 15> >(exec cat -v) 215 exec {OUTPUT_FILTER}> >(exec cat -v)
219 while read -r -N1 216 while read -r -N1
220 do 217 do
221 case "$REPLY" in 218 case "$REPLY" in
@@ -228,7 +225,7 @@ output_filter()
228 then 225 then
229 printf '%s' "$REPLY" 226 printf '%s' "$REPLY"
230 else 227 else
231 printf '%s' "$REPLY" >&15 228 printf '%s' "$REPLY" >&${OUTPUT_FILTER}
232 fi 229 fi
233 done 230 done
234} 231}