bureau.zsh-theme 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_branch () {
  15. ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
  16. ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
  17. echo "${ref#refs/heads/}"
  18. }
  19. bureau_git_status() {
  20. _STATUS=""
  21. # check status of files
  22. _INDEX=$(command git status --porcelain 2> /dev/null)
  23. if [[ -n "$_INDEX" ]]; then
  24. if $(echo "$_INDEX" | command grep -q '^[AMRD]. '); then
  25. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
  26. fi
  27. if $(echo "$_INDEX" | command grep -q '^.[MTD] '); then
  28. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
  29. fi
  30. if $(echo "$_INDEX" | command grep -q -E '^\?\? '); then
  31. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED"
  32. fi
  33. if $(echo "$_INDEX" | command grep -q '^UU '); then
  34. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED"
  35. fi
  36. else
  37. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_CLEAN"
  38. fi
  39. # check status of local repository
  40. _INDEX=$(command git status --porcelain -b 2> /dev/null)
  41. if $(echo "$_INDEX" | command grep -q '^## .*ahead'); then
  42. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
  43. fi
  44. if $(echo "$_INDEX" | command grep -q '^## .*behind'); then
  45. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND"
  46. fi
  47. if $(echo "$_INDEX" | command grep -q '^## .*diverged'); then
  48. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED"
  49. fi
  50. if $(command git rev-parse --verify refs/stash &> /dev/null); then
  51. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STASHED"
  52. fi
  53. echo $_STATUS
  54. }
  55. bureau_git_prompt () {
  56. local _branch=$(bureau_git_branch)
  57. local _status=$(bureau_git_status)
  58. local _result=""
  59. if [[ "${_branch}x" != "x" ]]; then
  60. _result="$ZSH_THEME_GIT_PROMPT_PREFIX$_branch"
  61. if [[ "${_status}x" != "x" ]]; then
  62. _result="$_result $_status"
  63. fi
  64. _result="$_result$ZSH_THEME_GIT_PROMPT_SUFFIX"
  65. fi
  66. echo $_result
  67. }
  68. _PATH="%{$fg_bold[white]%}%~%{$reset_color%}"
  69. if [[ $EUID -eq 0 ]]; then
  70. _USERNAME="%{$fg_bold[red]%}%n"
  71. _LIBERTY="%{$fg[red]%}#"
  72. else
  73. _USERNAME="%{$fg_bold[white]%}%n"
  74. _LIBERTY="%{$fg[green]%}$"
  75. fi
  76. _USERNAME="$_USERNAME%{$reset_color%}@%m"
  77. _LIBERTY="$_LIBERTY%{$reset_color%}"
  78. get_space () {
  79. local STR=$1$2
  80. local zero='%([BSUbfksu]|([FB]|){*})'
  81. local LENGTH=${#${(S%%)STR//$~zero/}}
  82. local SPACES=""
  83. (( LENGTH = ${COLUMNS} - $LENGTH - 1))
  84. for i in {0..$LENGTH}
  85. do
  86. SPACES="$SPACES "
  87. done
  88. echo $SPACES
  89. }
  90. _1LEFT="$_USERNAME $_PATH"
  91. _1RIGHT="[%*] "
  92. bureau_precmd () {
  93. _1SPACES=`get_space $_1LEFT $_1RIGHT`
  94. print
  95. print -rP "$_1LEFT$_1SPACES$_1RIGHT"
  96. }
  97. setopt prompt_subst
  98. PROMPT='> $_LIBERTY '
  99. RPROMPT='$(nvm_prompt_info) $(bureau_git_prompt)'
  100. autoload -U add-zsh-hook
  101. add-zsh-hook precmd bureau_precmd