diff options
author | Andrew Cady <d@jerkface.net> | 2024-07-31 16:08:47 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2024-07-31 16:08:47 -0400 |
commit | a3a4b4f1af814bb1f50afc0677b09bb1f955d0e0 (patch) | |
tree | e2313fbc7f04fc3a76dbf84737cd4bbef353c976 /twopane.bash | |
parent | f348782c30ebf9550befe0d5cf378e5a9a942c1c (diff) |
this fuckin works
Diffstat (limited to 'twopane.bash')
-rw-r--r-- | twopane.bash | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/twopane.bash b/twopane.bash index b40f248..2b30a3b 100644 --- a/twopane.bash +++ b/twopane.bash | |||
@@ -4,8 +4,14 @@ set -f | |||
4 | set -o pipefail | 4 | set -o pipefail |
5 | shopt -s lastpipe | 5 | shopt -s lastpipe |
6 | 6 | ||
7 | BOT_SIZE=8 | ||
8 | BOT_TITLE=input | ||
9 | BOT_CMD='PS1="$BOT_TITLE\$ " bash --noprofile --norc -i' | ||
10 | TOP_CMD='PS1="$TOP_TITLE\$ " bash --noprofile --norc -i; screen -X quit' | ||
11 | TOP_TITLE=output | ||
12 | |||
7 | TWOPANE=$(mktemp -d) | 13 | TWOPANE=$(mktemp -d) |
8 | export TWOPANE | 14 | export TWOPANE TOP_CMD BOT_CMD TOP_TITLE BOT_TITLE BOT_SIZE |
9 | trap 'rm -r "$TWOPANE"' EXIT | 15 | trap 'rm -r "$TWOPANE"' EXIT |
10 | STY=twopane.${TWOPANE##*/} | 16 | STY=twopane.${TWOPANE##*/} |
11 | SCREENRC=$TWOPANE/screenrc | 17 | SCREENRC=$TWOPANE/screenrc |
@@ -16,43 +22,33 @@ escape `` | |||
16 | caption string '%t' | 22 | caption string '%t' |
17 | layout new | 23 | layout new |
18 | split | 24 | split |
19 | focus top | ||
20 | screen -ln -t 'output' bash -i | ||
21 | exec :!:| socat -U STDOUT UNIX-RECV:"$TWOPANE"/socket | ||
22 | title 'output' | ||
23 | focus bottom | 25 | focus bottom |
24 | resize 8 | 26 | resize $BOT_SIZE |
27 | screen -ln -t "$BOT_TITLE" 1 bash "$TWOPANE"/bashrc | ||
25 | focus top | 28 | focus top |
26 | fit | 29 | screen -ln -t "$TOP_TITLE" sh -c "$TOP_CMD" |
30 | exec :!:| socat -u UNIX-RECV:"$TWOPANE"/socket STDOUT | ||
31 | title 'output' | ||
27 | focus bottom | 32 | focus bottom |
28 | screen -ln -t 'input' 1 bash "$TWOPANE"/bashrc | ||
29 | layout save 0 | 33 | layout save 0 |
30 | . | 34 | . |
31 | 35 | ||
32 | cat > "$TWOPANE"/bashrc <<'.' | 36 | cat > "$TWOPANE"/bashrc <<'.' |
33 | set -e | ||
34 | trap "screen -X quit" EXIT | 37 | trap "screen -X quit" EXIT |
35 | coproc socat -u STDIN,cloexec=0 UNIX-SENDTO:"$TWOPANE"/socket | 38 | sendp() |
36 | exec 30>&${COPROC[1]} | ||
37 | send() | ||
38 | { | 39 | { |
39 | printf '%s\n' "$*" >&30 | 40 | socat -u STDIN UNIX-SENDTO:"$TWOPANE"/socket |
40 | } | 41 | } |
41 | sendc() | 42 | sendc() |
42 | { | 43 | { |
43 | printf '%s' "$*" >&30 | 44 | printf '%s' "$*" | sendp |
45 | } | ||
46 | send() | ||
47 | { | ||
48 | sendc "$*"$'\n' | ||
44 | } | 49 | } |
45 | send echo hello world | 50 | export -f send sendc sendp |
46 | sendc echo hello | 51 | eval "$BOT_CMD" |
47 | sleep 1 | ||
48 | send world2 | ||
49 | sleep 1 | ||
50 | send top | ||
51 | export -f send sendc | ||
52 | bash -i || true | ||
53 | sendc q | ||
54 | send echo hello world3 | ||
55 | sleep 1 | ||
56 | . | 52 | . |
57 | 53 | ||
58 | screen -c "$SCREENRC" -m -S "$STY" -ln | 54 | screen -c "$SCREENRC" -m -S "$STY" -ln |