-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprompt_scala2_setup
89 lines (70 loc) · 2.4 KB
/
prompt_scala2_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
# Created by Sebastian Gniazdowski
prompt_scala2_help () {
cat <<EOF
This prompt is themable. You can invoke it in following way:
prompt scala2 <prompt, default is ":: "> <prompt color> <path color> <vcs info color>
You can provide only N first arguments, N=1..4.
The default invocation is: ":: " cyan cyan magenta
EOF
}
prompt_scala2_setup () {
local prompt_left=${1:-':: '}
local col_left=${2:-'cyan'}
local col_path=${3:-'cyan'}
local col_vcs=${4:-'magenta'}
autoload -Uz vcs_info
typeset -gA _psvar
_psvar[col_vcs]="$col_vcs"
local cl_left="%B%F{$col_left}"
local cl_path="%b%F{$col_path}"
local cl_vcs="%B%F{$col_vcs}"
local cl_rst="%b%f"
local _left="$cl_left$prompt_left"
local _path="$cl_path%28<*<%/%<<"
local _vcs="$cl_vcs"'${vcs_info_msg_0_}'
PS1="$_left$cl_rst"
PS2="$cl_left> $cl_rst"
RPS1="$_path$_vcs$cl_rst"
prompt_opts=(cr subst percent)
zstyle ':vcs_info:*' enable git svn darcs bzr hg
zstyle ':vcs_info:*' stagedstr "%F{green}●$cl_vcs"
zstyle ':vcs_info:*' unstagedstr "%F{yellow}●$cl_vcs"
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' formats '(%s)-[%b%u%c]-'
add-zsh-hook precmd prompt_scala2_precmd
}
prompt_scala2_precmd () {
setopt localoptions noxtrace noksharrays
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%F{'"${_psvar[col_vcs]}"'}]'
fi
vcs_info
}
prompt_scala2_preview () {
local -a colors_prompt
colors_prompt=(red yellow green blue magenta cyan)
local cprompt
integer i
if (( ! $#* )); then
for (( i = 1; i <= ${#colors_prompt}; i++ )); do
cprompt="${colors_prompt[$i]}"
prompt_preview_theme scala2 ":: " "$cprompt" "$cprompt"
(( i != ${#colors_prompt} )) && print
done
else
prompt_preview_theme scala2 "$@"
fi
}
prompt_scala2_setup "$@"
# vim:ft=zsh