Skip to content

Instantly share code, notes, and snippets.

@mgimenez
Created November 11, 2019 14:52
Show Gist options
  • Save mgimenez/2d2db3f9bfe1f860d38fde97c0b4cee4 to your computer and use it in GitHub Desktop.
Save mgimenez/2d2db3f9bfe1f860d38fde97c0b4cee4 to your computer and use it in GitHub Desktop.
bash_profile
export CLICOLOR=1
export LSCOLORS=exFxCxDxBxegedabagaced
#Start directory
cd /Users/mgimenez/Documents/workspace
#GIT Alias
alias sta='git status'
alias add='git add'
alias com='git commit -m'
alias pul='git pull origin'
alias pus='git push origin'
alias che='git checkout'
alias dif='git diff'
alias mer='git merge'
alias stas='git stash'
alias stap='git stash pop'
#Switch Node Version
#Requires NVM installed
find-up () {
path=$(pwd)
while [[ "$path" != "" && ! -e "$path/$1" ]]; do
path=${path%/*}
done
echo "$path"
}
cdnvm(){
cd "$@";
nvm_path=$(find-up .nvmrc | tr -d '[:space:]')
# If there are no .nvmrc file, use the default nvm version
if [[ ! $nvm_path = *[^[:space:]]* ]]; then
declare default_version;
default_version=$(nvm version default);
# If there is no default version, set it to `node`
# This will use the latest version on your machine
if [[ $default_version == "N/A" ]]; then
nvm alias default node;
default_version=$(nvm version default);
fi
# If the current version is not the default version, set it to use the default version
if [[ $(nvm current) != "$default_version" ]]; then
nvm use default;
fi
elif [[ -s $nvm_path/.nvmrc && -r $nvm_path/.nvmrc ]]; then
declare nvm_version
nvm_version=$(<"$nvm_path"/.nvmrc)
declare locally_resolved_nvm_version
# `nvm ls` will check all locally-available versions
# If there are multiple matching versions, take the latest one
# Remove the `->` and `*` characters and spaces
# `locally_resolved_nvm_version` will be `N/A` if no local versions are found
locally_resolved_nvm_version=$(nvm ls --no-colors "$nvm_version" | tail -1 | tr -d '\->*' | tr -d '[:space:]')
# If it is not already installed, install it
# `nvm install` will implicitly use the newly-installed version
if [[ "$locally_resolved_nvm_version" == "N/A" ]]; then
nvm install "$nvm_version";
elif [[ $(nvm current) != "$locally_resolved_nvm_version" ]]; then
nvm use "$nvm_version";
fi
fi
}
alias cd='cdnvm'
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment