Last Updated: January 07, 2018
· rahmat-budiharso

per directory zsh config

Put this lines in your .zshrc file

function chpwd() {
  if [ -r $PWD/.zsh_config ]; then
    source $PWD/.zsh_config
    source $HOME/.zshrc

With that now you can make .zsh_config file for each directory you want, and when you cd to that directory, zsh will read the .zsh_config file and use any configuration found in there. So for example if I have this .zsh_config in $HOME/rails_app:

alias rc='./script/rails c'

Now everytime I cd into $HOME/rails_app I will have rc command to open a rails console, and when I cd into other directory that doesn't have .zsh_config file zsh will use the original config file (or read .zsh_config file if it's found in the new directory).

3 Responses
Add your response

Does this introduce any noticeable slowdown when changing directories?

over 1 year ago ·

That depends on what kind of configuration you put on .zsh_config or .zshrc file, the function just simply read a new configuration whenever it find .zsh_config file. Based on my experience there's no noticeable slowdown when changing directory.

over 1 year ago ·

I just finished writing a script that can serve as an alternative for setting up local aliases and functions. It doesn't perform any dicey "source" commands so it should be a bit more secure. It's interface will also make the process much more convenient. If your looking for such a solution, check it out: LocalAlias

over 1 year ago ·