[Feature] Add configurable shell for execute_bash
Description
On Windows, execute_bash currently uses cmd.exe, even when Nanocoder is launched from MSYS2/Cygwin Bash. This causes Bash syntax such as ;, single quotes, command substitution, and escaping to behave incorrectly.
I understand there is custom tools in nanocoder, however, that is way too complicated for the use case of just wanting to use bash semantics but with a different shell location. execute_bash is already the right built-in tool for normal shell work, and I would rather keep using it than replace it with a custom tool. The issue is simply that users may run Nanocoder in environments where the preferred shell is Bash, Zsh, Ash, Csh, MSYS2 Bash, Cygwin Bash, or something else, so the built-in tool should not hardcode one shell without allowing an override. This feels less like adding a new feature and more like adding a configurable shell parameter/path for execute_bash, while preserving the current default behavior for everyone who does not set it.
Even on mac, I dont use the default zsh and install a custom bash in /usr/local/bin instead of /bin/bash, so hardcode these paths is not a best practice.
Current code in the bash executor js:
const isWindows = platform === 'win32';
const cwdCaptureFile = isWindows
? undefined
: join(jailTmp ?? tmpdir(), `nanocoder-cwd-${executionId}`);
Then:
if (sandbox) {
...
} else if (cwdCaptureFile === undefined) {
proc = spawn('cmd', ['/c', command], {cwd});
} else {
proc = spawn('sh', ['-c', spawnCommand], ...);
}
At least we can use the env var, if not parameter, like in custom tools handler:
function pickShell(configured: string | undefined): string {
if (configured === 'bash') return '/bin/bash';
if (configured === 'sh') return '/bin/sh';
if (process.platform === 'win32') return process.env.ComSpec || 'cmd.exe';
if (existsSync('/bin/bash')) return '/bin/bash';
return '/bin/sh';
}
Above still not the best way to I think adding a configurable shell option just like any tty is a good idea.
Thanks.
Use Case
On any OS when user wants to switch shell
Proposed Solution
Have a param in nanocoder-preferences.json to define the path of shell as custom, still can have bash or zsh or cmd.exe as default for a platform.
Alternatives Considered
I am currently just telling nano to not use cmd.exe but use bash.exe on Windows
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] This feature aligns with the project's goals (local-first AI assistance)
Implementation Notes (optional)
Allow custom shell path + argument in the preference file.
Something like:
{
"nanocoder": {
"bash": {
"command": "C:/msys64/usr/bin/bash.exe",
"args": ["-lc"]
}
}
}
Seems like pretty straight forward so may take a look.
Hi @akramcodez @will-lamerton can I get assigned for this? Or if you think this is a good idea to proceed? It is currently making my usage on Windows specifically miserable, so will send a PR soon.
Thanks.
sure @coralsundy 👍
I opened #2351 for the same thing before finding this issue, and closed it as a duplicate. Two points from it that may be useful here:
- PowerShell as a target, not only bash.
powershell.exeships with every supported Windows version, sopowershell/pwshwould work for users who have no Git Bash or MSYS2 installed.source/utils/shell-args.tsalready switches arguments onisWindowsCmd, so it would be one more branch (-NoProfile -NonInteractive -Command). - The prompt should name the shell the tool really uses. #2341 is the same root cause: the "Default Shell" line comes from
SHELLwhile the tool runs%ComSpec%.
@coralsundy are you still working on this? If it would help, I'm on Windows 11 and can test a branch against cmd, Windows PowerShell 5.1 and PowerShell 7, or take the PowerShell part.
@Esquetta please do, I am currently switching to other matters.
Thanks.
Thanks @coralsundy.
@akramcodez @will-lamerton could you assign this to me? My plan, to keep it small:
- A
shellsetting forexecute_bash(path or name). Without it nothing changes:%ComSpec%on Windows, the current shell elsewhere. - Arguments chosen by shell kind in
source/utils/shell-args.ts:cmd,powershell/pwsh, and POSIX shells such as Git Bash or MSYS2 bash. - The "Default Shell" line in the prompt names the shell the tool really runs (#2341).
I will test it on Windows 11 with cmd, Windows PowerShell 5.1, PowerShell 7 and Git Bash. If you would rather have the setting somewhere else, or a different name, tell me before I start.