Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. export NVM_DIR="$HOME/.nvm"
  2. [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
  3. [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
  4.  
  5. # nvm auto-switch
  6. find-up () {
  7. path=$(pwd)
  8. while [[ "$path" != "" && ! -e "$path/$1" ]]; do
  9. path=${path%/*}
  10. done
  11. echo "$path"
  12. }
  13.  
  14. cdnvm(){
  15. cd "$@";
  16. nvm_path=$(find-up .nvmrc | tr -d '[:space:]')
  17.  
  18. # If there are no .nvmrc file, use the default nvm version
  19. if [[ ! $nvm_path = *[^[:space:]]* ]]; then
  20.  
  21. declare default_version;
  22. default_version=$(nvm version default);
  23.  
  24. # If there is no default version, set it to `node`
  25. # This will use the latest version on your machine
  26. if [[ $default_version == "N/A" ]]; then
  27. nvm alias default node;
  28. default_version=$(nvm version default);
  29. fi
  30.  
  31. # If the current version is not the default version, set it to use the default version
  32. if [[ $(nvm current) != "$default_version" ]]; then
  33. nvm use default;
  34. fi
  35.  
  36. elif [[ -s $nvm_path/.nvmrc && -r $nvm_path/.nvmrc ]]; then
  37. declare nvm_version
  38. nvm_version=$(<"$nvm_path"/.nvmrc)
  39.  
  40. declare locally_resolved_nvm_version
  41. # `nvm ls` will check all locally-available versions
  42. # If there are multiple matching versions, take the latest one
  43. # Remove the `->` and `*` characters and spaces
  44. # `locally_resolved_nvm_version` will be `N/A` if no local versions are found
  45. locally_resolved_nvm_version=$(nvm ls --no-colors $(<"./.nvmrc") | tail -1 | tr -d '\->*' | tr -d '[:space:]')
  46.  
  47. # If it is not already installed, install it
  48. # `nvm install` will implicitly use the newly-installed version
  49. if [[ "$locally_resolved_nvm_version" == "N/A" ]]; then
  50. nvm install "$nvm_version";
  51. elif [[ $(nvm current) != "$locally_resolved_nvm_version" ]]; then
  52. nvm use "$nvm_version";
  53. fi
  54. fi
  55. }
  56. alias cd='cdnvm'
  57.  
  58.  
  59. # Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
  60. export PATH="$PATH:$HOME/.rvm/bin"
  61.  
  62. # Sourcing git conf. files
  63. source ~/.git-completion.sh
  64.  
  65. # get git branch
  66. parse_git_branch() {
  67. git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
  68. }
  69.  
  70. PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
  71. CLICOLOR=1
  72. LSCOLORS=ExFxBxDxCxegedabagacad
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement