diff options
Diffstat (limited to 'twopane.bash')
-rw-r--r-- | twopane.bash | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/twopane.bash b/twopane.bash index f3aff57..91b9f1a 100644 --- a/twopane.bash +++ b/twopane.bash | |||
@@ -58,42 +58,71 @@ title 'input' | |||
58 | source "$TWOPANE"/screenrc.startpane | 58 | source "$TWOPANE"/screenrc.startpane |
59 | . | 59 | . |
60 | 60 | ||
61 | TWOPANE_FUNCTION_EXPORTS='restart sendp sendc send start' | ||
62 | restart() | 61 | restart() |
63 | { | 62 | { |
64 | screen -X source "$TWOPANE"/screenrc.restart | 63 | screen -X source "$TWOPANE"/screenrc.restart |
65 | } | 64 | } |
66 | sendp() | 65 | sendp() |
67 | { | 66 | { |
68 | socat -u STDIN UNIX-SENDTO:"$TWOPANE"/socket | 67 | trap "kill -SIGUSR1 $1" EXIT |
68 | socat -u STDIN UNIX-SENDTO:"$TWOPANE"/socket || restart | ||
69 | } | 69 | } |
70 | sendc() | 70 | sendc() |
71 | { | 71 | { |
72 | [ "${COPROC[1]}" ] || coproc sendp | 72 | [ "${COPROC[1]}" ] || coproc { sendp $$; } |
73 | printf '%s' "$*" >&${COPROC[1]} | 73 | printf '%s' "$*" >&${COPROC[1]} |
74 | } | 74 | } |
75 | send() | 75 | send() |
76 | { | 76 | { |
77 | [ "${COPROC[1]}" ] || coproc sendp | 77 | [ "${COPROC[1]}" ] || coproc { sendp $$; } |
78 | printf '%s' "$*"$'\n' >&${COPROC[1]} | 78 | printf '%s' "$*"$'\n' >&${COPROC[1]} |
79 | } | 79 | } |
80 | |||
81 | sendcc() { sendc $'\003'; } | ||
82 | |||
83 | raw() | ||
84 | { | ||
85 | stty_opts=( | ||
86 | cbreak | ||
87 | raw | ||
88 | -isig | ||
89 | -iexten | ||
90 | -nl | ||
91 | intr undef | ||
92 | quit undef | ||
93 | #erase undef | ||
94 | #kill undef | ||
95 | eof undef | ||
96 | start undef | ||
97 | stop undef | ||
98 | susp undef | ||
99 | lnext undef | ||
100 | ) | ||
101 | stty "${stty_opts[@]}" | ||
102 | } | ||
103 | |||
80 | start() | 104 | start() |
81 | { | 105 | { |
82 | [ "${COPROC[1]}" ] || coproc sendp | 106 | trap ': SIGPIPE ${COPROC[@]@A}' SIGPIPE |
83 | while read -r -N1 </dev/tty | 107 | trap ': SIGCHLD ${COPROC[@]@A}' SIGCHLD |
108 | trap ': SIGUSR1 ${COPROC[@]@A}; COPROC=()' SIGUSR1 | ||
109 | raw | ||
110 | while read -r -N1 || [ $? -gt 128 ] | ||
84 | do | 111 | do |
85 | [ "${COPROC[1]}" ] || break | 112 | if [ "$REPLY" ] |
86 | printf '%s' "$REPLY" | 113 | then |
87 | done >&${COPROC[1]} | 114 | sendc "$REPLY" |
115 | fi | ||
116 | done | ||
88 | } | 117 | } |
89 | 118 | ||
90 | save_file bashrc <<. | 119 | save_file bashrc <<. |
91 | set -f | 120 | set -f |
121 | set -b | ||
92 | set -o pipefail | 122 | set -o pipefail |
93 | shopt -s lastpipe | 123 | shopt -s lastpipe |
94 | trap 'COPROC=()' SIGPIPE | ||
95 | trap "screen -X quit" EXIT | 124 | trap "screen -X quit" EXIT |
96 | $(declare -f $TWOPANE_FUNCTION_EXPORTS | sed 's/ COPROC / /') | 125 | $(declare -f) |
97 | export PS1="$BOT_TITLE\$ " | 126 | export PS1="$BOT_TITLE\$ " |
98 | \$BOT_CMD | 127 | \$BOT_CMD |
99 | . | 128 | . |