View on GitHub

Shenv

A set of scripts to create custom shell environments for different projects/activities

download .ZIPdownload .TGZ

Shell Environments v1.1

Why do you need this?

Let's say you are working on something and you've cd'ed to directories deep in your filesystem, you have set up your own aliases, your own functions and other shell variables which help you in executing what you are working on better. Don't you get irritated if you want to open a terminal and want to cd every time, create these functions/variables/aliases, etc? SHENV helps you in creating mini environments for each of such project directories!

Shell Support

  1. Bash

Advantages/Features

  1. You can create closed environments for different projects/activities that you do.
  2. While in an environment, if you just cd in your terminal, you won't end up in the home directory but rather in the environment's root directory which you specify.
  3. Create variables, alises and functions for an environment and don't even worry about unsetting/unaliasing them!

Instructions and Usage

For bash users

  1. Copy the envrc file bash/.bashenvrc to a location you desire and source it in your .bashrc
  2. You then need to mark a folder for storing all environment scripts that SHENV creates for you. This is a folder of your choice. Just set the variable SHENV_HOME at line 3 in the envrc file.
  3. To create a new environment, use envcreate <name> <directory> where name is the name of the environment and directory is the absolute path to the environment's root.
  4. To start an environment, use envstart <name> where name is the name of the environment
  5. Similarly, to end the environment, use envend <name>.
  6. You can add all your custom aliases, functions, environment variables in the envinit function in <name>-shenv.sh that is created at your SHENV_HOME directory.

An example (for bash)

There are three associative arrays that SHENV uses. variables, aliases and functions.
You populate these in the envinit function (as specified above). Like so -

variables[FILE]='$ENV_ROOT/file.txt'
aliases[run]='rake generate && rake preview'
functions[mkcd]='mkdir -p $1 && cd $1' # NOTE the single quotes !!

Once you start the environment with envstart, you can use these like any other shell variable, alias or a function. Like so -

cat $FILE
run # rake generate && rake preview
mkcd foo # create directory 'foo' and cd to it

Note that SHENV is not yet able to update your PATH or CLASSPATH in an environment and later restore them.

Coming Next

  1. Update variables in an environment and restore them later. (like PATH, CLASSPATH, etc)
  2. Support for Z-Shell.