Knowing your zsh configuration
2025-08-05
If you are like me, changed to zsh
and listen to most people around you without reading the docs. Hear me out.
Just using a .zshrc
will be enough in most cases. But will introduce pain points on the long run.
TL;DR
.zprofile
behaves the same to .profile/.bash_profile
. Use it if their are env
variables that need to be set/exported for every logged in shell. Not just spawned terminal windows.
For example:
export GDK_DPI_SCALE=2 # scale them GDK apps on high dpi monitors
export ELECTRON_OZONE_PLATFORM_HINT=auto # tell electron apps to remember their zoom level. Obsidian etc.
export EDITOR=nvim # set your default editor
Instead of tediously managing .desktop
files for every application to ,for example, scale them properly.
How zsh configuration files get sourced
Source order:
.zshenv
is loaded for all types of shell sessions.zprofile
if the shell is a login shell. Same behavior as.profile
.zshrc
if the shell is interactive.zlogin
on login shells
You will notice that both .zprofile
and .zlogin
are run on login shells. The only real difference is the source order.
Lets look at how these configuration files are meant to be used.
- .zshenv - Loaded all the time. Even in non-interactive and non-login sessions. (definitions in here could be used for cronjobs). Most of the time not used for personal computers.
- .zprofile - Loaded in login shells that are interactive and non-interactive (starting an application with an app launcher, automations, etc.). In here it is recommendet to set variables like
PATH
andEDITOR
. - .zshrc - Loaded in all interactive login shells (your cli). To configure appearance and specific behavior like loading alaiases and other setup.
- .zlogin - Same as .zprofile but loaded last. For setting terminal types, running external programms or other specific settings that depend on this order of sourcing. Should not be used to modify the shell environment. Use
.zprofile
and.zshrc
should be used for this
Here is the Official Documentation for the files handling.
My .zprofile
export EDITOR=nvim
export MANPAGER='nvim +Man!'
# QT high dpi behavior
export QT_AUTO_SCREEN_SCALE_FACTOR=0
export QT_SCALE_FACTOR=2
# GDK high dpi behavior
export GDK_DPI_SCALE=2
export GDK_SCALE=2
export ELECTRON_OZONE_PLATFORM_HINT=auto