aboutsummaryrefslogtreecommitdiffstats
path: root/zsh/config/prompt.zsh
blob: 1a9776b5d20a4fc05305cfca7b935ca964c714b5 (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
autoload -Uz vcs_info

directory() {
   echo "%{$fg_bold[magenta]%}%~%{$reset_color%}"
}

current_time() {
   echo "%{$fg[white]%}[%*]"
}

return_status() {
  local LAST_EXIT_CODE=$?
  if [[ $LAST_EXIT_CODE -ne 0 ]]; then
    local EXIT_CODE_PROMPT=' '
    EXIT_CODE_PROMPT+="%{$fg_bold[red]%}$LAST_EXIT_CODE%{$reset_color%}"
    echo "$EXIT_CODE_PROMPT "
  fi
}

precmd() {
    vcs_info
    VCS_STATUS=""
    if [[ -n ${vcs_info_msg_0_} ]]; then
        STATUS=$(command git status --porcelain 2> /dev/null | tail -n1)
        if [[ -n $STATUS ]]; then
            VCS_STATUS="(%F{yellow}${vcs_info_msg_0_}%f) "
        else
            VCS_STATUS="(%F{green}${vcs_info_msg_0_}%f) "
        fi
    fi
    PROMPT='%B$(directory)%b %# %f'
    RPROMPT='$(return_status)${VCS_STATUS}$(current_time)%f'
}

zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:git*' formats "%b%u%c"
zstyle ':vcs_info:git*' actionformats "%b|%a%u%c"
zstyle ':vcs_info:*' unstagedstr ' *'
zstyle ':vcs_info:*' stagedstr ' +'

setopt prompt_subst