Skip to content

Instantly share code, notes, and snippets.

@lcjury
Created June 10, 2021 03:43
Show Gist options
  • Save lcjury/7f928975d308ceccae9b829266bac0a1 to your computer and use it in GitHub Desktop.
Save lcjury/7f928975d308ceccae9b829266bac0a1 to your computer and use it in GitHub Desktop.
lazy load nvm and ruby
if [ -s "$HOME/.nvm/nvm.sh" ] && [ ! "$(type -t __init_nvm)" = function ]; then
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
declare -a __node_commands=('nvm' 'node' 'npm' 'yarn' 'gulp' 'grunt' 'webpack')
function __init_nvm() {
for i in "${__node_commands[@]}"; do unalias $i; done
. "$NVM_DIR"/nvm.sh
unset __node_commands
unset -f __init_nvm
}
for i in "${__node_commands[@]}"; do alias $i='__init_nvm && '$i; done
fi
# Ruby lazy load
declare -a __ruby_commands=('ruby' 'gem', 'irb')
function __init_ruby() {
for i in "${__ruby_commands[@]}"; do unalias $i; done
eval "$(rbenv init -)"
unset -f __init_ruby
}
for i in "${__ruby_commands[@]}"; do alias $i='__init_ruby && '$i; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment