DEV Community


TIL about zshell startup

I still answer "developer". Italian living in Germany. proud MC of Euruko [2016], Ruby on Ice [2017, 2018], BalkanRuby [2017], Italian Ruby Day [2016, 2018].
・1 min read

This is a walk-with-me-while-I-do-things series, I'm going to tell you what I learned while I'm learning

You might remember about my ordeal with bash and Catalina and zshell and iTerm. I bit the bullet and switched to zshell.

I have an alias for starting the postgres server that on bash resides on .bashrc (by the way, did you know that rc stands for run commands?). With zshell, you can use .zshrc for the same purpose.

zshell at startup reads these files for the user in the following order:

  1. .zshenv - always read when launching the shell, no matter from where. you want the important stuff here.
  2. .zshprofile - read at login. don't use, use .zshlogin instead. the purpose is the same.
  3. .zshrc - read when interactive. this is where you should put aliases, key bindings, coloring, etc.
  4. .zshlogin - read at login, use it for things needed once the shell is set up, to execute external commands.
  5. .zshlogout - read when the login shell exits, it should be used to release resources acquired during login.

Before each of these, zshell runs the matching files that can be found in /etc/ for all users on the machine.

More info here (official documentation), here on StackOverflow, and here (switching to zshell because of Catalina).

Discussion (4)

moopet profile image
Ben Sinclair

I have this in my .bashrc, .bash_profile and .zshrc:

[ -f ~/.aliases ] && . ~/.aliases

That way I keep my aliases in a common file. Sure, some are shell specific but more likely they're OS specific, so inceptionally inside the .aliases file, I have stuff like this:

case $OSTYPE in
    alias ls='ls --color --group-directories-first -FhN'
    alias ls='ls -FhG'
nirnaeth profile image
Monica Author

oh this is so simple and yet so great!

I'll steal your idea :D

yujiri8 profile image
Ryan Westlund

by the way, did you know that rc stands for run commands?

Huh! I always assumed it was "remote configuration"!

nirnaeth profile image
Monica Author

at first I was also thinking that, but then the “remote” part was really not fitting... why remote if this is running on my machine? 🤔

I looked for it and ta-da! TIL inception!