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
Advantages/Features
- You can create closed environments for different projects/activities that you do.
- While in an environment, if you just
cdin your terminal, you won't end up in the home directory but rather in the environment's root directory which you specify. - Create variables, alises and functions for an environment and don't even worry about unsetting/unaliasing them!
Instructions and Usage
For bash users
- Copy the envrc file
bash/.bashenvrcto a location you desire and source it in your.bashrc - 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_HOMEat line 3 in the envrc file. - 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. - To start an environment, use
envstart <name>where name is the name of the environment - Similarly, to end the environment, use
envend <name>. - You can add all your custom aliases, functions, environment variables in the
envinitfunction in<name>-shenv.shthat is created at yourSHENV_HOMEdirectory.
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
- Update variables in an environment and restore them later. (like
PATH,CLASSPATH, etc) - Support for Z-Shell.