fix(shell): don't exec tmux during VS Code's shell-env probe #73

Merged
lyrathorpe merged 1 commits from fix/vscode-shell-env-tmux-guard into main 2026-07-14 16:48:16 +01:00
Showing only changes of commit 2125dd7aac - Show all commits
+11
View File
@@ -96,6 +96,15 @@ in
# runs before oh-my-zsh/compinit so the exec replaces the shell before # runs before oh-my-zsh/compinit so the exec replaces the shell before
# that setup is wasted. Guards, each preventing a real breakage: # that setup is wasted. Guards, each preventing a real breakage:
# interactive only -> don't hijack scp / `ssh host cmd` / scripted shells # interactive only -> don't hijack scp / `ssh host cmd` / scripted shells
# stdout is a tty -> VS Code (macOS) resolves the shell environment on
# startup by running an interactive login shell with
# stdout piped, no controlling terminal. Without this
# guard `exec tmux` runs there, fails ("open terminal
# failed: not a terminal"), exits non-zero, and VS
# Code reports "Unable to resolve your shell
# environment". A real terminal always has a tty here.
# not VS Code env -> also skip VS Code's env-resolution probe explicitly,
# in case a future version allocates a pty for it.
# $TMUX empty -> a pane's zsh won't re-exec tmux (infinite loop) # $TMUX empty -> a pane's zsh won't re-exec tmux (infinite loop)
# not SSH -> don't force inbound SSH logins into a server tmux # not SSH -> don't force inbound SSH logins into a server tmux
# not VS Code -> its integrated terminal manages itself # not VS Code -> its integrated terminal manages itself
@@ -103,6 +112,8 @@ in
# $NO_TMUX unset -> escape hatch: `NO_TMUX=1 <term>` opens a bare shell # $NO_TMUX unset -> escape hatch: `NO_TMUX=1 <term>` opens a bare shell
(lib.mkOrder 200 '' (lib.mkOrder 200 ''
if [[ $- == *i* ]] \ if [[ $- == *i* ]] \
&& [[ -t 1 ]] \
&& [[ -z "$VSCODE_RESOLVING_ENVIRONMENT" ]] \
&& [[ -z "$TMUX" ]] \ && [[ -z "$TMUX" ]] \
&& [[ -z "$NO_TMUX" ]] \ && [[ -z "$NO_TMUX" ]] \
&& [[ -z "$SSH_CONNECTION" && -z "$SSH_TTY" ]] \ && [[ -z "$SSH_CONNECTION" && -z "$SSH_TTY" ]] \