-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zsh-prompt
94 lines (75 loc) · 2.66 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
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
# -*- shell-script -*-
autoload -Uz colors && colors
TERM=xterm-256color
promptlen() {
# http://stackoverflow.com/questions/10564314/
local zero='%([BSUbfksu]|([FBK]|){*})';
local plain=${(S%%)1//$~zero/};
echo ${#plain};
}
strrep() { printf "$1%.0s" {1..$2}; }
# override to perform command for each new line in shell
prompt_hook() { ; }
git-dir-is-dirty() { test $(git diff --shortstat 2>>/dev/null | wc -l) != 0; }
# https://gist.github.com/msabramo/2355834
git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$ZSH_THEME_GIT_PROMPT_SUFFIX";
}
get_prompt() {
# inspired by Ayatoli's prompt (ayozone.org)
# ,-----------,
# | VARIABLES |
# '-----------'
local error="$?";
# $PROMPT_ADJUST variable reduces prompt length
local promptadjust=${PROMPT_ADJUST:-0};
local cols="${4:-$COLUMNS}";
local left_width=$((cols - promptadjust));
local FG1="%F{$1}";
local FG2="%F{$2}";
local FG3="%F{$3}";
local FG4="%F{$2}"; # specialized for git repos
local FGnumber="%F{047}";
local FGtick="%F{047}";
local FGcross="%F{202}";
local FGdirty="%F{009}";
local FGclean="%F{047}";
if `git-dir-is-dirty`; then
FG4="$FGdirty";
elif [[ -d .git ]]; then
FG4="$FGclean";
fi
local datestr="$(date '+%H:%M, %a %d %b %y')";
local datestrlen=`promptlen "$datestr"`;
local dirstr="${PWD/$HOME/~}";
# ,--------,
# | LINE 1 |
# '--------'
maxlen=$((left_width - 40));
local dirstr_adj="${dirstr: -$maxlen:$maxlen}";
local left_col="$FG4┏━$FG2❰$FG1$datestr$FG2❱━❰$FG1$dirstr_adj$FG2❱━";
if (( error > 0 )); then
local left_error_suffix="━━━❰ ${FGcross}✗ error: $error $FG2❱━";
else
local left_error_suffix="━━━❰ ${FGtick}✔ $FG2❱━";
fi
# 18 chars (error) or 9 chars (no error)
local left_len=`promptlen $left_col$left_error_suffix`;
local left_padding=`strrep '━' $((left_width - left_len - 1))`
# local left_padded="$left${left_padding}┫";
local left_col_padded="$left_col$left_error_suffix${left_padding}┫";
# (28 + 18 + 1 =) 47 chars + padding
# ,--------,
# | LINE 2 |
# '--------'
# %{...%nG%} tells the shell that ... is n chars long
local left2_col="$FG4%{┗━$FG2❰$FGnumber%3G%}%!$FG2%{❱━❱❱%4G%}";
# ,------,
# | MAIN |
# '------'
eval "$prompt_hook";
printf "%s\n%s" "$left_col_padded" "$left2_col %{$reset_color%}";
}
setopt prompt_subst
PROMPT="\$(get_prompt 111 011 047)";