fileability/chocolat-public — Issue #600: Assignment of environment variables.
Author: amcgregor
Created: 2011-11-03 05:17:24+00:00
State: open

> **Friendly tl;dr warning.**

Use Case
====

With scripts in language bundles (truffles), regardless of the underlying language for the script (JS, BASH, Ruby, Python, etc.) it is a requirement for my projects to have environment variables set to simulate a UNIX "chroot" at the language level. I primarily program Python, in which case my packages and their dependancies are isolated using a system called [virtualenv](http://pypi.python.org/pypi/virtualenv). Virtualenv is usable one of two ways:

* System-native Python interpreter but with `PYTHON_PATH` set.
* Virtual environment-specific Python interpreter via a defined `PATH`.

There are other useful environment variables to control SCM systems, for use in truffle-based templates and snippets (e.g. my name, organization name, etc.) and can be used to configure more advanced truffle scripts on a per-project basis without modifying the truffles themselves.

Behaviour
====

[This mockup](http://cl.ly/091S1P2Q2y362S0D2u1s/o) demonstrates a simple addition to the project sidebar as a new collapsable section called, appropriately, "ENVIRONMENT". Behaviour would be thus:

* Hidden completely if no environment variables are set in the project.
* A new section (separator + menu item) in the context menu labelled "New Environment Variable…"
* The name of the environment variable is treated as its "file name" for when file renaming is implemented. (Click, delay, click and/or right-click "Rename".)
* Environment variables are edited just like files using the standard editor and BASH variable highlighting. (Colouring `$` variables, e.g. in the example of `/some/path/bin:$PATH`) This includes multiple-selection based vertical splitting. [1]
* In the case of Actions → Build submenu items the BASH wrapper will need to be updated to export the variables defined in the project.
* In the case of JavaScript executed within Chocolat, these variables can be made available (after merging with the standard environment and expansion) as ENV or some-such.
* These are saved within the Chocolat project file as a dictionary of strings with the key `CHEnvironment` or some-such and sub-keys being the names of the variables.

Notes
----

1. Yes, some environment variables can contain multiple lines or whole files. It's weird, but it happens. (Run `set` in a terminal for many examples.)