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