]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/themes/bureau.zsh-theme
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / themes / bureau.zsh-theme
1 # oh-my-zsh Bureau Theme
2
3 ### NVM
4
5 ZSH_THEME_NVM_PROMPT_PREFIX="%B⬡%b "
6 ZSH_THEME_NVM_PROMPT_SUFFIX=""
7
8 ### Git [±master ▾●]
9
10 ZSH_THEME_GIT_PROMPT_PREFIX="[%{$fg_bold[green]%}±%{$reset_color%}%{$fg_bold[white]%}"
11 ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}]"
12 ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}✓%{$reset_color%}"
13 ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg[cyan]%}▴%{$reset_color%}"
14 ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg[magenta]%}▾%{$reset_color%}"
15 ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}"
16 ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}●%{$reset_color%}"
17 ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}"
18
19 bureau_git_info () {
20   local ref
21   ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
22   ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
23   echo "${ref#refs/heads/}"
24 }
25
26 bureau_git_status() {
27   local result gitstatus
28   gitstatus="$(command git status --porcelain -b 2>/dev/null)"
29
30   # check status of files
31   local gitfiles="$(tail -n +2 <<< "$gitstatus")"
32   if [[ -n "$gitfiles" ]]; then
33     if [[ "$gitfiles" =~ $'(^|\n)[AMRD]. ' ]]; then
34       result+="$ZSH_THEME_GIT_PROMPT_STAGED"
35     fi
36     if [[ "$gitfiles" =~ $'(^|\n).[MTD] ' ]]; then
37       result+="$ZSH_THEME_GIT_PROMPT_UNSTAGED"
38     fi
39     if [[ "$gitfiles" =~ $'(^|\n)\\?\\? ' ]]; then
40       result+="$ZSH_THEME_GIT_PROMPT_UNTRACKED"
41     fi
42     if [[ "$gitfiles" =~ $'(^|\n)UU ' ]]; then
43       result+="$ZSH_THEME_GIT_PROMPT_UNMERGED"
44     fi
45   else
46     result+="$ZSH_THEME_GIT_PROMPT_CLEAN"
47   fi
48
49   # check status of local repository
50   local gitbranch="$(head -n 1 <<< "$gitstatus")"
51   if [[ "$gitbranch" =~ '^## .*ahead' ]]; then
52     result+="$ZSH_THEME_GIT_PROMPT_AHEAD"
53   fi
54   if [[ "$gitbranch" =~ '^## .*behind' ]]; then
55     result+="$ZSH_THEME_GIT_PROMPT_BEHIND"
56   fi
57   if [[ "$gitbranch" =~ '^## .*diverged' ]]; then
58     result+="$ZSH_THEME_GIT_PROMPT_DIVERGED"
59   fi
60
61   # check if there are stashed changes
62   if command git rev-parse --verify refs/stash &> /dev/null; then
63     result+="$ZSH_THEME_GIT_PROMPT_STASHED"
64   fi
65
66   echo $result
67 }
68
69 bureau_git_prompt() {
70   # check git information
71   local gitinfo=$(bureau_git_info)
72   if [[ -z "$gitinfo" ]]; then
73     return
74   fi
75
76   # quote % in git information
77   local output="${gitinfo:gs/%/%%}"
78
79   # check git status
80   local gitstatus=$(bureau_git_status)
81   if [[ -n "$gitstatus" ]]; then
82     output+=" $gitstatus"
83   fi
84
85   echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${output}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
86 }
87
88
89 _PATH="%{$fg_bold[white]%}%~%{$reset_color%}"
90
91 if [[ $EUID -eq 0 ]]; then
92   _USERNAME="%{$fg_bold[red]%}%n"
93   _LIBERTY="%{$fg[red]%}#"
94 else
95   _USERNAME="%{$fg_bold[white]%}%n"
96   _LIBERTY="%{$fg[green]%}$"
97 fi
98 _USERNAME="$_USERNAME%{$reset_color%}@%m"
99 _LIBERTY="$_LIBERTY%{$reset_color%}"
100
101
102 get_space () {
103   local STR=$1$2
104   local zero='%([BSUbfksu]|([FB]|){*})'
105   local LENGTH=${#${(S%%)STR//$~zero/}}
106   local SPACES=$(( COLUMNS - LENGTH - ${ZLE_RPROMPT_INDENT:-1} ))
107
108   (( SPACES > 0 )) || return
109   printf ' %.0s' {1..$SPACES}
110 }
111
112 _1LEFT="$_USERNAME $_PATH"
113 _1RIGHT="[%*]"
114
115 bureau_precmd () {
116   _1SPACES=`get_space $_1LEFT $_1RIGHT`
117   print
118   print -rP "$_1LEFT$_1SPACES$_1RIGHT"
119 }
120
121 setopt prompt_subst
122 PROMPT='> $_LIBERTY '
123 RPROMPT='$(nvm_prompt_info) $(bureau_git_prompt)'
124
125 autoload -U add-zsh-hook
126 add-zsh-hook precmd bureau_precmd