CryZe

My Git PS1

Oct 11th, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.02 KB | None | 0 0
  1. #  by Mike Stewart - http://MediaDoneRight.com
  2.  
  3. #  SETUP CONSTANTS
  4. #  Bunch-o-predefined colors.  Makes reading code easier than escape sequences.
  5. #  I don't remember where I found this.  o_O
  6.  
  7. # Reset
  8. Color_Off="\[\033[0m\]"       # Text Reset
  9.  
  10. # Regular Colors
  11. Black="\[\033[0;30m\]"        # Black
  12. Red="\[\033[0;31m\]"          # Red
  13. Green="\[\033[0;32m\]"        # Green
  14. Yellow="\[\033[0;33m\]"       # Yellow
  15. Blue="\[\033[0;34m\]"         # Blue
  16. Purple="\[\033[0;35m\]"       # Purple
  17. Cyan="\[\033[0;36m\]"         # Cyan
  18. White="\[\033[0;37m\]"        # White
  19.  
  20. # Bold
  21. BBlack="\[\033[1;30m\]"       # Black
  22. BRed="\[\033[1;31m\]"         # Red
  23. BGreen="\[\033[1;32m\]"       # Green
  24. BYellow="\[\033[1;33m\]"      # Yellow
  25. BBlue="\[\033[1;34m\]"        # Blue
  26. BPurple="\[\033[1;35m\]"      # Purple
  27. BCyan="\[\033[1;36m\]"        # Cyan
  28. BWhite="\[\033[1;37m\]"       # White
  29.  
  30. # Underline
  31. UBlack="\[\033[4;30m\]"       # Black
  32. URed="\[\033[4;31m\]"         # Red
  33. UGreen="\[\033[4;32m\]"       # Green
  34. UYellow="\[\033[4;33m\]"      # Yellow
  35. UBlue="\[\033[4;34m\]"        # Blue
  36. UPurple="\[\033[4;35m\]"      # Purple
  37. UCyan="\[\033[4;36m\]"        # Cyan
  38. UWhite="\[\033[4;37m\]"       # White
  39.  
  40. # Background
  41. On_Black="\[\033[40m\]"       # Black
  42. On_Red="\[\033[41m\]"         # Red
  43. On_Green="\[\033[42m\]"       # Green
  44. On_Yellow="\[\033[43m\]"      # Yellow
  45. On_Blue="\[\033[44m\]"        # Blue
  46. On_Purple="\[\033[45m\]"      # Purple
  47. On_Cyan="\[\033[46m\]"        # Cyan
  48. On_White="\[\033[47m\]"       # White
  49.  
  50. # High Intensty
  51. IBlack="\[\033[0;90m\]"       # Black
  52. IRed="\[\033[0;91m\]"         # Red
  53. IGreen="\[\033[0;92m\]"       # Green
  54. IYellow="\[\033[0;93m\]"      # Yellow
  55. IBlue="\[\033[0;94m\]"        # Blue
  56. IPurple="\[\033[0;95m\]"      # Purple
  57. ICyan="\[\033[0;96m\]"        # Cyan
  58. IWhite="\[\033[0;97m\]"       # White
  59.  
  60. # Bold High Intensty
  61. BIBlack="\[\033[1;90m\]"      # Black
  62. BIRed="\[\033[1;91m\]"        # Red
  63. BIGreen="\[\033[1;92m\]"      # Green
  64. BIYellow="\[\033[1;93m\]"     # Yellow
  65. BIBlue="\[\033[1;94m\]"       # Blue
  66. BIPurple="\[\033[1;95m\]"     # Purple
  67. BICyan="\[\033[1;96m\]"       # Cyan
  68. BIWhite="\[\033[1;97m\]"      # White
  69.  
  70. # High Intensty backgrounds
  71. On_IBlack="\[\033[0;100m\]"   # Black
  72. On_IRed="\[\033[0;101m\]"     # Red
  73. On_IGreen="\[\033[0;102m\]"   # Green
  74. On_IYellow="\[\033[0;103m\]"  # Yellow
  75. On_IBlue="\[\033[0;104m\]"    # Blue
  76. On_IPurple="\[\033[10;95m\]"  # Purple
  77. On_ICyan="\[\033[0;106m\]"    # Cyan
  78. On_IWhite="\[\033[0;107m\]"   # White
  79.  
  80. # Various variables you might want for your PS1 prompt instead
  81. #  by Mike Stewart - http://MediaDoneRight.com
  82.  
  83. #  SETUP CONSTANTS
  84. #  Bunch-o-predefined colors.  Makes reading code easier than escape sequences.
  85. #  I don't remember where I found this.  o_O
  86.  
  87. # Reset
  88. Color_Off="\[\033[0m\]"       # Text Reset
  89.  
  90. # Regular Colors
  91. Black="\[\033[0;30m\]"        # Black
  92. Red="\[\033[0;31m\]"          # Red
  93. Green="\[\033[0;32m\]"        # Green
  94. Yellow="\[\033[0;33m\]"       # Yellow
  95. Blue="\[\033[0;34m\]"         # Blue
  96. Purple="\[\033[0;35m\]"       # Purple
  97. Cyan="\[\033[0;36m\]"         # Cyan
  98. White="\[\033[0;37m\]"        # White
  99.  
  100. # Bold
  101. BBlack="\[\033[1;30m\]"       # Black
  102. BRed="\[\033[1;31m\]"         # Red
  103. BGreen="\[\033[1;32m\]"       # Green
  104. BYellow="\[\033[1;33m\]"      # Yellow
  105. BBlue="\[\033[1;34m\]"        # Blue
  106. BPurple="\[\033[1;35m\]"      # Purple
  107. BCyan="\[\033[1;36m\]"        # Cyan
  108. BWhite="\[\033[1;37m\]"       # White
  109.  
  110. # Underline
  111. UBlack="\[\033[4;30m\]"       # Black
  112. URed="\[\033[4;31m\]"         # Red
  113. UGreen="\[\033[4;32m\]"       # Green
  114. UYellow="\[\033[4;33m\]"      # Yellow
  115. UBlue="\[\033[4;34m\]"        # Blue
  116. UPurple="\[\033[4;35m\]"      # Purple
  117. UCyan="\[\033[4;36m\]"        # Cyan
  118. UWhite="\[\033[4;37m\]"       # White
  119.  
  120. # Background
  121. On_Black="\[\033[40m\]"       # Black
  122. On_Red="\[\033[41m\]"         # Red
  123. On_Green="\[\033[42m\]"       # Green
  124. On_Yellow="\[\033[43m\]"      # Yellow
  125. On_Blue="\[\033[44m\]"        # Blue
  126. On_Purple="\[\033[45m\]"      # Purple
  127. On_Cyan="\[\033[46m\]"        # Cyan
  128. On_White="\[\033[47m\]"       # White
  129.  
  130. # High Intensty
  131. IBlack="\[\033[0;90m\]"       # Black
  132. IRed="\[\033[0;91m\]"         # Red
  133. IGreen="\[\033[0;92m\]"       # Green
  134. IYellow="\[\033[0;93m\]"      # Yellow
  135. IBlue="\[\033[0;94m\]"        # Blue
  136. IPurple="\[\033[0;95m\]"      # Purple
  137. ICyan="\[\033[0;96m\]"        # Cyan
  138. IWhite="\[\033[0;97m\]"       # White
  139.  
  140. # Bold High Intensty
  141. BIBlack="\[\033[1;90m\]"      # Black
  142. BIRed="\[\033[1;91m\]"        # Red
  143. BIGreen="\[\033[1;92m\]"      # Green
  144. BIYellow="\[\033[1;93m\]"     # Yellow
  145. BIBlue="\[\033[1;94m\]"       # Blue
  146. BIPurple="\[\033[1;95m\]"     # Purple
  147. BICyan="\[\033[1;96m\]"       # Cyan
  148. BIWhite="\[\033[1;97m\]"      # White
  149.  
  150. # High Intensty backgrounds
  151. On_IBlack="\[\033[0;100m\]"   # Black
  152. On_IRed="\[\033[0;101m\]"     # Red
  153. On_IGreen="\[\033[0;102m\]"   # Green
  154. On_IYellow="\[\033[0;103m\]"  # Yellow
  155. On_IBlue="\[\033[0;104m\]"    # Blue
  156. On_IPurple="\[\033[10;95m\]"  # Purple
  157. On_ICyan="\[\033[0;106m\]"    # Cyan
  158. On_IWhite="\[\033[0;107m\]"   # White
  159.  
  160. # Various variables you might want for your PS1 prompt instead
  161. Time12h="\T"
  162. Time12a="\@"
  163. User="\u"
  164. Host="\h"
  165. PathShort="\w"
  166. PathFull="\W"
  167. NewLine="\n"
  168. Jobs="\j"
  169.  
  170.  
  171. # This PS1 snippet was adopted from code for MAC/BSD I saw from: http://allancraig.net/index.php?option=com_content&view=article&id=108:ps1-export-command-for-git&catid=45:general&Itemid=96
  172. # I tweaked it to work on UBUNTU 11.04 & 11.10 plus made it mo' better
  173.  
  174. export PS1=$Color_Off'$(git branch &>/dev/null;\
  175. if [ $? -eq 0 ]; then \
  176. echo "'$Green$User@$Host' '$Yellow$PathShort' $(echo `git status` | grep "nothing to commit" > /dev/null 2>&1; \
  177. if [ "$?" -eq "0" ]; then \
  178.  # @4 - Clean repository - nothing to commit
  179.  echo "'$Green'"$(__git_ps1 "(%s)"); \
  180. else \
  181.  # @5 - Changes to working tree
  182.  echo "'$IRed'"$(__git_ps1 "{%s}"); \
  183. fi) '$Color_Off'\n\$ "; \
  184. else \
  185. # @2 - Prompt when not in GIT repo
  186. echo "'$Green$User@$Host' '$Yellow$PathShort$Color_Off'\n\$ "; \
  187. fi)'
Advertisement
Add Comment
Please, Sign In to add comment