When VS Code is started from Activities (i.e. via the UI), I receive an error message, "Unable to resolve your shell environment: Unexpected exit code from spawned shell (code 1, signal null)". This is happening because the last block in my rc file (zsh, not that it should matter here) is:
if command -v tmux &> /dev/null \
&& [ -n "$PS1" ] \
&& [[ ! "$TERM" =~ screen ]] \
&& [[ ! "$TERM" =~ tmux ]] \
&& [ -z "$TMUX" ] \
&& [[ "$TERM_PROGRAM" != "vscode" ]]; then
exec tmux
fi
I got the tmux-specific part of the guard here and the Code-specific part here. However, when Code is running the "small process to run (or 'resolve') the shell environment" described here, $TERM_PROGRAM
does not appear to be set, so exec tmux
still runs, hence the error.
How can I detect that the environment resolver is running? Does it set any other variables that I can test?
EDIT: I realized I could just list the environment out to file in my rc, and I found a number of variables prefixed with VSCODE_
, namely the following:
VSCODE_CODE_CACHE_PATH
VSCODE_CWD
VSCODE_IPC_HOOK
VSCODE_NLS_CONFIG
VSCODE_PID
Is testing for any of these reliable in this context?
CodePudding user response:
Checking the process tree is a consistent and reliable way to do this in either scenario (integrated terminal or environment resolution process). Specifically, my .zshrc
now ends as follows:
if ... (tmux conditions) \
&& ! pstree -s $$ | grep -wq code; then
exec tmux
fi