Skip to content

fix(shell): quote shellrc source guard so ZDOTDIR with spaces works - #2860

Merged
mikeland73 merged 1 commit into
mainfrom
mikeland73/devbox-zdotdir-space-fix
Jun 21, 2026
Merged

fix(shell): quote shellrc source guard so ZDOTDIR with spaces works#2860
mikeland73 merged 1 commit into
mainfrom
mikeland73/devbox-zdotdir-space-fix

Conversation

@mikeland73

Copy link
Copy Markdown
Collaborator

Summary

The [ -f <path> ] guard that devbox generates around sourcing the user's original shellrc was unquoted in both the zsh and bash branches of shellrc.tmpl. When ZDOTDIR (and therefore the baked-in path) contains a space — e.g. a terminal integration that sets .../Application Support/... — the path split into multiple words, [ failed with too many arguments, the whole if block was skipped, and the user's real shellrc (prompt, aliases, oh-my-zsh, etc.) never got sourced. This quotes the path in both branches and updates the affected golden files.

How was it tested?

devbox run -- go test ./internal/devbox/ passes, including a new regression test TestWriteDevboxShellrcZDOTDIRWithSpaces that builds a shellrc from a ZDOTDIR containing Application Support, asserts the guard is quoted, and runs the generated guard line through /bin/sh to confirm it no longer errors with "too many arguments".

Community Contribution License

All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.

By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.

🤖 Generated with Claude Code

The `[ -f <path> ]` guard around sourcing the user's shellrc was unquoted.
When ZDOTDIR (and thus the path) contains a space — e.g. a terminal
integration setting ".../Application Support/..." — the path split into
multiple words, `[` failed with "too many arguments", and the user's real
shellrc never got sourced. Quote the path in both the zsh and bash branches.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mikeland73
mikeland73 requested review from gcurtis and savilJune 9, 2026 21:44
@mikeland73
mikeland73 marked this pull request as ready for review June 9, 2026 22:21
CopilotAI review requested due to automatic review settings June 9, 2026 22:21

CopilotAI left a comment

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.

Pull request overview

This PR fixes devbox-generated shellrc guards so that sourcing a user’s original shell rc file works even when the rc path contains spaces (notably when ZDOTDIR points into paths like .../Application Support/...). It updates the shellrc template accordingly, refreshes golden test fixtures, and adds a regression test to prevent reintroducing the issue.

Changes:

  • Quote .OriginalInitPath in the [ -f ... ] guard in internal/devbox/shellrc.tmpl for both the zsh and non-zsh branches.
  • Update shellrc golden files to match the newly quoted guard output.
  • Add a regression test to ensure a space-containing ZDOTDIR produces a quoted guard and that the guard line no longer fails with too many arguments.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

FileDescription
internal/devbox/shellrc.tmplQuotes the -f guard path to prevent word-splitting when rc paths contain spaces.
internal/devbox/shell_test.goAdds regression coverage for ZDOTDIR paths containing spaces and validates guard execution via /bin/sh.
internal/devbox/testdata/shellrc/basic/shellrc.goldenUpdates expected generated shellrc output with the quoted guard.
internal/devbox/testdata/shellrc/zsh_zdotdir/shellrc.goldenUpdates expected generated zsh shellrc output with the quoted guard.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mikeland73
mikeland73 merged commit 063fe53 into mainJun 21, 2026
26 checks passed
@mikeland73
mikeland73 deleted the mikeland73/devbox-zdotdir-space-fix branch June 21, 2026 17:43
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@mikeland73