by DanielKehoe · 2y ago · 0 comments
- Use `~/.zprofile` to set the PATH and EDITOR environment variables. - Use `~/.zshrc` for aliases and a custom prompt, or anything tweaking the appearance and behavior of the terminal.
It seems the advantage of the `~/.zprofile` file versus `~/.zshenv` is that it sets environment variables such as `$PATH` without override from macOS. It seems the `~/.zshrc` file could be used for `$PATH` but, by convention and design, is intended for customizing the look and feel of the interactive terminal.
Frankly, saying `~/.zprofile` is better than `~/.zshrc` for setting `$PATH` only "by convention and design" feels like a cop-out. Wondering if anyone knows better.
In your guide, under ~/.zshenv, you mention that "macOS overrides this for PATH settings for interactive shells", without mentioning why or how. What's happening is that macOS sets your path in /etc/zprofile.
It seems your guide is missing a few global configfiles :) This is the order for an interactive login shell [1]:
/etc/zshenv
${ZDOTDIR:-$HOME}/.zshenv
/etc/zprofile (login)
${ZDOTDIR:-$HOME}/.zprofile (login)
/etc/zshrc (interactive)
${ZDOTDIR:-$HOME}/.zshrc (interactive)
/etc/zlogin (login)
${ZDOTDIR:-$HOME}/.zlogin (login)
/etc/zlogout (login - loaded on logout)
${ZDOTDIR:-$HOME}/.zlogout (login - loaded on logout)
In fact, the configfiles you mention are only loaded the way you've mentioned them, if the option GLOBAL_RCS is unset. And if GLOBAL_RCS is unset, macOS does not override your PATH, because/etc/zprofile is not loaded :)