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