-
Notifications
You must be signed in to change notification settings - Fork 1
/
prompt
36 lines (26 loc) · 1.22 KB
/
prompt
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
setopt prompt_percent
# (git info pwd) on rprompt
function update_rprompt() {
local PROMPT_CWD_INFO=
[[ "${PWD/#$HOME/~}" =~ '^~/?$' ]] || PROMPT_CWD_INFO="%F{green}%30<..<%~"
local PROMPT_GIT_INFO=
# TODO: change colors depending on the index status
git branch &>/dev/null && PROMPT_GIT_INFO="%F{cyan}${$(git symbolic-ref HEAD 2>/dev/null)##*/} $(git rev-parse --short HEAD 2>/dev/null)"
RPROMPT=
[[ -z "${PROMPT_GIT_INFO}" && -z "${PROMPT_CWD_INFO}" ]] && return
[[ ! -z "${PROMPT_GIT_INFO}" ]] && RPROMPT="${PROMPT_GIT_INFO}"
[[ ! -z "${PROMPT_CWD_INFO}" ]] && RPROMPT="${PROMPT_CWD_INFO}"
[[ ! -z "${PROMPT_GIT_INFO}" && ! -z "${PROMPT_CWD_INFO}" ]] && RPROMPT="${PROMPT_GIT_INFO} ${PROMPT_CWD_INFO}"
RPROMPT="%F{white}(${RPROMPT}%F{white})%F{default}"
}
PROMPT="%F{white}[%F{yellow}%D{%H:%M:%S}%F{white}|%F{yellow}%h%F{white}]%(?. .%F{red}%?)%F{white}(%F{green}%n%F{white}@%F{cyan}%m%F{white})%F{blue}%#%F{default} "
function update_window_title() {
printf "\e]1;zsh\a\e]2;%s\a" "${PWD/#$HOME/~}"
[[ $(fc -ln -- -1 2>/dev/null) =~ '^git' ]] && update_rprompt
}
precmd_functions+=( update_window_title )
chpwd_functions+=( update_rprompt )
#execute each once on start
update_window_title
update_rprompt
# vim: syntax=sh: