mirror of
https://github.com/rait-09/obsidian-agent-client.git
synced 2026-07-22 16:30:32 +00:00
fix: avoid intermediate variables in WSL shell wrapper
wsl.exe pre-expands $VAR references before passing them to the Linux
shell. Intermediate variables assigned within the command are not in
the WSL environment and get expanded to empty strings, breaking agent
spawning and Auto-detect in WSL mode.
Use ${SHELL:-/bin/sh} directly in the case/exec statements instead of
assigning to $s. Fallback changed from /bin/bash to /bin/sh for
compatibility with systems where /bin/bash is absent (#131).
This commit is contained in:
parent
84263bd480
commit
fce40a361e
2 changed files with 10 additions and 8 deletions
|
|
@ -72,15 +72,16 @@ export function resolveCommandPathInWsl(
|
|||
args.push("-d", distribution);
|
||||
}
|
||||
// Use the same wrapper as wrapCommandForWsl so PATH resolution context is identical:
|
||||
// source ~/.profile (linuxbrew, mise, etc.), detect user's $SHELL, fall back to bash
|
||||
// source ~/.profile (linuxbrew, mise, etc.), detect user's $SHELL, fall back to /bin/sh
|
||||
// for non-POSIX shells (fish, elvish, nushell, xonsh).
|
||||
const innerCommand = `which '${escaped}'`;
|
||||
const innerEscaped = innerCommand.replace(/'/g, "'\\''");
|
||||
const wrapperCommand =
|
||||
`. ~/.profile 2>/dev/null; ` +
|
||||
`s="\${SHELL:-/bin/bash}"; ` +
|
||||
`case "$s" in */fish|*/elvish|*/nushell|*/xonsh) s=/bin/bash ;; esac; ` +
|
||||
`exec "$s" -l -c '${innerEscaped}'`;
|
||||
`case \${SHELL:-/bin/sh} in ` +
|
||||
`*/fish|*/elvish|*/nushell|*/xonsh) exec /bin/sh -l -c '${innerEscaped}';; ` +
|
||||
`*) exec \${SHELL:-/bin/sh} -l -c '${innerEscaped}';; ` +
|
||||
`esac`;
|
||||
args.push("sh", "-c", wrapperCommand);
|
||||
execFile("C:\\Windows\\System32\\wsl.exe", args, { timeout: 5000 }, (err, stdout) => {
|
||||
if (err) { resolve(null); return; }
|
||||
|
|
|
|||
|
|
@ -76,15 +76,16 @@ export function wrapCommandForWsl(
|
|||
// (e.g., .zprofile for zsh, .bash_profile for bash).
|
||||
// Source ~/.profile first as a fallback because bash -l skips it when
|
||||
// ~/.bash_profile exists, and many tools (linuxbrew, nvm, mise) add to ~/.profile.
|
||||
// Non-POSIX shells (fish, elvish, nushell) fall back to bash since the
|
||||
// Non-POSIX shells (fish, elvish, nushell) fall back to /bin/sh since the
|
||||
// inner command uses POSIX syntax (export, &&).
|
||||
const innerCommand = `${pathPrefix}cd ${escapeShellArg(wslCwd)} && ${command}${argsString}`;
|
||||
const innerEscaped = innerCommand.replace(/'/g, "'\\''");
|
||||
const wrapperCommand =
|
||||
`. ~/.profile 2>/dev/null; ` +
|
||||
`s="\${SHELL:-/bin/bash}"; ` +
|
||||
`case "$s" in */fish|*/elvish|*/nushell|*/xonsh) s=/bin/bash ;; esac; ` +
|
||||
`exec "$s" -l -c '${innerEscaped}'`;
|
||||
`case \${SHELL:-/bin/sh} in ` +
|
||||
`*/fish|*/elvish|*/nushell|*/xonsh) exec /bin/sh -l -c '${innerEscaped}';; ` +
|
||||
`*) exec \${SHELL:-/bin/sh} -l -c '${innerEscaped}';; ` +
|
||||
`esac`;
|
||||
wslArgs.push("sh", "-c", wrapperCommand);
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in a new issue