Skip to content

Instantly share code, notes, and snippets.

@usergenic
Last active August 29, 2015 13:57
Show Gist options
  • Save usergenic/9535417 to your computer and use it in GitHub Desktop.
Save usergenic/9535417 to your computer and use it in GitHub Desktop.
#!/bin/bash
# helper functions for immediate+persistent shell vars
# be sure to source ~/.vars in your ~/.bashrc etc.
#
# usage:
# $ var+ pdir /long/annoying/path/to/type/to/project/v1.0
# $ cd $pdir
# (start a new terminal tomorrow...)
# $ cd $pdir
# $ vars
# export pdir=/long/annoying/path/to/type/to/project/v1.0
# $ var- pdir
VARS_FILE=$HOME/.vars
function remove_var_from_vars_file() {
sed -i "/^export $1=.\+$/d" $VARS_FILE
}
function var+ {
remove_var_from_vars_file $1
echo export $1=$2 >> $VARS_FILE
export $1=$2
}
function var- {
remove_var_from_vars_file $1
unset $1
}
function vars {
cat $VARS_FILE
}
@raggi
Copy link

raggi commented Mar 14, 2014

I see other people have trouble writing valid shell functions :D

either function or (), never both!

Turns out this would work for .env too, the foreman / heroku standards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment