| Crates.io | envy-cli |
| lib.rs | envy-cli |
| version | 0.6.0 |
| created_at | 2019-03-09 22:48:25.100561+00 |
| updated_at | 2025-08-22 13:29:45.527218+00 |
| description | A magical little tool that takes care of your environment settings. |
| homepage | https://github.com/mre/envy |
| repository | https://github.com/mre/envy |
| max_upload_size | |
| id | 119669 |
| size | 75,014 |
Sets environment variables when you enter a directory. Works with bash, zsh, and fish. Tested on macOS, Linux, and Windows.
At work, I have to set some environment variables every time I'm working on certain projects.
For example, these can be Google Cloud settings, the Consul host, or Docker configs.
It's tedious to set the correct environment variables myself every time.
direnv automatically loads .env files, but I don't want to clutter my system
with .env files. Also, I need the same environment variables in a few unrelated
projects, and I don't want to keep the .env files in sync.
Thus, the idea for envy was born.
It uses a config file that defines what environment variables to set for each folder.
cargo install envy-cli
Add the following line to the end of your ~/.zshrc file:
eval "$(envy hook zsh)"
For bash, use envy hook bash instead and add it to your ~/.bashrc file.
eval "$(envy hook bash)"
For fish, use envy hook fish instead and add it to your
~/.config/fish/config.fish file.
eval (envy hook fish)
Once you open a new shell, envy will start matching directories and set the
specified environment variables from the config file.
Run envy edit to open the config file. (On macOS, this file is located at
/Users/<user>/Library/Application Support/Envy/Config.toml.)
Define the list of regular expressions and the settings. The first regular expression that matches a path wins.
[[paths]]
pattern = ".*project1.*"
env = [
"CONSUL_HTTP_ADDR=http://consul:8500",
"GITHUB_TOKEN=123"
]
[[paths]]
pattern = ".*project2.*"
env = [
"DOCKER_HOST=tcp://127.0.0.1:2376",
"foo=bar"
]
The moment you save the file, the current terminal will automatically pick up the new settings; no need to reload or open a new terminal. :v:
envy supports loading environment files à la direnv as well. Run envy allow .env to auto-load the .env file in the current path on enter. You can add
multiple .env files (e.g. envy allow .envrc). Duplicate keys will be
overwritten in the order of appearance in the envy config file (run envy edit
to modify order). Use envy deny .env to remove an environment file from the
list.
envy can export environment variables in JSON format, making it a drop-in replacement for direnv export json. This is particularly useful for integration with tools like Nushell and Zed:
# Export environment variables as JSON
envy export json
# Use with Nushell (as direnv replacement)
envy export json | from json | load-env
# Use with jq for processing
envy export json | jq .
The JSON format matches direnv's output exactly: {"KEY": "value"} where each environment variable becomes a key-value pair in the JSON object.
Usage: envy <COMMAND>
Commands:
export Export environment variables based on the current directory
hook Print the hook to activate envy for your shell
edit Edit the envy config file
show Show envy config for current directory
find Find a single environment variable and print its value
path Print path to envy config file
load Load environment variables from a given `.env` file (for the current session only)
allow Grants envy to load the given `.env` file
deny Revokes the authorization of a given `.env` file
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
Note: To load the environment variables into the current shell, you need to run eval "$(envy load)".