45

I am trying to get ZSH config working correctly on Mac OSX. I installed it using curl: curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh. Then I modified my zshrc file to fit my needs. It works only after I run source ~/.zshrc. But then if I come back and open a new tab or new terminal I have to do source ~/.zshrc to get the config settings to work again. Has anybody ran into this issue? I believe there is a way to make it so I don't have to do source ~/.zshrc with every new tab.

Anthon
  • 69,918
  • 32
  • 186
  • 246
Jacob Waller
  • 4,119
  • 3
  • 26
  • 32
  • Have you tried logging out and back in? – Anthon Mar 28 '13 at 13:00
  • Yes I have restarted the machine. I just got a new Mac and have this issue now. I also run Linux Mint and have the same issue. All of it works after running source ~/.zshrc so if I can get that config to load on login it would fix it. – Jacob Waller Mar 28 '13 at 13:44
  • Restarting should not be necessary, but often login and just opening a new terminal can be different. I am running out of ideas, but the one thing you could try is see if the env. variable ZDOTDIR is set (e.g. in `/etc/zshenv`), if that is set it determines from where .zshrc is read, and only if **not** set it takes ~/.zshrc . Also see [zsh manpage](http://linux.die.net/man/1/zsh) (It has been a while since I used `zsh`) – Anthon Mar 28 '13 at 15:01
  • `zsh` on Mac OS X should work without requiring you to `source ~/.zshrc` so I'll ask a possibly stupid question: have you set your shell to `zsh` (default is `bash`)? – simont Mar 29 '13 at 10:50
  • Yes my default shell is zsh it loads the zsh prompt when I open the terminal or a new tab. – Jacob Waller Apr 03 '13 at 15:54

6 Answers6

39

I figured this out. It was due to my config file. The part of the zsh config that wasn't loading needed to be moved down after the plugins load. After moving that it all worked as expected.

Jacob Waller
  • 4,119
  • 3
  • 26
  • 32
  • 6
    could you give some more details? I'm having the same probvlem – Andrew Hundt Nov 25 '13 at 17:56
  • 1
    What is your specific issue? I had to move some of my custom codings below the plugins= line source $ZSH/oh-my-zsh.sh bindkey '^R' history-incremental-search-backward autoload -U edit-command-line zle -N edit-command-line bindkey -M vicmd v edit-command-line That fixed it for me – Jacob Waller Nov 26 '13 at 16:02
  • 17
    Cool. I've finally found the problem, somehow plugins and loading oh-my-zsh became swapped. The correct order for reference: `plugins=(osx git )` then `source $ZSH/oh-my-zsh.sh`. – Andrew Hundt Nov 26 '13 at 22:25
  • 1
    Thanks, this was driving me nuts! – aglassman Jan 21 '16 at 16:21
  • 2
    More generally, _any_ oh-my-zsh config needs to be loaded before sourcing `$ZSH/oh-my-zsh.sh` – Benjamin R Dec 25 '17 at 21:10
  • @AndrewHundt your comment was the exact solution in my case. It just feels unnatural for the plugins to be called first and then OMZSH to be sourced! – Yashank May 21 '21 at 16:33
30

If you have themes like Powerlevel9k installed for your zsh shell then source the oh-my-zsh config file after the theme variable assignments in your .zshrc file like shown below.

Eg:

........
........
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=('status' 'load' 'ram_joined' 'time')

# source oh-my-zsh config
source $ZSH/oh-my-zsh.sh
skepticNeophyte
  • 399
  • 4
  • 8
8

Not the ideal solution but solves the issue:

Terminal -> Preferences -> Profiles -> Shells -> Startup

Check the box that says "Run command" and in the input box run

source ~/.zsh/.zshrc

This will be executed when you open a new terminal window / tab.

DivyaJyoti Rajdev
  • 734
  • 1
  • 9
  • 15
  • changing the Shells Open with option is a better Idea. - Open Preferences for Terminal - Select the General Tab - Change Sells open with from Default login shell to Command (complete path) with the /bin/zsh in the input box. – Faisal Ali Oct 15 '21 at 10:47
7

My final solution was to go to Terminal --> Preferences --> General --> Shells open with --> Command (complete path), and set it to /bin/zsh (or your path to zsh), and then set both New windows/tabs open with to "Same profile". It works fine for me.

My initial attempt was to go to Terminal --> Preferences --> Profiles, and in my default profile's "shell" tab's Startup section, I set it to run command "source ~/.zshrc". This also solved the problem of /.zshrc not loading, but it seemed tedious to see that command show on every terminal tab/window.

timokratia
  • 85
  • 1
  • 8
1

I had a similar problem. I found that I had long ago changed my Terminal preferences to run tcsh instead of the default login shell. Took me forever to figure this out!

Clint
  • 11
  • 1
0

On mac zsh it is loading ~/.zsh_profile on shell start. So just create one like this will do.

echo "source ~/.zshrc" > .zsh_profile

Or just put your .zshrc content into .zsh_profile. Whatever works for you.

Schwarz Software
  • 1,114
  • 8
  • 22
Julie
  • 1
  • 1
    I would just create a symlink to the file so when you edit one file the other is updated too (it points to the first one).. no double-edit is required in that case :-) ```ln -s ~/.zshrc ~/.zsh_profile``` – CeDeROM Jun 18 '23 at 17:53