Posted By

harrikauhanen on 07/06/10


Tagged


Versions (?)

Show rvm gemset, git branch and git status in your command prompt


 / Published in: Bash
 

  1. # ~/.profile
  2.  
  3. function detect_rvm_version {
  4. local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
  5. [ "$gemset" != "" ] && gemset="@$gemset"
  6. local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}')
  7. [ "$version" != "" ] && version="$version"
  8. local full="$version$gemset"
  9. [ "$full" != "" ] && echo "$full"
  10. }
  11.  
  12. function detect_git_dirty {
  13. local git_status=$(git status 2>&1 | tail -n1)
  14. [[ $git_status != "fatal: Not a git repository (or any of the parent directories): .git" ]] && [[ $git_status != "nothing to commit (working directory clean)" ]] && echo "*"
  15. }
  16.  
  17. function detect_git_branch {
  18. git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
  19. }
  20.  
  21. function dev_info {
  22. echo "[$(detect_rvm_version) $(detect_git_branch)$(detect_git_dirty)]"
  23. }
  24.  
  25. # Colors
  26. txtred='\e[0;31m' # Red
  27. txtwht='\e[0;37m' # White
  28. txtrst='\e[0m' # Text Reset
  29.  
  30. # Custom command prompt
  31. export PS1="\[$txtwht\]\w \[$txtred\]\$(dev_info) \[$txtrst\]"
  32.  
  33. # If you don't have colors, use something like this instead:
  34. # export PS1="\w \$(dev_info) "

Report this snippet  

You need to login to post a comment.