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!
- You can create closed environments for different projects/activities that you do.
- 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. - Create variables, alises and functions for an environment and don't even worry about unsetting/unaliasing them!
For bash users
- Copy the envrc file
bash/.bashenvrc
to a location you desire and source it in your.bashrc
a - Create a directory with the name
.shenv
in your home directory. This folder is used for storing all environment scripts that SHENV creates for you. If you want to change it, just set the variableSHENV_HOME
at line 3 in the envrc file, to the directory you want to use as theSHENV_HOME
. - 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
envinit
function in<name>/shenv.sh
that is created at yourSHENV_HOME
directory.
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.
- Update variables in an environment and restore them later. (like
PATH
,CLASSPATH
, etc) - Support for Z-Shell.
The MIT License (MIT)
Copyright (c) 2014, Sathyam M Vellal
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.