summaryrefslogtreecommitdiff
path: root/src/rpc.bash
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2023-08-26 10:35:00 -0400
committerAndrew Cady <d@jerkface.net>2023-08-26 10:35:00 -0400
commit09b30ddf5d4b1e7ff72fa07b7d8a0563ecb949cf (patch)
tree862b7f9ca50b7947ece73d5c6110ff1f52e60235 /src/rpc.bash
parent03eb0cad29e677f0b1e49f7eba8e581ecaaa2018 (diff)
make tty work with new hack
Diffstat (limited to 'src/rpc.bash')
-rw-r--r--src/rpc.bash41
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
69with_ssh_option() 69bash_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
90remote_run_function_simple() 90bash_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
98remote_run_function() 98remote_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
116remote_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")
130END
131 exec ssh localhost -t -- bash -c "${bashcode@Q}" bash "$@"
132 )
133}
134
135remote_run_function()
136{
137 if [ -t 0 ]
138 then
139 remote_run_function_tty "$@"
140 else
141 remote_run_function_notty "$@"
142 fi
143}