diff options
author | Andrew Cady <d@jerkface.net> | 2023-08-26 10:35:00 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2023-08-26 10:35:00 -0400 |
commit | 09b30ddf5d4b1e7ff72fa07b7d8a0563ecb949cf (patch) | |
tree | 862b7f9ca50b7947ece73d5c6110ff1f52e60235 | |
parent | 03eb0cad29e677f0b1e49f7eba8e581ecaaa2018 (diff) |
make tty work with new hack
-rw-r--r-- | src/rpc.bash | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/src/rpc.bash b/src/rpc.bash index 44f7020..5e39851 100644 --- a/src/rpc.bash +++ b/src/rpc.bash | |||
@@ -66,7 +66,7 @@ bash_rpc_remote_run_script() | |||
66 | "$SHELL" -c "${script@Q}" "$0" "${@@Q}" | 66 | "$SHELL" -c "${script@Q}" "$0" "${@@Q}" |
67 | } | 67 | } |
68 | 68 | ||
69 | with_ssh_option() | 69 | bash_rpc_with_ssh_option() |
70 | { | 70 | { |
71 | local BASH_RPC_SSH_OPTIONS | 71 | local BASH_RPC_SSH_OPTIONS |
72 | BASH_RPC_SSH_OPTIONS+=("$1") | 72 | BASH_RPC_SSH_OPTIONS+=("$1") |
@@ -87,7 +87,7 @@ bash_rpc_eval_stdin() | |||
87 | eval "unset REPLY; $(cat <<< "$REPLY")" | 87 | eval "unset REPLY; $(cat <<< "$REPLY")" |
88 | } | 88 | } |
89 | 89 | ||
90 | remote_run_function_simple() | 90 | bash_rpc_run_function_simple() |
91 | { | 91 | { |
92 | script_source=$(declare -f "$1" && printf '"$@";\n') | 92 | script_source=$(declare -f "$1" && printf '"$@";\n') |
93 | bash_rpc_remote_run_script \ | 93 | bash_rpc_remote_run_script \ |
@@ -95,24 +95,49 @@ remote_run_function_simple() | |||
95 | "$@" | 95 | "$@" |
96 | } | 96 | } |
97 | 97 | ||
98 | remote_run_function() | 98 | remote_run_function_notty() |
99 | { | 99 | { |
100 | main=$1 | 100 | main=$1 |
101 | funcs=$(recursive_dependencies "$main") | 101 | funcs=$(recursive_dependencies "$main") |
102 | stage2_source=$( | 102 | stage2_source=$( |
103 | declare -f $funcs | 103 | declare -f $funcs |
104 | printf '"$@"\n' "$main" | 104 | printf '"$@"\n' |
105 | ) | 105 | ) |
106 | |||
107 | local BASH_RPC_STDIN_IS_TTY=$([ ! -t 0 ] || echo y) | ||
108 | { | 106 | { |
109 | printf '%s' "$stage2_source" | 107 | printf '%s' "$stage2_source" |
110 | cat | 108 | cat |
111 | } | | 109 | } | |
112 | ${BASH_RPC_STDIN_IS_TTY:+ with_ssh_option '-tt'} \ | 110 | bash_rpc_run_function_simple \ |
113 | remote_run_function_simple \ | ||
114 | bash_rpc_eval_stdin \ | 111 | bash_rpc_eval_stdin \ |
115 | "${#stage2_source}" \ | 112 | "${#stage2_source}" \ |
116 | "$@" | 113 | "$@" |
117 | } | 114 | } |
118 | 115 | ||
116 | remote_run_function_tty() | ||
117 | { | ||
118 | main=$1 | ||
119 | funcs=$(recursive_dependencies "$main") | ||
120 | stage2_source=$( | ||
121 | declare -f $funcs | ||
122 | printf 'TERM=%s\n' "${TERM@Q}" | ||
123 | printf '"$@"\n' | ||
124 | ) | ||
125 | ( | ||
126 | TERM="$stage2_source" | ||
127 | export TERM | ||
128 | read -r bashcode <<'END' | ||
129 | :; rpc=$TERM; TERM=screen; source <(printf '%s' "$rpc") | ||
130 | END | ||
131 | exec ssh localhost -t -- bash -c "${bashcode@Q}" bash "$@" | ||
132 | ) | ||
133 | } | ||
134 | |||
135 | remote_run_function() | ||
136 | { | ||
137 | if [ -t 0 ] | ||
138 | then | ||
139 | remote_run_function_tty "$@" | ||
140 | else | ||
141 | remote_run_function_notty "$@" | ||
142 | fi | ||
143 | } | ||