aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/zsh/09-prompt.zsh
blob: ca892c3eba6f22e1669c421aa14cf315782acd5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#                 ██      
#                ░██      
#  ██████  ██████░██      
# ░░░░██  ██░░░░ ░██████  
#    ██  ░░█████ ░██░░░██ 
#   ██    ░░░░░██░██  ░██ 
#  ██████ ██████ ░██  ░██ 
# ░░░░░░ ░░░░░░  ░░   ░░  
#
#  ▓▓▓▓▓▓▓▓▓▓
# ░▓ author ▓ xero <x@xero.nu>
# ░▓ code   ▓ http://code.xero.nu/dotfiles
# ░▓ mirror ▓ http://git.io/.files
# ░▓▓▓▓▓▓▓▓▓▓
# ░░░░░░░░░░
autoload -U compinit colors zcalc
compinit -d
colors

ICO_DIRTY="⚡"
#ICO_DIRTY="↯"
#ICO_DIRTY="*"
ICO_AHEAD="↑"
#ICO_AHEAD="🠙"
#ICO_AHEAD="▲"
ICO_BEHIND="↓"
#ICO_BEHIND="🠛"
#ICO_BEHIND="▼"
ICO_DIVERGED="⥮"
COLOR_ROOT="%F{red}"
COLOR_USER="%F{527}"
COLOR_NORMAL="%F{527}"
PROMPT_STYLE="classic"
# Modify the colors and symbols in these variables as desired.
GIT_PROMPT_SYMBOL="%F{blue}±"                              # plus/minus     - clean repo
GIT_PROMPT_PREFIX="%F{green} %F{527}"
GIT_PROMPT_SUFFIX="%F{green}%F{527}"
GIT_PROMPT_AHEAD="%F{red}ANUM%F{527}"             # A"NUM"         - ahead by "NUM" commits
GIT_PROMPT_BEHIND="%F{white}BNUM%F{527}"           # B"NUM"         - behind by "NUM" commits
GIT_PROMPT_MERGING="%F{magenta}⚡%F{527}"     # lightning bolt - merge conflict
GIT_PROMPT_UNTRACKED="%F{red}●%F{527}"       # red circle     - untracked files
GIT_PROMPT_MODIFIED="%F{yellow}●%F{527}"     # yellow circle  - tracked files modified
GIT_PROMPT_STAGED="%F{green}●%F{527}"        # green circle   - staged changes present = ready for "git push"

parse_git_branch() {
  # Show Git branch/tag, or name-rev if on detached head
  ( git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD ) 2> /dev/null
}

parse_git_state() {
  # Show different symbols as appropriate for various Git repository states
  # Compose this value via multiple conditional appends.
  local GIT_STATE=""
  local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
  if [ "$NUM_AHEAD" -gt 0 ]; then
    GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD}
  fi
  local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
  if [ "$NUM_BEHIND" -gt 0 ]; then
    GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND}
  fi
  local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)"
  if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then
    GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING
  fi
  if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
    GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED
  fi
  if ! git diff --quiet 2> /dev/null; then
    GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED
  fi
  if ! git diff --cached --quiet 2> /dev/null; then
    GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED
  fi
  if [[ -n $GIT_STATE ]]; then
    echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX"
  fi
}


#█▓▒░ allow functions in the prompt
setopt PROMPT_SUBST
autoload -Uz colors && colors

#█▓▒░ colors for permissions
if [[ "$EUID" -ne "0" ]]
then  # if user is not root
	USER_LEVEL="${COLOR_USER}"
else # root!
	USER_LEVEL="${COLOR_ROOT}"
fi

git_prompt_string() {
  local git_where="$(parse_git_branch)"
  
  # If inside a Git repository, print its branch and state
  [ -n "$git_where" ] && echo "[$GIT_PROMPT_SYMBOL$(parse_git_state)$GIT_PROMPT_PREFIX%F{yellow}${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX%F{527}]─"
  
  # If not inside the Git repo, print exit codes of last command (only if it failed)
  #[ ! -n "$git_where" ] && echo "%F{red}%(?..%?)"
}


function error() {
    echo "%(?..[%F{red}%?%F{527}]─)"
}

function host() {
    if [[ -n $SSH_CONNECTION ]]; then
        echo "%F{red}!%F{527}$HOST"
    else
        echo "$HOST"
    fi
}

PROMPT='${COLOR_NORMAL}┌─[${USER_LEVEL}${USER}@$(host)]─$(git_prompt_string)$(error)[%~]
└─ - %f'
setfont lat0-08