Skip to content

fix(zsh): set PATH in .zshenv so early .zshrc consumers resolve - #8

Merged
ptaranat merged 1 commit into
mainfrom
fix/zsh-path-ordering
Sep 22, 2026
Merged

ptaranat merged 1 commit into
mainfrom
fix/zsh-path-ordering

Conversation

@ptaranat

Copy link
Copy Markdown
Owner

Homebrew, $HOME/bin and sbin were added in rc.d/01-environment.zsh,
sourced at .zshrc:124. But .zshrc runs znap eval atuin at line 96 and
sources rc.d/00-banner.zsh (which sorts before 01-) earlier still, so both
ran before PATH was ready and printed 'command not found'. Move those PATH
entries to .zshenv, keeping the same order so final priority is unchanged.

For the same reason the banner no longer shells out to gshuf (a coreutils
binary that may not be on PATH yet); it uses zsh's built-in $RANDOM instead.

Also folds in the opencode PATH line the installer had appended to the
deployed ~/.config/zsh/.zshrc, so chezmoi apply no longer reverts it.

@ptaranat
ptaranat marked this pull request as ready for review July 20, 2026 22:25
@ptaranat
ptaranat requested a review from Copilot July 20, 2026 22:25

ptaranat commented Jul 20, 2026 •

Copy link
Copy Markdown
Owner Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Moves essential PATH setup earlier in Zsh startup so commands used during early .zshrc execution (and non-interactive shells) can resolve correctly, and removes an early dependency on Homebrew coreutils.

Changes:

  • Move Homebrew + user bin PATH entries from rc.d/01-environment.zsh into .zshenv so they are available before .zshrc plugin initialization and in non-interactive shells.
  • Replace banner randomness that depended on gshuf with zsh’s built-in $RANDOM.
  • Add an “opencode” PATH entry to the managed dot_zshrc to avoid it being reverted by chezmoi apply.

Reviewed changes

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

File Description
dot_zshenv Prepends Homebrew and user bin directories early for all zsh invocations.
dot_config/zsh/rc.d/01-environment.zsh Removes PATH manipulation now handled by .zshenv.
dot_config/zsh/rc.d/00-banner.zsh Avoids early dependency on coreutils by using $RANDOM.
dot_config/zsh/dot_zshrc Adds an opencode PATH entry (currently hardcoded).

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

Comment thread dot_zshenv Outdated
Comment on lines +22 to +26
# Homebrew and $HOME/bin. Also set here rather than in rc.d/01-environment.zsh:
# .zshrc's `znap eval atuin '...'` runs before rc.d is sourced, so atuin (and
# anything else Homebrew-installed used earlier in .zshrc) was not yet on PATH
# at that point. Order below matches the old rc.d/01-environment.zsh so the
# final PATH priority is unchanged.
Comment thread dot_config/zsh/dot_zshrc Outdated
main already moved ~/.local/bin and Homebrew into .zshenv, for the reason
given there: rc.d is sourced at the end of .zshrc, so entries added there are
invisible to non-interactive shells and to the earlier parts of .zshrc. Three
entries never made the move.

/opt/homebrew/sbin was dropped entirely rather than relocated, so its contents
(addgnupghome, applygnupgdefaults) have been off PATH since. Added next to bin
on both OSes, bin first, matching the order `brew shellenv` emits.

$HOME/bin was left behind in rc.d and still had the original problem: ~/bin
holds hermit, which is exactly the sort of thing a script or editor subprocess
expects to resolve, and neither could see it. Moving it to .zshenv puts it
behind mise rather than in front. That changes nothing today, because mise
manages no tool of the same name.

The opencode PATH line was never in the source at all. Its installer appended
it to the deployed ~/.config/zsh/.zshrc, so it existed only as drift and the
next `chezmoi apply` would have reverted it and taken opencode off PATH.

The (N-/) note moved to .zshenv along with the entries it describes, and the
rc.d header now says where paths live and why, so the next addition does not
land back in the wrong file.

Verified by rendering the template and sourcing it in an `env -i` shell:
hermit, opencode and addgnupghome all resolve, and Homebrew's bin precedes
sbin.
@ptaranat

Copy link
Copy Markdown
Owner Author

Reworked onto the current main. The 65-file diff is gone: this branch was cut before main was rewritten, so GitHub was comparing across that rewrite.

Most of the original commit is already upstream and done better. main moved ~/.local/bin and Homebrew into .zshenv, made the Homebrew prepend OS-aware, and fixed the banner's gshuf call. What is left is the three entries that never made the move:

  • /opt/homebrew/sbin was dropped rather than relocated, so addgnupghome and applygnupgdefaults have been off PATH since. Added next to bin on both OSes, bin first, matching brew shellenv.
  • $HOME/bin was left in rc.d, which still has the original problem: it holds hermit, invisible to non-interactive shells. Moving it puts it behind mise instead of in front, which changes nothing today because mise manages no tool of that name.
  • the opencode line was never in the source at all. Its installer wrote it into the deployed ~/.config/zsh/.zshrc, so it exists only as drift and the next chezmoi apply would have reverted it and taken opencode off PATH.

The (N-/) note moved to .zshenv with the entries it describes, and the rc.d header now states where paths belong so the next one does not land in the wrong file again.

Verified by rendering the template and sourcing it in an env -i shell: hermit, opencode and addgnupghome all resolve, Homebrew's bin precedes sbin.

@ptaranat
ptaranat force-pushed the fix/zsh-path-ordering branch from 0a6a025 to fc7bdea Compare September 22, 2026 15:56
@ptaranat
ptaranat merged commit 72db846 into main Sep 22, 2026
@ptaranat
ptaranat deleted the fix/zsh-path-ordering branch September 22, 2026 16:31
@ptaranat
ptaranat restored the fix/zsh-path-ordering branch September 22, 2026 16:32
@ptaranat
ptaranat deleted the fix/zsh-path-ordering branch September 22, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants