-
-
Notifications
You must be signed in to change notification settings - Fork 643
Expand file tree
/
Copy path.zprompt
More file actions
104 lines (92 loc) · 3.2 KB
/
Copy path.zprompt
File metadata and controls
104 lines (92 loc) · 3.2 KB
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
# Git segment for the prompt: branch name plus change markers
# (+ staged, ! unstaged, ? untracked, $ stashed).
prompt_git() {
local output line branch=''
local staged='' unstaged='' untracked='' git_status=''
# One call gets the branch + every change; fails outside a repo
output=$(git status --porcelain --branch 2>/dev/null) || return
while IFS= read -r line; do
case "${line}" in
"## No commits yet on "*) branch="${line#"## No commits yet on "}" ;;
"## HEAD (no branch)"*) branch=$(git rev-parse --short HEAD) ;;
"## "*) branch="${line#"## "}" && branch="${branch%%...*}" ;;
"??"*) untracked='?' ;;
*)
# col 1 = staged, col 2 = unstaged
[[ "${line:0:1}" != " " ]] && staged='+'
[[ "${line:1:1}" != " " ]] && unstaged='!'
;;
esac
done <<<"${output}"
git_status="${staged}${unstaged}${untracked}"
git rev-parse --verify refs/stash &>/dev/null && git_status+='$'
[[ -n "${git_status}" ]] && git_status=" [${git_status}]"
printf "%b on %b%s%s" "${white}" "${blue}" "${branch}" "${git_status}"
}
export VIRTUAL_ENV_DISABLE_PROMPT=1
prompt_venv() {
if [[ -n "$VIRTUAL_ENV" ]]; then
local venv_name
venv_name=$(basename "$VIRTUAL_ENV")
printf "\n%b(%s)\n" "${steel_blue}" "${venv_name}"
fi
}
bold=$(tput bold)
reset=$(tput sgr0)
# Exact 24-bit colors when the terminal advertises them (COLORTERM doesn't
# survive SSH, so remote sessions get the nearest 256-color values)
if [[ "${COLORTERM}" == "truecolor" || "${COLORTERM}" == "24bit" ]]; then
# hex "e47030" -> its 24-bit escape (printf %d converts each 0x pair)
color() { printf '\033[38;2;%d;%d;%dm' "0x${1:0:2}" "0x${1:2:2}" "0x${1:4:2}"; }
blue=$(color afd7ff)
steel_blue=$(color 5f87af)
green=$(color 5faf5f)
magenta=$(color b48ead)
orange=$(color e47030)
red=$(color d75f5f)
white=$(color f1f1f1)
yellow=$(color ffff87)
else
blue=$(tput setaf 153)
steel_blue=$(tput setaf 67)
green=$(tput setaf 71)
magenta=$(tput setaf 139)
orange=$(tput setaf 166)
red=$(tput setaf 167)
white=$(tput setaf 15)
yellow=$(tput setaf 228)
fi
# Red username when root
if [[ "${USER}" == "root" ]]; then
userStyle="${red}"
else
userStyle="${orange}"
fi
# Magenta hostname over SSH (distinct from the red root warning)
if [[ "${SSH_TTY}" ]]; then
hostStyle="${bold}${magenta}"
else
hostStyle="${yellow}"
fi
# Blank line before each prompt via zsh's precmd hook (runs before every
# prompt but not on redraws, so Cmd+K leaves the prompt at the top). The
# first prompt of a session skips it.
precmd() {
if [[ -n "${_prompt_seen}" ]]; then
print ''
fi
_prompt_seen=1
}
PS1="\$(prompt_venv)" # virtual environment
PS1+="%{${bold}%}" # bold for the whole prompt line
PS1+="%{${userStyle}%}%n" # username
PS1+="%{${white}%} at "
PS1+="%{${hostStyle}%}%m" # host
PS1+="%{${white}%} in "
PS1+="%{${green}%}%1~" # working directory
PS1+="\$(prompt_git)" # Git repository details
PS1+=$'\n'
PS1+="%{${white}%}› %{${reset}%}" # input marker (and reset color)
export PS1
PS2="%{${yellow}%}➜ %{${reset}%}"
export PS2