bureau.zsh-theme 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. 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 _STATUS _INDEX
  22. # check status of files
  23. _INDEX=$(command git status --porcelain 2> /dev/null)
  24. if [[ -n "$_INDEX" ]]; then
  25. if $(echo "$_INDEX" | command grep -q '^[AMRD]. '); then
  26. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
  27. fi
  28. if $(echo "$_INDEX" | command grep -q '^.[MTD] '); then
  29. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
  30. fi
  31. if $(echo "$_INDEX" | command grep -q -E '^\?\? '); then
  32. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED"
  33. fi
  34. if $(echo "$_INDEX" | command grep -q '^UU '); then
  35. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED"
  36. fi
  37. else
  38. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_CLEAN"
  39. fi
  40. # check status of local repository
  41. _INDEX=$(command git status --porcelain -b 2> /dev/null)
  42. if $(echo "$_INDEX" | command grep -q '^## .*ahead'); then
  43. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
  44. fi
  45. if $(echo "$_INDEX" | command grep -q '^## .*behind'); then
  46. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND"
  47. fi
  48. if $(echo "$_INDEX" | command grep -q '^## .*diverged'); then
  49. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED"
  50. fi
  51. if $(command git rev-parse --verify refs/stash &> /dev/null); then
  52. _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STASHED"
  53. fi
  54. echo $_STATUS
  55. }
  56. bureau_git_prompt() {
  57. local branch=$(bureau_git_branch)
  58. local status=$(bureau_git_status)
  59. local info
  60. if [[ -z "${branch}" ]]; then
  61. return
  62. fi
  63. info="${branch:gs/%/%%}"
  64. if [[ -n "${status}" ]]; then
  65. info+=" $status"
  66. fi
  67. echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${info}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
  68. }
  69. _PATH="%{$fg_bold[white]%}%~%{$reset_color%}"
  70. if [[ $EUID -eq 0 ]]; then
  71. _USERNAME="%{$fg_bold[red]%}%n"
  72. _LIBERTY="%{$fg[red]%}#"
  73. else
  74. _USERNAME="%{$fg_bold[white]%}%n"
  75. _LIBERTY="%{$fg[green]%}$"
  76. fi
  77. _USERNAME="$_USERNAME%{$reset_color%}@%m"
  78. _LIBERTY="$_LIBERTY%{$reset_color%}"
  79. get_space () {
  80. local STR=$1$2
  81. local zero='%([BSUbfksu]|([FB]|){*})'
  82. local LENGTH=${#${(S%%)STR//$~zero/}}
  83. local SPACES=""
  84. (( LENGTH = ${COLUMNS} - $LENGTH - 1))
  85. for i in {0..$LENGTH}
  86. do
  87. SPACES="$SPACES "
  88. done
  89. echo $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