-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzsh_prompt
61 lines (49 loc) · 1.59 KB
/
zsh_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
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
YELLOW="%b%F{yellow}"
WHITE="%b%F{white}"
BGREEN="%B%F{green}"
BCYAN="%B%F{cyan}"
BRED="%B%F{red}"
RESET="%b%f"
function prompt_clock() {
echo "${WHITE}$(date +'%R')"
}
function prompt_pwd() {
echo "${YELLOW}${PWD/$HOME/~}"
}
function prompt_git() {
ref=$(git symbolic-ref HEAD 2> /dev/null || git rev-parse --short HEAD 2> /dev/null) || return 0
dirty=$([[ -n "$(git status --porcelain | tail -n1)" ]] && echo " X")
echo "${BCYAN}git:(${BRED}${ref#refs/heads/}${YELLOW}${dirty}${BCYAN})"
}
function prompt_aws() {
profile=$(export | grep AWS_PROFILE) || return 0
echo "${BCYAN}aws:(${BRED}${AWS_PROFILE}${BCYAN})"
}
function prompt_kube() {
ctx=$(kubectl config current-context 2> /dev/null) || return 0
ns=$(kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null)
echo "${BCYAN}k8s:(${BRED}${ctx##*:cluster/}${WHITE}:${BGREEN}${ns:-default}${BCYAN})"
}
function prompt_prompt() {
echo "%(?.${BGREEN}.${BRED})>${RESET} "
}
function prompt_length() {
expanded_prompt=$(echo -n $1 | sed -r 's/(%b|%B|%F\{[^}]+}|%\([^)]+\))//g')
echo ${#expanded_prompt}
}
function build_prompt() {
git=$(prompt_git)
aws=$(prompt_aws)
kube=$(prompt_kube)
prompt_first="$(prompt_clock) $(prompt_pwd)"
prompt_last="${git:+$git }${aws:+$aws }${kube:+$kube }"
prompt_sep=" "
# if too large use multi line
if [ $(prompt_length "${prompt_first}${prompt_sep}${prompt_last}") -gt $(tput cols) ]; then
prompt_sep="\n"
fi
echo "${prompt_first}${prompt_sep}${prompt_last}\n$(prompt_prompt)"
}
PROMPT='
$(build_prompt)'
RPROMPT=''