Zsh Startup Files
Sources:
- **
title: Contents
style: nestedList # TOC style (nestedList|inlineFirstLevel)
minLevel: 1 # Include headings from the specified level
maxLevel: 4 # Include headings up to the specified level
includeLinks: true # Make headings clickable
debugInConsole: false # Print debug info in Obsidian console
Overview
There are five primary startup files for Z Shell (Zsh):
.zshenv
: Zsh Environment Configuration.zprofile
: Zsh Profile Configuration.zshrc
: Zsh Interactive Shell Configuration.zlogin
: Zsh Login Configuration.zlogout
: Zsh Logout Configuration
.zshenv
- Zsh Environment Configuration
.zshenv
is sources on all invocations of the shell, unless the -f
option flag is set.
What to Include:
- Command Search Path
- Environment Variable Exports
- Commands for setting up aliases and functions that are needed for other scripts
What to Exclude:
- Commands the product output
- Anything that assumes the shell is attached to a TTY
.zprofile
- Zsh Profile Configuration
.zprofile
is sourced in all login shells. It is meant to serve as an alternative to zlogin
for ksh
.
What to Include:
- Commands that should be executed only in login shells
- As a general rule, it should not change the shell environment at all.
- As a general rule, set the terminal type then run a series of external commands e.g. fortune, msgs, etc.
What to Exclude:
- Alias Definitions
- Function Definitions
- Options
- Environment Variable Settings
.zshrc
- Zsh Interactive Shell Configuration
zshrc
is sourced in interactive shells.
What to Include:
- Commands to setup aliases, functions, options, key bindings, etc.
.zlogin
- Zsh Login Configuration
.zlogin
is similar to .zprofile
, except sourced after .zshrc
.
.zlogout
- Zsh Logout Configuration
.zlogout
is sourced when a login shell exits.
Extras
.zsh-update
.zshrc-e
File Paths
Default System Files:
/etc/zshenv
/etc/sprofile
/etc/zshrc
/etc/zlogin
/etc/zlogout
Default User Files:
$HOME/.zshenv
$HOME/.zprofile
$HOME/.zshrc
$HOME/.zlogin
$HOME/.zlogout
When using XDG:
$HOME/zsh/.zshenv
$XDG_CONFIG_HOME/zsh/.zprofile
$XDG_CONFIG_HOME/zsh/.zshrc
$XDG_CONFIG_HOME/zsh/.zlogin
$XDG_CONFIG_HOME/zsh/.zlogout
When using ZDOTDIR
:
${ZDOTDIR:-$HOME}/.zshenv
${ZDOTDIR:-$HOME}/.zprofile
${ZDOTDIR:-$HOME}/.zshrc
${ZDOTDIR:-$HOME}/.zlogin
${ZDOTDIR:-$HOME}/.zlogout
Zsh System Directory Paths:
/etc/zshenv.d/
/etc/zprofile.d/
/etc/zshrc.d/
/etc/zlogin.d/
/etc/zlogout.d/
Zsh User Directory Paths:
${XDG_CONFIG_HOME:-$HOME/.config}/zshenv.d/
${XDG_CONFIG_HOME:-$HOME/.config}/zprofile.d/
${XDG_CONFIG_HOME:-$HOME/.config}/zshrc.d/
${XDG_CONFIG_HOME:-$HOME/.config}/zlogin.d/
${XDG_CONFIG_HOME:-$HOME/.config}/zlogout.d/