Advertisement
Guest User

Untitled

a guest
May 28th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #!/bin/bash
  2. # Add this to the end of .bashrc
  3.  
  4. # prompt with ruby version
  5. # rbenv version | sed -e 's/ .*//'
  6. __rbenv_ps1 ()
  7. {
  8. rbenv_ruby_version=`rbenv version | sed -e 's/ .*//'`
  9. printf $rbenv_ruby_version
  10. }
  11.  
  12. color_txt_blue='\e[0;34m'
  13. color_txt_green='\e[0;32m'
  14. color_txt_yellow='\e[0;33m'
  15. color_txt_red='\e[0;31m'
  16. color_txt_white='\e[0;37m'
  17. color_txt_dark_grey='\e[90m'
  18. color_txt_default='\e[39m'
  19.  
  20. rbenv_installed () {
  21. [[ -f `which rbenv` ]]
  22. }
  23.  
  24. ruby_selected () {
  25. [[ `rbenv version` != "system "* ]]
  26. }
  27.  
  28. git_ps1_available () {
  29. [[ `type __git_ps1 | head -n 1` = "__git_ps1 is a function" ]]
  30. }
  31.  
  32. git_repo_detected () {
  33. git status &> /dev/null
  34. }
  35.  
  36. git_branch_color () {
  37. case `git symbolic-ref --short HEAD` in
  38. 'master')
  39. echo $color_txt_red
  40. ;;
  41. 'dev')
  42. echo $color_txt_yellow
  43. ;;
  44. *)
  45. echo $color_txt_green
  46. ;;
  47. esac
  48. }
  49.  
  50. ruby_version_name () {
  51. if rbenv_installed && ruby_selected; then
  52. echo "\[$color_txt_dark_grey\]ruby-$(__rbenv_ps1)"
  53. fi
  54. }
  55.  
  56. git_branch_name () {
  57. if git_ps1_available && git_repo_detected; then
  58. echo "\[$(git_branch_color)\]$(__git_ps1)"
  59. fi
  60. }
  61.  
  62. current_working_dir () {
  63. echo " \[$color_txt_white\]\w"
  64. }
  65.  
  66. bash_prompt_sign () {
  67. echo "\[$color_txt_default\]\$"
  68. }
  69.  
  70. current_user_with_host () {
  71. if rbenv_installed && ruby_selected; then
  72. echo ""
  73. else
  74. echo " \[$color_txt_dark_grey\]\u@\h"
  75. fi
  76. }
  77.  
  78. set_bash_prompt () {
  79. PS1="$(current_user_with_host)$(current_working_dir) $(ruby_version_name)$(git_branch_name)$(bash_prompt_sign) "
  80. }
  81.  
  82. export PROMPT_COMMAND=set_bash_prompt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement