How to reload ZSH configuration
I've been using Zsh with Oh-My-Zsh for a long time. All MacOS users have the Zsh (Z shell) installed and configured by default.
My Zsh configuration changes very rarely, but when it does, I need to restart my shell in order for my changes to take effect. Since I'm using tmux I can open a new window (which loads a new Zsh instance), but most of the time, I prefer to reload the current window.
To reload your Zsh (Z shell) .zshrc configuration, you can use the following command
$ exec zsh
How to reload Oh-My-Zsh configuration?
Oh-My-Zsh - The Zsh configuration manager has a built-in command to reload the current Zsh session:
$ omz reload
This command is actually an alias for exec zsh
- It does the same. It replaces your Zsh session with a new one, including your new .zshrc (if changed). It also reloads your plugins (if any).
Do not use source ~/.zshrc
OhMyZsh documentation suggests not to use source ~/.zshrc
for configuration reload. You should use exec zsh
as suggested above. The reason is that this approach can cause some trouble because some things that are already in the session, like functions, hooks, and variables, are not removed. You can read more about this in the OhMyZsh wiki FAQ.
What exactly does exec
do?
The exec
command is used to execute a program or command in the current shell session, replacing the current shell process with the new program. When you use exec
followed by a command, it doesn't create a new process; instead, it replaces the current shell process with the specified program. This can have various effects, depending on how you use it.