Macos – How to specify a separate file for the aliases in oh-the-zsh

bashmacosoh-my-zshshellzsh

I'm preparing a bash script, that will set a bunch of handy shell aliases at once. I'm using a pair of iTerm2 and oh-my-zsh.

I know that I can manually add aliases into ~/.zshrc.
I also know that I can even to that automatically by calling sed with some extra stuff, but for separation and consistency I would like to keep my "omz" aliases in a separate file like ~/.bash_aliases?

So then my bash script could easily override the content of that file and put a list of my aliases without worrying, that I will remove by accident some other settings from ~/.zshrc.

How I could specify a separate file for aliases in oh-my-zsh?

Best Answer

All you need to do is to remove the alias definitions from ~/.zshrc into the file ~/.zsh_aliases and replace the multiple alias commands in ~/.zshrc by:

. ~/.zsh_aliases

You can use the same technique for other sections of ~/.zshrc: for instance, you may find it convenient to move any function definitions into ~/.zsh_functions.

Related Question