Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. source ~/.git-prompt.sh
  2.  
  3.  
  4. # parse_git_branch() {
  5. # git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \color{#fff}{.*}.∗/ (\1)/'
  6. # }
  7.  
  8. # # export PS1='${debian_chroot:+($debian_chroot)}\u@\h\[\033[33m\]虎\[\033[00m\]\[\033[01;34m\]\w\[\033[00m\]\$ '
  9. # export PS1='\[\033[01;34m\]\w\[\033[00m\]\[\033[33m\]虎\[\033[00m\]\[\033[31m\]$(parse_git_branch)\[\033[00m\]$ '
  10.  
  11.  
  12. #
  13. # Set the prompt #
  14. #
  15.  
  16. # Select git info displayed, see /usr/lib/git-core/git-sh-prompt for more
  17. export GIT_PS1_SHOWDIRTYSTATE=1 # '*'=unstaged, '+'=staged
  18. export GIT_PS1_SHOWSTASHSTATE=1 # '$'=stashed
  19. export GIT_PS1_SHOWUNTRACKEDFILES=1 # '%'=untracked
  20. export GIT_PS1_SHOWUPSTREAM="verbose" # 'u='=no difference, 'u+1'=ahead by 1 commit
  21. export GIT_PS1_STATESEPARATOR='' # No space between branch and index status
  22. export GIT_PS1_DESCRIBE_STYLE="describe" # detached HEAD style:
  23. # contains relative to newer annotated tag (v1.6.3.2~35)
  24. # branch relative to newer tag or branch (master~4)
  25. # describe relative to older annotated tag (v1.6.3.1-13-gdd42c2f)
  26. # default exactly eatching tag
  27.  
  28. # Check if we support colours
  29. __colour_enabled() {
  30. local -i colors=$(tput colors 2>/dev/null)
  31. [[ $? -eq 0 ]] && [[ $colors -gt 2 ]]
  32. }
  33. unset __colourise_prompt && __colour_enabled && __colourise_prompt=1
  34.  
  35. __set_bash_prompt()
  36. {
  37. local exit="$?" # Save the exit status of the last command
  38.  
  39. # PS1 is made from $PreGitPS1 + <git-status> + $PostGitPS1
  40. local PreGitPS1="${debian_chroot:+($debian_chroot)}"
  41. local PostGitPS1=""
  42.  
  43. if [[ $__colourise_prompt ]]; then
  44. export GIT_PS1_SHOWCOLORHINTS=1
  45.  
  46. # Wrap the colour codes between \[ and \], so that
  47. # bash counts the correct number of characters for line wrapping:
  48. local Red='\[\e[0;31m\]'; local BRed='\[\e[1;31m\]'
  49. local Gre='\[\e[0;32m\]'; local BGre='\[\e[1;32m\]'
  50. local Yel='\[\e[0;33m\]'; local BYel='\[\e[1;33m\]'
  51. local Blu='\[\e[0;34m\]'; local BBlu='\[\e[1;34m\]'
  52. local Mag='\[\e[0;35m\]'; local BMag='\[\e[1;35m\]'
  53. local Cya='\[\e[0;36m\]'; local BCya='\[\e[1;36m\]'
  54. local Whi='\[\e[0;37m\]'; local BWhi='\[\e[1;37m\]'
  55. local None='\[\e[0m\]' # Return to default colour
  56.  
  57. # No username and bright colour if root
  58. # if [[ ${EUID} == 0 ]]; then
  59. # PreGitPS1+="$BRed\h "
  60. # else
  61. # PreGitPS1+="$Red\u@\h$None:"
  62. # fi
  63.  
  64. PreGitPS1+="$Blu\w$None"
  65. else # No colour
  66. # Sets prompt like: ravi@boxy:~/prj/sample_app
  67. unset GIT_PS1_SHOWCOLORHINTS
  68. PreGitPS1="${debian_chroot:+($debian_chroot)}\u@\h:\w"
  69. fi
  70.  
  71. # Now build the part after git's status
  72.  
  73. # # Highlight non-standard exit codes
  74. # if [[ $exit != 0 ]]; then
  75. # PostGitPS1="$Red[$exit]"
  76. # fi
  77.  
  78. # Change colour of prompt if root
  79. if [[ ${EUID} == 0 ]]; then
  80. PostGitPS1+="$BRed"'\$ '"$None"
  81. else
  82. PostGitPS1+="$Mag"'\$ '"$None"
  83. fi
  84.  
  85. # Set PS1 from $PreGitPS1 + <git-status> + $PostGitPS1
  86. __git_ps1 "$PreGitPS1" "$PostGitPS1" '虎%s'
  87.  
  88. # echo '$PS1='"$PS1" # debug
  89. # defaut Linux Mint 17.2 user prompt:
  90. # PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\[\033[00m\] $(__git_ps1 "(%s)") \$ '
  91. }
  92.  
  93. # This tells bash to reinterpret PS1 after every command, which we
  94. # need because __git_ps1 will return different text and colors
  95. PROMPT_COMMAND=__set_bash_prompt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement