bureau.zsh-theme 3.6 KB

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