Shell functions to load enviroments
Nowadays, tools like rbenv or nvm manipulate your shell environment to provide specific versions of ruby, node, etc. If you add several of those scripts to your .bashrc or .zshrc it takes to long to spawn a new shell, at least for my taste.
The following functions can be added instead and initialize the environments only when the specific commands are invoced for the first time.
# for rbenv
function rbenv {
echo "~~~ init rbenv ~~~"
unset -f rbenv
export PATH=$HOME/.rbenv/bin:$PATH
eval "$(rbenv init -)"
rbenv $@
}
# for nvm
function nvm {
echo "~~~ init nvm ~~~"
unset -f nvm
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"
nvm $@
}
# for miniconda (using zsh)
function conda {
echo "~~~ init conda ~~~"
unset -f conda
eval "$(conda shell.zsh hook)"
conda $@
}