-
Notifications
You must be signed in to change notification settings - Fork 1
/
prompt_sprint2_setup
128 lines (102 loc) · 3.6 KB
/
prompt_sprint2_setup
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Created by Sebastian Gniazdowski
prompt_sprint2_help () {
cat <<EOF
This prompt is color themable. You can invoke it in following way:
prompt sprint2 <time/line color> <braces clr.> <text clr.> <at/colon clr.> <prompt clr.>
You can provide only N first arguments, N=1..5.
The default colors are: yellow red cyan yellow green
EOF
}
prompt_sprint2_setup () {
local col_time_line=${1:-'yellow'}
local col_parens=${2:-'red'}
local col_text=${3:-'cyan'}
local col_at_colon=${4:-'yellow'}
local col_prompt=${5:-'green'}
autoload -Uz vcs_info
typeset -gA _psvar
local cl_time_line="%B%F{$col_time_line}"
local cl_text="%b%F{$col_text}"
local cl_parens="%B%F{$col_parens}"
local cl_at_colon="%b%F{$col_at_colon}"
local cl_prompt="%B%F{$col_prompt}"
local cl_rst="%b%f"
local _lpar="${cl_parens}["
local _rpar="${cl_parens}]"
local _time="$cl_time_line%D{%H:%M}"
_psvar[user]='%n'
local _user="$cl_text"'${_psvar[user]}'
_psvar[at]="@"
_psvar[host]='%m'
local _at="$cl_at_colon"'${_psvar[at]}'"$cl_text"'${_psvar[host]}'
_psvar[colon]=':'
local _path="$cl_at_colon"'${_psvar[colon]}'"$cl_text%28<*<%/%<<"
local _line="$cl_time_line%i"
local _prompt="$cl_prompt# "
# You can instantly shorten the prompt by setting PSSHORT=1
if [[ "$COLUMNS" -le 94 || "$PSSHORT" = "1" ]]; then
_psvar=()
else
_psvar[user]='%n'
_psvar[at]="@"
_psvar[host]='%m'
_psvar[colon]=':'
fi
PS1="$_time$_lpar$_user$_at$_path$_rpar$_line$_prompt$cl_rst"
PS2="$cl_parens> $cl_rst"
RPS1='${vcs_info_msg_0_}'
prompt_opts=(cr subst percent)
zstyle ':vcs_info:*' enable git svn darcs bzr hg
zstyle ':vcs_info:*' stagedstr "%F{green}●$cl_rst"
zstyle ':vcs_info:*' unstagedstr "%F{yellow}●$cl_rst"
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' formats '(%s)-[%b%u%c]-'
add-zsh-hook precmd prompt_sprint2_precmd
}
prompt_sprint2_precmd () {
setopt localoptions noxtrace noksharrays
# You can instantly shorten the prompt by setting PSSHORT=1
if [[ "$COLUMNS" -le 94 || "$PSSHORT" = "1" ]]; then
_psvar=()
else
_psvar[user]='%n'
_psvar[at]="@"
_psvar[host]='%m'
_psvar[colon]=':'
fi
local -a changed_files
changed_files=( )
git diff --quiet 2>/dev/null || changed_files=( ${(f)"$( git diff --name-only 2>/dev/null )"} )
changed_files=( $^changed_files(N) )
if [[ "${#changed_files}" -gt 0 ]]; then
local basedir
basedir="$(git rev-parse --show-toplevel)/"
changed_files=( ${(f)"$( find "${basedir}${^changed_files[@]}" -mtime +2 )"} )
fi
if [[ "${#changed_files}" -eq 0 ]]; then
zstyle ':vcs_info:*' formats ' (%s)-[%b%u%c]'
else
zstyle ':vcs_info:*' formats ' (%s)-[%b%u%B%F{yellow}-OLD-%c%%b%f]'
fi
vcs_info
}
prompt_sprint2_preview () {
local -a colors_time_line colors_text
colors_time_line=(red yellow green blue magenta cyan)
colors_text=(red yellow green blue magenta cyan)
local ctime_line ctext i j
if (( ! $#* )); then
for (( i = 1; i <= ${#colors_time_line}; i++ )); do
ctime_line="${colors_time_line[$i]}"
for (( j = 1; j <= ${#colors_text}; j++ )); do
ctext="${colors_text[$j]}"
prompt_preview_theme sprint2 "$ctime_line" "red" "$ctext"
(( i != ${#colors_time_line} || j != ${#colors_text} )) && print
done
done
else
prompt_preview_theme sprint2 "$@"
fi
}
prompt_sprint2_setup "$@"
# vim:ft=zsh