Skip to content

Fix for 'forge zsh setup' command when running in MSYS2 zsh#2778

Closed
Alexx999 wants to merge 2 commits intoantinomyhq:mainfrom
Alexx999:pr-fix-windows-zsh
Closed

Fix for 'forge zsh setup' command when running in MSYS2 zsh#2778
Alexx999 wants to merge 2 commits intoantinomyhq:mainfrom
Alexx999:pr-fix-windows-zsh

Conversation

@Alexx999
Copy link
Copy Markdown

@Alexx999 Alexx999 commented Apr 1, 2026

Before:
forge.exe had CRLF line endings in embedded .zsh scripts, and also running scripts via 'zsh -c' was failing for some weird reasons.

Zsh does not support CRLF line endings failing with errors like parse error near `in^M'
'Git for Windows' defaults to autocrlf=true which is one possible cause for CRLFs in there, so suppress it via .gitattributes
Also, explicitly normalize line endings when embedding the strings so that any setup would work the same way.

After fixing that, the error shifted to zsh:251: parse error near `f' - something about long/complex zsh -c commands is broken in MSYS2 env, running from a file works perfectly though: setup completed and : hi works with these changes

…xe in MSYS2 zsh environment

forge.exe had CRLF line endings in .zsh files, and also running scripts via 'zsh -c' was failing for some weird reasons.
@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Apr 1, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 1, 2026

CLA assistant check
All committers have signed the CLA.

let mut child = std::process::Command::new("zsh")
.arg("-c")
.arg(script_content)
.arg(script_path.to_str().unwrap())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential panic on non-UTF8 paths: Calling unwrap() on to_str() will panic if the temp path contains non-UTF8 characters. While rare with system temp directories, this could crash the application in certain environments.

Fix by handling the error:

.arg(script_path.to_str()
    .ok_or_else(|| anyhow::anyhow!("Temp path contains invalid UTF-8"))?)

Or use as_os_str() if zsh command accepts OsStr (though Command::arg() already accepts AsRef):

.arg(&script_path)
Suggested change
.arg(script_path.to_str().unwrap())
.arg(&script_path)

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@tusharmath
Copy link
Copy Markdown
Collaborator

Thanks @Alexx999!
Closing in favour of https://github.com/antinomyhq/forgecode/pull/2433/changes

@tusharmath tusharmath closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants