Skip to content

Instantly share code, notes, and snippets.

@alephalpha0
Last active May 22, 2021 16:27
Show Gist options
  • Save alephalpha0/225c555d1e29acc15b8623561ccd86f8 to your computer and use it in GitHub Desktop.
Save alephalpha0/225c555d1e29acc15b8623561ccd86f8 to your computer and use it in GitHub Desktop.
ZSH RC / settings load order

ZSH shell startup/shutdown files.

This is really just for my own reference, as ZSH loads its config in its own order and I can never seem to remember it. The global files (which shouldn't really be tampered with by users) will be mentioned and put into larger font than the user files. However, I won't be expounding upon them, as that is outside the purpose of this writing.

/etc/zshenv above all else. The alpha, the omega, the genesis.

.zshenv (req to be in $HOME)

Here there be environmental variables.

Place here anything I'm going to export so that it can be referenced later.

Good candidates include XDG_* and changes to program defaults.

Set up your $PATH & $PAGER & etc etc etc.

Quality of life: export ZDOTDIR="$XDG_CONFIG_HOME/zsh"

/etc/zprofile ONLY if the shell is a login shell.

.zprofile ($ZDOTDIR/.zprofile) ONLY if shell is login.

Any commands you want happening on every login.

Start daemons, set a new MOTD, start a SSH tunnel.

The possibilities are endless.

/etc/zshrc ONLY if the shell is interactive.

.zshrc ($ZDOTDIR/.zshrc) ONLY if the shell is interactive.

Used for shell options and various commands.

There should be a loooong list of setopt and unsetopt going on here.

Shell modules and the ZSH prompt go here, as well as history config.

Source your scripts and set your aliases.

/etc/zlogin ONLY if shell is login.

.zlogin ($ZDOTDIR/.zlogin) ONLY if shell is login.

Almost same purpose as .zprofile but you know, not really different. Use only one or the other if you're flying by the book.

.zlogout ($ZDOTDIR/.zlogout) ONLY if shell is login.

Can be used to execute commands when a shell exits.

Good time to clean up caches or tmp files/folders.

Logout of sessions, set the environment back to how you like it when you login.

Send an email to yourself of temp logs and an email to your mom telling her you love her.

References, sources & points of interest.

  1. http://zsh.sourceforge.net/Doc/Release/Files.html#Files

  2. https://unix.stackexchange.com/questions/71253/what-should-shouldnt-go-in-zshenv-zshrc-zlogin-zprofile-zlogout#71258

  3. https://thevaluable.dev/zsh-install-configure/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment