Skip to content

Commit 5a3795c

Browse files
committed
Make it2ssh work on Ubuntu 18, Ubuntu 20, and macOS remote hosts
1 parent b6a9f91 commit 5a3795c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

ssh-helpers/conductor.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,21 @@ conductor_cmd_runpython() {
244244
really_run_python() {
245245
log really_run_python
246246
unset RCOUNT
247+
ttypath=$(tty)
248+
log "tty is $ttypath"
247249
exec python3 << ENDOFSCRIPT
248250
import os
249251
import sys
250-
tty_path = os.ttyname(sys.stdout.fileno())
252+
tty_path = "$ttypath"
251253
sys.stdin = open(tty_path, "r")
252254
try:
253-
print(f"\033]135;:{os.getpid()}\033\\\033]135;:end $boundary r 0\033\\\\", end="", flush=True)
255+
print(f"\\033]135;:{os.getpid()}\\033\\\\", end="", flush=True)
256+
print(f"\\033]135;:end $boundary r 0\\033\\\\", end="", flush=True)
254257
program=""
255258
for line in sys.stdin:
256259
if line.rstrip() == "EOF":
257260
exec(program)
258-
print(f"\033]135;:unhook\033\\\\", end="", flush=True)
261+
print(f"\\033]135;:unhook\\033\\\\", end="", flush=True)
259262
break
260263
program += line
261264
except Exception as e:

utilities/it2ssh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ fi
147147
send_conductor='printf "\033]1337;SendConductor'"$st"'"'
148148

149149
# Run a command on the remote host that instructs iTerm2 to send a script, then reads the script and executes it.
150-
sanitized="$send_conductor"';s="";IFS=""; stty -echo; while read -r l;do [ "$l" = EOF ]&&break; s="$s$l\n"; done; unset IFS; eval "$s"'
150+
# I tried many ways to concatenate s and l and this is the only one that works on both Ubuntu 18 and Ubuntu 20.
151+
sanitized="$send_conductor"';s="";IFS=""; stty -echo; while read -r l;do [ "$l" = EOF ]&&break; s=$(printf "%s\n%s" "$s" "$l"); done; unset IFS; eval "$s"'
151152

152153
# If ssh gets a signal, let it2ssh keep running.
153154
set +e

0 commit comments

Comments
 (0)