GithubHelp home page GithubHelp logo

mre / envy Goto Github PK

View Code? Open in Web Editor NEW
70.0 3.0 5.0 319 KB

๐Ÿ’ซ Manage environment variables without cluttering your .zshrc.

License: Apache License 2.0

Rust 99.23% Makefile 0.77%
dotenv direnv environment variables cli

envy's Introduction

envy

Sets environment variables when you enter a directory. Works with bash, zsh, and fish.

Documentation Rust

Example

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.

Installation

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.

Usage

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. โœŒ๏ธ

direnv compatibility

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.

Command-line options

envy 0.4.0
context-based environment variables

USAGE:
    envy <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    allow     Grants envy to load the given `.env` file
    deny      Revokes the authorization of a given `.env` file
    edit      Edit the envy config file
    export    Export environment variables based on the current directory
    find      Find a single environment variable and print its value
    help      Prints this message or the help of the given subcommand(s)
    hook      Print the hook to activate envy for your shell
    load      Load environment variables from a given `.env` file (for the current session only)
    path      Print path to envy config file
    show      Show envy config for current directory

Note: To load the environment variables into the current shell, you need to run eval "$(envy load)".

Limitations

  • Only tested on macOS. It should also work on Linux and Windows, though.
  • Does not unset variables when you leave a directory.
  • Developing this for myself. Thus, this project won't be worked on very actively.

envy's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar mre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

envy's Issues

Multiline variables

I have a use case where I want to set an env variable like this:

FLINK_PROPERTIES="jobmanager.rpc.address: host
taskmanager.numberOfTaskSlots: 3
blob.server.port: 6124
"

I could not do that properly, do you have a solution to this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.