Zsh keeps forgetting PATH vars

itermoh-my-zshzsh

I'm using [oh-my-zsh] in iTerm on MacBook running Mavericks.

I have iTerm set to source my .zsh file on load, and mostly that works.

cd && source .zsh

Except when it doesn't. Sometimes, even in the middle of a session, it will forget my environment vars and aliases. If that happens, even basic stuff like mvn gets "forgotten."

I'm not sure if this is an issue with iTerm, zsh, or oh-my-zsh. Any thoughts?

Best Answer

According to the zsh user guide, aliases should be defined in ~/.zshrc:

You may be able to think of some aliases you want to define in your startup files; .zshrc is probably the right place.

It also has a tip for keeping your ~/.zshrc clean:

I only tend to use aliases in interactive shells, so I define them from .zshrc, but you may want to use .zshenv if you use aliases more widely. In fact, to keep my .zshrc neat I save all the aliases in a separate file called .aliasrc and in .zshrc I have:

if [[ -r ~/.aliasrc ]]; then
   . ~/.aliasrc   
fi

which checks if there is a readable file ~/.aliasrc, and if there is, it runs it in exactly the same way the normal startup files are run.

So, you might want to create a file called ~/.aliasrc and source it (. means source) from your ~/.zshrc.

The same source suggests that environmental variables should be in ~/.zshenv:

The easiest place to put these is in .zshenv --- hence it's name. Environment variables will be passed to any programmes run from a shell, so it may be enough to define them in .zlogin or .zprofile: however, any shell started for you non-interactively won't run those, and there are other possible problems if you use a windowing system which is started by a shell other than zsh or which doesn't run a shell start-up file at all --- I had to tweak mine to make it do so. So .zshenv is the safest place; it doesn't take long to define environment variables. Other people will no doubt give you completely contradictory views, but that's people for you.

Related Question