bureau.zsh-theme 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. # ignore non git folders and hidden repos (adapted from lib/git.zsh)
  60. if ! command git rev-parse --git-dir &> /dev/null \
  61. || [[ "$(command git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then
  62. return
  63. fi
  64. # check git information
  65. local gitinfo=$(bureau_git_info)
  66. if [[ -z "$gitinfo" ]]; then
  67. return
  68. fi
  69. # quote % in git information
  70. local output="${gitinfo:gs/%/%%}"
  71. # check git status
  72. local gitstatus=$(bureau_git_status)
  73. if [[ -n "$gitstatus" ]]; then
  74. output+=" $gitstatus"
  75. fi
  76. echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${output}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
  77. }
  78. _PATH="%{$fg_bold[white]%}%~%{$reset_color%}"
  79. if [[ $EUID -eq 0 ]]; then
  80. _USERNAME="%{$fg_bold[red]%}%n"
  81. _LIBERTY="%{$fg[red]%}#"
  82. else
  83. _USERNAME="%{$fg_bold[white]%}%n"
  84. _LIBERTY="%{$fg[green]%}$"
  85. fi
  86. _USERNAME="$_USERNAME%{$reset_color%}@%m"
  87. _LIBERTY="$_LIBERTY%{$reset_color%}"
  88. get_space () {
  89. local STR=$1$2
  90. local zero='%([BSUbfksu]|([FB]|){*})'
  91. local LENGTH=${#${(S%%)STR//$~zero/}}
  92. local SPACES=$(( COLUMNS - LENGTH - ${ZLE_RPROMPT_INDENT:-1} ))
  93. (( SPACES > 0 )) || return
  94. printf ' %.0s' {1..$SPACES}
  95. }
  96. _1LEFT="$_USERNAME $_PATH"
  97. _1RIGHT="[%*]"
  98. bureau_precmd () {
  99. _1SPACES=`get_space $_1LEFT $_1RIGHT`
  100. print
  101. print -rP "$_1LEFT$_1SPACES$_1RIGHT"
  102. }
  103. setopt prompt_subst
  104. PROMPT='> $_LIBERTY '
  105. RPROMPT='$(nvm_prompt_info) $(bureau_git_prompt)'
  106. autoload -U add-zsh-hook
  107. add-zsh-hook precmd bureau_precmd