bureau.zsh-theme 3.28 KB
Newer Older
isquariel's avatar
isquariel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# oh-my-zsh Bureau Theme

### NVM

ZSH_THEME_NVM_PROMPT_PREFIX="%B⬡%b "
ZSH_THEME_NVM_PROMPT_SUFFIX=""

### Git [±master ▾●]

ZSH_THEME_GIT_PROMPT_PREFIX="[%{$fg_bold[green]%}±%{$reset_color%}%{$fg_bold[white]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}]"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}✓%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg[cyan]%}▴%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg[magenta]%}▾%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}"

bureau_git_branch () {
  ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
  ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
  echo "${ref#refs/heads/}"
}

25
bureau_git_status() {
isquariel's avatar
isquariel committed
26
  _STATUS=""
27
28
29
30

  # check status of files
  _INDEX=$(command git status --porcelain 2> /dev/null)
  if [[ -n "$_INDEX" ]]; then
31
    if $(echo "$_INDEX" | command grep -q '^[AMRD]. '); then
32
33
      _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
    fi
34
    if $(echo "$_INDEX" | command grep -q '^.[MTD] '); then
35
36
      _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
    fi
37
    if $(echo "$_INDEX" | command grep -q -E '^\?\? '); then
38
39
      _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED"
    fi
40
    if $(echo "$_INDEX" | command grep -q '^UU '); then
41
42
43
44
      _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED"
    fi
  else
    _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_CLEAN"
isquariel's avatar
isquariel committed
45
46
  fi

47
48
  # check status of local repository
  _INDEX=$(command git status --porcelain -b 2> /dev/null)
49
  if $(echo "$_INDEX" | command grep -q '^## .*ahead'); then
50
51
    _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
  fi
52
  if $(echo "$_INDEX" | command grep -q '^## .*behind'); then
53
54
    _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND"
  fi
55
  if $(echo "$_INDEX" | command grep -q '^## .*diverged'); then
56
57
58
59
60
61
62
    _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED"
  fi

  if $(command git rev-parse --verify refs/stash &> /dev/null); then
    _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STASHED"
  fi

isquariel's avatar
isquariel committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  echo $_STATUS
}

bureau_git_prompt () {
  local _branch=$(bureau_git_branch)
  local _status=$(bureau_git_status)
  local _result=""
  if [[ "${_branch}x" != "x" ]]; then
    _result="$ZSH_THEME_GIT_PROMPT_PREFIX$_branch"
    if [[ "${_status}x" != "x" ]]; then
      _result="$_result $_status"
    fi
    _result="$_result$ZSH_THEME_GIT_PROMPT_SUFFIX"
  fi
  echo $_result
}


_PATH="%{$fg_bold[white]%}%~%{$reset_color%}"

83
if [[ $EUID -eq 0 ]]; then
isquariel's avatar
isquariel committed
84
85
86
87
88
89
90
91
92
93
94
95
96
  _USERNAME="%{$fg_bold[red]%}%n"
  _LIBERTY="%{$fg[red]%}#"
else
  _USERNAME="%{$fg_bold[white]%}%n"
  _LIBERTY="%{$fg[green]%}$"
fi
_USERNAME="$_USERNAME%{$reset_color%}@%m"
_LIBERTY="$_LIBERTY%{$reset_color%}"


get_space () {
  local STR=$1$2
  local zero='%([BSUbfksu]|([FB]|){*})'
97
  local LENGTH=${#${(S%%)STR//$~zero/}}
isquariel's avatar
isquariel committed
98
99
  local SPACES=""
  (( LENGTH = ${COLUMNS} - $LENGTH - 1))
100

isquariel's avatar
isquariel committed
101
102
103
104
105
106
107
108
109
110
111
112
113
  for i in {0..$LENGTH}
    do
      SPACES="$SPACES "
    done

  echo $SPACES
}

_1LEFT="$_USERNAME $_PATH"
_1RIGHT="[%*] "

bureau_precmd () {
  _1SPACES=`get_space $_1LEFT $_1RIGHT`
114
  print
115
  print -rP "$_1LEFT$_1SPACES$_1RIGHT"
isquariel's avatar
isquariel committed
116
117
118
}

setopt prompt_subst
119
PROMPT='> $_LIBERTY '
isquariel's avatar
isquariel committed
120
121
122
123
RPROMPT='$(nvm_prompt_info) $(bureau_git_prompt)'

autoload -U add-zsh-hook
add-zsh-hook precmd bureau_precmd