summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--[-rwxr-xr-x]twopane.bash38
1 files changed, 25 insertions, 13 deletions
diff --git a/twopane.bash b/twopane.bash
index b9c1051..5ba1264 100755..100644
--- a/twopane.bash
+++ b/twopane.bash
@@ -3,6 +3,7 @@ set -e
3set -f 3set -f
4set -o pipefail 4set -o pipefail
5shopt -s lastpipe 5shopt -s lastpipe
6PROGNAME=${0##*/}
6 7
7BOT_SIZE=8 8BOT_SIZE=8
8BOT_TITLE=input 9BOT_TITLE=input
@@ -14,10 +15,10 @@ TWOPANE=$(mktemp -d)
14export TWOPANE TOP_CMD BOT_CMD TOP_TITLE BOT_TITLE BOT_SIZE 15export TWOPANE TOP_CMD BOT_CMD TOP_TITLE BOT_TITLE BOT_SIZE
15trap 'rm -r "$TWOPANE"' EXIT 16trap 'rm -r "$TWOPANE"' EXIT
16STY=twopane.${TWOPANE##*/} 17STY=twopane.${TWOPANE##*/}
18
17save_file() 19save_file()
18{ 20{
19 out=$TWOPANE/${1:?$0: filename cannot be empty string} 21 cat > "$TWOPANE"/"${1:?$PROGNAME: Error: filename cannot be empty string}"
20 cat > "$out"
21} 22}
22save_screenrc() 23save_screenrc()
23{ 24{
@@ -32,7 +33,7 @@ layout new
32split 33split
33focus bottom 34focus bottom
34resize $BOT_SIZE 35resize $BOT_SIZE
35screen -ln -t "$BOT_TITLE" 0 bash "$TWOPANE"/bashrc 36screen -ln -t "$BOT_TITLE" 0 bash --noprofile --rcfile "$TWOPANE"/bashrc -x -i
36 37
37source "$TWOPANE"/screenrc.startpane 38source "$TWOPANE"/screenrc.startpane
38. 39.
@@ -46,7 +47,7 @@ focus bottom
46layout save 0 47layout save 0
47. 48.
48 49
49save_screenrc 'restart' <<'.' 50save_screenrc 'restart' <<.
50layout new 51layout new
51split 52split
52focus bottom 53focus bottom
@@ -57,8 +58,7 @@ title 'input'
57source "$TWOPANE"/screenrc.startpane 58source "$TWOPANE"/screenrc.startpane
58. 59.
59 60
60save_file bashrc <<'.' 61TWOPANE_FUNCTION_EXPORTS='restart sendp sendc send start'
61trap "screen -X quit" EXIT
62restart() 62restart()
63{ 63{
64 screen -X source "$TWOPANE"/screenrc.restart 64 screen -X source "$TWOPANE"/screenrc.restart
@@ -69,22 +69,34 @@ sendp()
69} 69}
70sendc() 70sendc()
71{ 71{
72 printf '%s' "$*" | sendp 72 printf '%s' "$*" >&${COPROC[1]}
73} 73}
74send() 74send()
75{ 75{
76 sendc "$*"$'\n' 76 printf '%s' "$*"$'\n' >&${COPROC[1]}
77} 77}
78start() 78start()
79{ 79{
80 while read -r -N1 80 while read -r -N1
81 do 81 do
82 sendc "$REPLY" 82 printf '%s' "$REPLY" >&${COPROC[1]}
83 done 83 done
84} 84}
85export -f restart sendp sendc send start 85
86bash -c "$BOT_CMD" || read -p "Error: process terminated with exit code $? 86save_file bashrc <<.
87Press enter to quit." 87set -x
88set -f
89set -o pipefail
90shopt -s lastpipe
91trap "screen -X quit" EXIT
92$(declare -f $TWOPANE_FUNCTION_EXPORTS)
93export PS1="$BOT_TITLE\$ "
94coproc sendp
88. 95.
89 96
90screen -c "$TWOPANE"/screenrc -m -S "$STY" -ln 97main()
98{
99 screen -c "$TWOPANE"/screenrc -m -S "$STY" -ln
100}
101
102main "$@"