I want to use different zshrcs and choose one using a single file tat holds variables and loads them up. I've tried looking it up, but there are only for iTerm2. I would appreciate any support. Thank you.


I do a similar thing that Amint documents. This is for bash, but I do the same thing for fish, and it clearly applies to zsh

My .bashrc was getting unwieldy, so I broke it up into several libraries (functions for the prompt, aliases, functions to wrap other commands, etc) and I do separate things based on what computer I'm working at.

if [[ -d ~/.bash.d ]]; then
    shopt -s nullglob
    for file in ~/.bash.d/*.bash; do
        source "$file"
    if [[ -d ~/.bash.d/"$(hostname)" ]]; then
        for file in ~/.bash.d/"$(hostname)"/*.bash; do
            source "$file"
    shopt -u nullglob
    unset file

So if I create something new, I can just drop it into the appropriate directory and it will be active for the next bash session.


(Also achievable on Bash, and any shell with an .*rc file.)

To do this, you can make a directory setup like this:

 .zshrc (main rc to choose profile)
 .zshenv (sources each rc)
 .zsh/profiles/ (rcs)

First, add this to the start of your zshrc:

# Chooses zshrc1.

# Chooses zshrc2.

# Paste and edit to your likings.
source $HOME/.zshenv

Then, make the .zshenv file and add this:

if [[ "$RC1_ENABLE" == "true"  ]]; then
  echo "{zshenv} Setting RC1 up with ZSH."
  source "$HOME/.zsh/profiles/zshrc1.zsh"

if [[ "$RC2_ENABLE" == "true" ]]; then
  echo "{zshenv} Setting RC2 up with ZSH."
  source "$HOME/.zsh/profiles/zshrc2.zsh"

After, make the directory .zsh/profiles. This can be whatever you want, though.

Then, add your RCs with the names you added in the zshenv file.

After, go back to the main zshrc, and edit one of these lines to activate an RC:

# Chooses zshrc1.

# Chooses zshrc2.

Then, open up a new zsh session.

{zshenv} Setting RC2 up with ZSH.
user@hostname ~ $

You did it! Now you can switch between RCs. You may also be able to use two RCs at the same time. If you use themes (Oh My ZSH!, Prezto, or if you did it from bash (which is possible), Bash-it), be careful if you use different theming.

A reason you may want to do this is for personal, work and school prompts. You may also want to use themes, but also want to stick with the original old hostname%. You may also want to use different aliases. Separated functions, backup RC, you name it.

Enjoy using your multi prompt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.