Many users asked us how to change Spaceship options only for a specific directory. There are plenty solutions for this. We will show how to do that with a tool called
direnv is a tool that allows you to manage environment variables for a directory. It is a simple wrapper around
.envrc files. It can load and unload variables defined in
.envrc based on current directory. It also works not only with Zsh, but with other popular shells.
direnv with the package manager of your choice. Or use a script to install a binary build of
After successful installation of
direnv you need to hook it to your shell.
direnv into Zsh¶
Add the following line somewhere at the end of your
eval "$(direnv hook zsh)"
Setting per-directory environment variables¶
As soon as you've installed
direnv and hooked it to the Zsh, you can set environment variables for any directory in a
.envrc file within that directory.
After that you need explicitly grant permissions to source
.envrc files in the directory.
direnv allow /path/to/directory
Here is a live example of how
direnv there are many other tools that allow you to manage environment variables for a directory. Here's a list of the most popular of them: