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

9,544

Solution 1

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.

Solution 2

In my case, i'm using oh-my-zsh and in the ~/.zshrc file i placed the linked file path as

source FILE_PATH

then restart the terminal and all done.

Share:
9,544

Related videos on Youtube

Matt Komarnicki
Author by

Matt Komarnicki

Updated on September 18, 2022

Comments

  • Matt Komarnicki
    Matt Komarnicki over 1 year

    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?

    • Admin
      Admin over 7 years
      Where you are inserting your aliases in ~/.zshrc, replace them with . ~/.zsh_aliases, where you put the aliases instead.