🐚 Shell RC
Guide on maintaining good startup scripts. Also known as rc files, such as .bashrc
, .zshrc
, etc.
Zsh
info
TL;DR:
- You don't need
/etc/zshenv
,~/.zprofile
,~/.zlogin
, and~/.zlogout
. - You only need:
~/.zshenv
: For environment variables.~/.zshrc
: For aliases, functions, and auto-completion.
- Call
compinit
ASAP in~/.zshrc
- If you use zsh frameworks (e.g. Oh My Zsh), they might have done this for you.
- That means you should source them ASAP
- If you use zsh frameworks (e.g. Oh My Zsh), they might have done this for you.
compinit
is not the same asbashcompinit
- Zsh is highly compatible with Bash completion scripts.
- If you only have Bash completion scripts, you can use
bashcompinit
instead. - Call
bashcompinit
it right aftercompinit
. - They are independent of each other and can be used together.
Depending on how shell is invoked, Zsh reads different files. Here is the order:
/etc/zshenv
~/.zshenv
/etc/paths
(only for macOS)~/.zprofile
(only for login shells)/etc/zshrc
(only for macOS)~/.zshrc
(only for interactive shells)~/.zlogin
(only for login shells)- Your shell session
~/.zlogout
(only for login shells)
note
Different systems (even installations) may behave differently. Use zsh -x
to findout what happens on shell startup.
Third party configuration guide
When a CLI tool is installed, they may require some configuration on RC files. For the following reasons:
Type | Where to put |
---|---|
Environment Variables (beside Paths) | ~/.zshenv |
Paths | ~/.zshrc |
Aliases | ~/.zshrc |
Functions | ~/.zshrc |
Auto-completion | ~/.zshrc (After calling compinit ) |