bureau.zsh-theme 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # oh-my-zsh Bureau Theme
  2. ### NVM
  3. ZSH_THEME_NVM_PROMPT_PREFIX="%B⬡%b "
  4. ZSH_THEME_NVM_PROMPT_SUFFIX=""
  5. ### Git [±master ▾●]
  6. ZSH_THEME_GIT_PROMPT_PREFIX="[%{$fg_bold[green]%}±%{$reset_color%}%{$fg_bold[white]%}"
  7. ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}]"
  8. ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}✓%{$reset_color%}"
  9. ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg[cyan]%}▴%{$reset_color%}"
  10. ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg[magenta]%}▾%{$reset_color%}"
  11. ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}"
  12. ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}●%{$reset_color%}"
  13. ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}"
  14. bureau_git_info () {
  15. local ref
  16. ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
  17. ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
  18. echo "${ref#refs/heads/}"
  19. }
  20. bureau_git_status() {
  21. local result gitstatus
  22. gitstatus="$(command git status --porcelain -b 2>/dev/null)"
  23. # check status of files
  24. local gitfiles="$(tail -n +2 <<< "$gitstatus")"
  25. if [[ -n "$gitfiles" ]]; then
  26. if [[ "$gitfiles" =~ $'(^|\n)[AMRD]. ' ]]; then
  27. result+="$ZSH_THEME_GIT_PROMPT_STAGED"
  28. fi
  29. if [[ "$gitfiles" =~ $'(^|\n).[MTD] ' ]]; then
  30. result+="$ZSH_THEME_GIT_PROMPT_UNSTAGED"
  31. fi
  32. if [[ "$gitfiles" =~ $'(^|\n)\\?\\? ' ]]; then
  33. result+="$ZSH_THEME_GIT_PROMPT_UNTRACKED"
  34. fi
  35. if [[ "$gitfiles" =~ $'(^|\n)UU ' ]]; then
  36. result+="$ZSH_THEME_GIT_PROMPT_UNMERGED"
  37. fi
  38. else
  39. result+="$ZSH_THEME_GIT_PROMPT_CLEAN"
  40. fi
  41. # check status of local repository
  42. local gitbranch="$(head -n 1 <<< "$gitstatus")"
  43. if [[ "$gitbranch" =~ '^## .*ahead' ]]; then
  44. result+="$ZSH_THEME_GIT_PROMPT_AHEAD"
  45. fi
  46. if [[ "$gitbranch" =~ '^## .*behind' ]]; then
  47. result+="$ZSH_THEME_GIT_PROMPT_BEHIND"
  48. fi
  49. if [[ "$gitbranch" =~ '^## .*diverged' ]]; then
  50. result+="$ZSH_THEME_GIT_PROMPT_DIVERGED"
  51. fi
  52. # check if there are stashed changes
  53. if command git rev-parse --verify refs/stash &> /dev/null; then
  54. result+="$ZSH_THEME_GIT_PROMPT_STASHED"
  55. fi
  56. echo $result
  57. }
  58. bureau_git_prompt() {
  59. # check git information
  60. local gitinfo=$(bureau_git_info)
  61. if [[ -z "$gitinfo" ]]; then
  62. return
  63. fi
  64. # quote % in git information
  65. local output="${gitinfo:gs/%/%%}"
  66. # check git status
  67. local gitstatus=$(bureau_git_status)
  68. if [[ -n "$gitstatus" ]]; then
  69. output+=" $gitstatus"
  70. fi
  71. echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${output}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
  72. }
  73. _PATH="%{$fg_bold[white]%}%~%{$reset_color%}"
  74. if [[ $EUID -eq 0 ]]; then
  75. _USERNAME="%{$fg_bold[red]%}%n"
  76. _LIBERTY="%{$fg[red]%}#"
  77. else
  78. _USERNAME="%{$fg_bold[white]%}%n"
  79. _LIBERTY="%{$fg[green]%}$"
  80. fi
  81. _USERNAME="$_USERNAME%{$reset_color%}@%m"
  82. _LIBERTY="$_LIBERTY%{$reset_color%}"
  83. get_space () {
  84. local STR=$1$2
  85. local zero='%([BSUbfksu]|([FB]|){*})'
  86. local LENGTH=${#${(S%%)STR//$~zero/}}
  87. local SPACES=$(( COLUMNS - LENGTH - ${ZLE_RPROMPT_INDENT:-1} ))
  88. (( SPACES > 0 )) || return
  89. printf ' %.0s' {1..$SPACES}
  90. }
  91. _1LEFT="$_USERNAME $_PATH"
  92. _1RIGHT="[%*]"
  93. bureau_precmd () {
  94. _1SPACES=`get_space $_1LEFT $_1RIGHT`
  95. print
  96. print -rP "$_1LEFT$_1SPACES$_1RIGHT"
  97. }
  98. setopt prompt_subst
  99. PROMPT='> $_LIBERTY '
  100. RPROMPT='$(nvm_prompt_info) $(bureau_git_prompt)'
  101. autoload -U add-zsh-hook
  102. add-zsh-hook precmd bureau_precmd