-
-
Save usergenic/9535417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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