justinmayer / tackle

Collection of fish shell functions, modules, plugins, and themes
MIT License
150 stars 16 forks source link

Add a "Environment.fish" file to tackle/tacklebox for setting environment vars #19

Open simotek opened 8 years ago

simotek commented 8 years ago

Hi, as I regularly swap between machines I prefer to keep my entire fish config as part of tackle/tacklebox and reduce the contents of config.fish to just where to load tacklebox from and which plugins to load.

As such I am looking for a place to define environment vars such as EDITOR and a few others that I never change, my proposal is to add a environment.fish file to tackle that tacklebox can run early on to set these variables.

Does this seem like a good solution to the problem or have I missed something that's already there? and if I was to submit such a feature are you likely to accept it.

Cheers Simon

justinmayer commented 8 years ago

Thanks, Simon, for bringing up a topic that has long been on my mind. My target use case is a bit different than yours, but perhaps we can use the same machinery to address both needs.

Inspired by The Twelve-Factor App, many folks are putting configuration in environment variables, often in the form of .env files that are loaded by various triggers (entering a directory, app initialization, etc). It would be great if we had a function that parsed such a file and set the environment variables contained within (along with a corresponding function that can un-set variables as well).

These env files normally take the form of:

EDITOR=vim
LC_ALL=en_US.UTF-8

… but it would be nice if a fishier space-delimited syntax were also supported:

EDITOR vim
LC_ALL en_US.UTF-8

The function I am proposing, perhaps named something like load_env, would accept either of the above delimiter formats, take a file path as its argument, and set the environment variables according to the key/value directives inside. The main advantages to this method are:

  1. ability to share a single env file across fish/bash/zsh shells
  2. theoretically safer since we're not sourcing arbitrary .fish files

This function could, in turn, be used to address your use case by having Tacklebox look for an environment or env file at the tackle root and then loading it via said load_env function.

And if such a function were to exist, I could use it for Twelve-Factor App configuration, as well as re-write the Virtualhooks module to use the new load_env and unload_env functions.

What do you think? Any chance this proposed function is something you'd care to work on?

simotek commented 8 years ago

Thanks this is exactly the feedback I was looking for, The concept of a env file at the tackle root was exactly what I was looking at, I just didn't know that env files were a standard, this seems like a good way forward.

I'm happy to work on this hopefully over the next couple of weeks i'm still working out time etc with a new job but it doesn't seem like this will be large amounts of work.

justinmayer commented 8 years ago

Awesome! Looking forward to it. (^_^)