-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzsh_ps
More file actions
54 lines (43 loc) · 1.53 KB
/
zsh_ps
File metadata and controls
54 lines (43 loc) · 1.53 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
# Zsh prompt - translated from bash_ps
# Box-drawing frame with git branch, fill line, timestamp
setopt PROMPT_SUBST
# Git branch
function prompt_git_branch() {
git branch --no-color 2>/dev/null | sed -n 's/^\* //p'
}
# Error indicator (called from prompt, uses PROMPT_EXIT_STATUS set by precmd)
function prompt_error_indicator() {
[[ $PROMPT_EXIT_STATUS -ne 0 ]] && echo '%F{red}%B[%F{red}✗%F{red}%B]%F{green}%B─'
}
# Calculate fill line before each prompt
function precmd() {
# Capture exit status FIRST before any other commands
PROMPT_EXIT_STATUS=$?
local pwd_len=${#${(%):-%~}}
local git_info=$(prompt_git_branch)
local git_len=${#git_info}
local offset=38
# Account for error indicator [✗]─ when present (adds 4 chars)
[[ $PROMPT_EXIT_STATUS -ne 0 ]] && offset=$((offset + 4))
local fillsize=$((COLUMNS - offset - pwd_len - git_len))
FILL=""
while ((fillsize > 0)); do
FILL="-${FILL}"
((fillsize--))
done
}
# Build the prompt (wrapped in function to use local vars)
function _setup_prompt() {
# Colors
local lg='%F{green}%B' # light green (bold)
local pk='%F{red}%B' # pink (bold red)
local yl='%F{yellow}' # yellow
local cy='%F{cyan}' # cyan
local pr='%F{magenta}' # purple
local rs='%f%b' # reset
# User@host
local uh=$yl'%n'$lg'@'$cy'%m'
# Two-line prompt with box drawing
PROMPT=$'\n'$lg'┌─$(prompt_error_indicator)['$uh$lg']─['$pk'%~'$lg'] '$pr'$(prompt_git_branch) '$lg'${FILL} %T'$'\n'$lg'└──╼ '$rs
}
_setup_prompt