Skip to content

Instantly share code, notes, and snippets.

@ctudorache87
Last active May 10, 2020 08:32
Show Gist options
  • Save ctudorache87/240ac12c803c60f8bf08ef8b680f4955 to your computer and use it in GitHub Desktop.
Save ctudorache87/240ac12c803c60f8bf08ef8b680f4955 to your computer and use it in GitHub Desktop.
WSL NVM fix in bash.rc
# Add these lines to .bashrc in WSL to prevent slow shell startup because of NVM
export NVM_DIR="$HOME/.nvm"
# add --no-use so that nvm doesn't load node automatically
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --no-use # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# manually add desired node version to PATH
NODE_VERSION="v12.6.0"
export PATH="${PATH}:${NVM_DIR}/versions/node/${NODE_VERSION}/bin"
get_bash_w() {
# Returns the same working directory that the \W bash prompt command
echo $(pwd | sed 's@'"$HOME"'@~@')
}
split_pwd() {
# Split pwd into the first element, elipsis (...) and the last subfolder
# /usr/local/share/doc --> /usr/.../doc
# ~/project/folder/subfolder --> ~/project/../subfolder
split=2
W=$(get_bash_w)
if [ $(echo $W | grep -o '/' | wc -l) -gt $split ]; then
echo $W | cut -d'/' -f1-$split | xargs -I{} echo {}"/../${W##*/}"
else
echo $W
fi
}
# git aware bash
# export PS1='\[\033[01;34m\]\w\[\033[01;32m\]\[\033[0m\033[0;32m\]\[\033[01;32m\]$(__git_ps1)\[\033[00m\] $ '
# git aware bash with path shortened
export PS1='\[\033[01;34m\]$(split_pwd)\[\033[01;32m\]\[\033[0m\033[0;32m\]\[\033[01;32m\]$(__git_ps1)\[\033[35m\] >\[\033[94m\]>\[\033[33m\]> \[\033[00m\]'
#parse_git_branch() {
# git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
#}
#export PS1="\[\e[34m\]\u@\h \[\e[32m\]\$(parse_git_branch)\[\e[00m\]$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment