Skip to content

Commit 0d2d173

Browse files
lroolleclaude
andcommitted
fix(tmux): login-shell-proof remote invocations, honor shim -q
- remote ssh commands pass the tmux path and args as positionals to a fixed sh -c script: the login shell (zsh/fish) only parses quoted words, sh does the expansion. No exec before a || fallback — a successful exec would make the fallback unreachable. - deva-bridge-tmux shim: -q suppresses info lines again (stdout to /dev/null, warnings/errors stay on stderr), matching the old script. Verified live: ls, spaced-arg tmux passthrough, bridge lifecycle. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 255f4a7 commit 0d2d173

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

scripts/deva-bridge-tmux

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ Prefer: deva-tmux bridge start (auto-selects ssh when provisioned)
2020
EOF
2121
}
2222

23+
QUIET=0
24+
2325
while [ $# -gt 0 ]; do
2426
case $1 in
2527
-h | --help) usage; exit 0 ;;
26-
-q | --quiet) ;;
28+
-q | --quiet) QUIET=1 ;;
2729
-H | --host)
2830
[ $# -ge 2 ] || { echo "$prog: missing value for $1" >&2; exit 1; }
2931
DEVA_BRIDGE_HOST="$2"; export DEVA_BRIDGE_HOST; shift ;;
@@ -38,4 +40,9 @@ while [ $# -gt 0 ]; do
3840
shift
3941
done
4042

43+
# -q matched the old script's behavior: info lines suppressed, warnings
44+
# and errors still on stderr.
45+
if [ "$QUIET" -eq 1 ]; then
46+
exec deva-tmux bridge start --transport socat --foreground >/dev/null
47+
fi
4148
exec deva-tmux bridge start --transport socat --foreground

scripts/deva-tmux

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,14 @@ host_tmux_bin() {
8383
die "tmux not found on host ($(host_target))"
8484
}
8585

86+
# Remote invocations pass the tmux path (and args) as positionals to a
87+
# fixed `sh -c` script: the login shell only ever parses quoted words, and
88+
# sh — not zsh/fish — does the expansion. No exec before a || fallback:
89+
# a successful exec would make the fallback unreachable.
8690
host_tmux_socket() {
8791
local bin="$1"
88-
hssh "$(host_target)" "sh -c '$bin display-message -p \"#{socket_path}\" 2>/dev/null || echo /tmp/tmux-\$(id -u)/default'"
92+
hssh "$(host_target)" \
93+
"sh -c '\"\$0\" display-message -p \"#{socket_path}\" 2>/dev/null || echo /tmp/tmux-\$(id -u)/default' $(printf '%q' "$bin")"
8994
}
9095

9196
# --- socat transport ---------------------------------------------------------
@@ -189,7 +194,7 @@ cmd_ls() {
189194
if [[ "$transport" == "ssh" ]]; then
190195
local bin
191196
bin=$(host_tmux_bin)
192-
hssh "$(host_target)" "$bin ls"
197+
hssh "$(host_target)" "sh -c 'exec \"\$0\" ls' $(printf '%q' "$bin")"
193198
else
194199
ensure_bridge socat
195200
tmux -S "$BRIDGE_SOCK" ls
@@ -201,11 +206,14 @@ cmd_attach() {
201206
local transport
202207
transport=$(resolve_transport)
203208
if [[ "$transport" == "ssh" ]]; then
204-
local bin cmd="attach"
209+
local bin
205210
bin=$(host_tmux_bin)
206-
[[ -n "${1:-}" ]] && cmd="new-session -A -s $(printf '%q' "$1")"
207211
mkdir -p "$STATE_DIR"
208-
exec ssh -t "${SSH_OPTS[@]}" "$(host_target)" "$bin $cmd"
212+
if [[ -n "${1:-}" ]]; then
213+
exec ssh -t "${SSH_OPTS[@]}" "$(host_target)" \
214+
"sh -c 'exec \"\$0\" new-session -A -s \"\$1\"' $(printf '%q ' "$bin" "$1")"
215+
fi
216+
exec ssh -t "${SSH_OPTS[@]}" "$(host_target)" "sh -c 'exec \"\$0\" attach' $(printf '%q' "$bin")"
209217
else
210218
ensure_bridge socat
211219
if [[ -n "${1:-}" ]]; then
@@ -222,7 +230,7 @@ cmd_tmux() {
222230
if [[ "$transport" == "ssh" ]]; then
223231
local bin
224232
bin=$(host_tmux_bin)
225-
hssh "$(host_target)" "$bin $(printf '%q ' "$@")"
233+
hssh "$(host_target)" "sh -c 'exec \"\$0\" \"\$@\"' $(printf '%q ' "$bin" "$@")"
226234
else
227235
ensure_bridge socat
228236
tmux -S "$BRIDGE_SOCK" "$@"

0 commit comments

Comments
 (0)