bureau.zsh-theme 3.1 KB

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