-
Notifications
You must be signed in to change notification settings - Fork 31
/
prompt_powerline_setup
185 lines (152 loc) · 5.67 KB
/
prompt_powerline_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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#
# A ZSH theme based on a combination of the skwp prezto theme and the robl ohmyzsh theme.
# * RVM info shown on the right
# * Git branch info on the left
# * Single line prompt
# * Time since last commit on the left
# * Time in place of user@hostname
#
# Authors:
# David Rice <[email protected]>
ZSH_THEME_REP_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}"
ZSH_THEME_REP_TIME_SINCE_COMMIT_MEDIUM="%{$fg[yellow]%}"
ZSH_THEME_REP_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
ZSH_THEME_REP_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
# returns the time since last git commit
git_time_details()() {
# only proceed if there is actually a git repository
if $(git rev-parse --git-dir > /dev/null 2>&1); then
# only proceed if there is actually a commit
if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
# get the last commit hash
# lc_hash=$(git log --pretty=format:'%h' -1 2> /dev/null)
# get the last commit time
lc_time=$(git log --pretty=format:'%at' -1 2> /dev/null)
now=$(date +%s)
seconds_since_last_commit=$((now-lc_time))
lc_time_since=$(time_since_commit $seconds_since_last_commit)
echo "$lc_time_since"
else
echo ""
fi
else
echo ""
fi
}
# returns the time by given seconds
time_since_commit()() {
seconds_since_last_commit=$(($1 + 0))
# totals
MINUTES=$((seconds_since_last_commit / 60))
HOURS=$((seconds_since_last_commit/3600))
# sub-hours and sub-minutes
DAYS=$((seconds_since_last_commit / 86400))
SUB_HOURS=$((HOURS % 24))
SUB_MINUTES=$((MINUTES % 60))
if [ "$HOURS" -gt 24 ]; then
echo "${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m"
elif [ "$MINUTES" -gt 60 ]; then
echo "${HOURS}h${SUB_MINUTES}m"
else
echo "${MINUTES}m"
fi
}
rvm_info_for_prompt() {
if [[ -d ~/.rvm/ ]]; then
local ruby_version=$(~/.rvm/bin/rvm-prompt)
if [ -n "$ruby_version" ]; then
echo "$ruby_version"
fi
else
echo ""
fi
}
prompt_powerline_precmd() {
# Check for untracked files or updated submodules since vcs_info doesn't.
if [[ ! -z $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
fmt_branch="%b%u%c${__PROMPT_SKWP_COLORS[4]}●%f"
else
fmt_branch="%b%u%c"
fi
zstyle ':vcs_info:*:prompt:*' formats "${fmt_branch}"
vcs_info 'prompt'
RVM_PRECMD_INFO=$(rvm_info_for_prompt)
# zstyle ':prezto:module:ruby' rvm '%r'
}
prompt_powerline_setup() {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
prompt_opts=(cr percent subst)
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
add-zsh-hook precmd prompt_powerline_precmd
# Use extended color pallete if available.
if [[ $TERM = *256color* || $TERM = *rxvt* ]]; then
__PROMPT_SKWP_COLORS=(
"%F{81}" # turquoise
"%F{166}" # orange
"%F{135}" # purple
"%F{161}" # hotpink
"%F{118}" # limegreen
)
else
__PROMPT_SKWP_COLORS=(
"%F{cyan}"
"%F{yellow}"
"%F{magenta}"
"%F{red}"
"%F{green}"
)
fi
# Enable VCS systems you use.
zstyle ':vcs_info:*' enable bzr git hg svn
# check-for-changes can be really slow.
# You should disable it if you work with large repositories.
zstyle ':vcs_info:*:prompt:*' check-for-changes true
# Formats:
# %b - branchname
# %u - unstagedstr (see below)
# %c - stagedstr (see below)
# %a - action (e.g. rebase-i)
# %R - repository path
# %S - path in the repository
# %n - user
# %m - machine hostname
# local fmt_branch="(${__PROMPT_SKWP_COLORS[1]}%b%f%u%c)"
local fmt_branch="${__PROMPT_SKWP_COLORS[2]}%b%f%u%c"
local fmt_action="${__PROMPT_SKWP_COLORS[5]}%a%f"
local fmt_unstaged="${__PROMPT_SKWP_COLORS[2]}●%f"
local fmt_staged="${__PROMPT_SKWP_COLORS[5]}●%f"
zstyle ':vcs_info:*:prompt:*' unstagedstr "${fmt_unstaged}"
zstyle ':vcs_info:*:prompt:*' stagedstr "${fmt_staged}"
zstyle ':vcs_info:*:prompt:*' actionformats "${fmt_branch}${fmt_action}"
zstyle ':vcs_info:*:prompt:*' formats "${fmt_branch}"
zstyle ':vcs_info:*:prompt:*' nvcsformats ""
# SPLIT RVM PROMPT INFO
# TODO: should assign this to local variable? somehow doesn't work correctly.
rvm_split=("${(s/@/)$(rvm_info_for_prompt)}")
# if [ "$POWERLINE_RIGHT_B" = "" ]; then
# POWERLINE_RIGHT_B=%D{%H:%M:%S}
local powerline_right_b=$rvm_split[1]
# fi
# if [ "$POWERLINE_RIGHT_A" = "" ]; then
local powerline_right_a=$rvm_split[2]
# fi
# Setup powerline style colouring
POWERLINE_COLOR_BG_GRAY=%K{240}
POWERLINE_COLOR_BG_LIGHT_GRAY=%K{240}
POWERLINE_COLOR_BG_WHITE=%K{255}
POWERLINE_COLOR_FG_GRAY=%F{240}
POWERLINE_COLOR_FG_LIGHT_GRAY=%F{240}
POWERLINE_COLOR_FG_WHITE=%F{255}
POWERLINE_SEPARATOR=$'\uE0B0'
POWERLINE_R_SEPARATOR=$'\uE0B2'
POWERLINE_LEFT_A="%K{green}%F{white} %~ %k%f%F{green}%K{blue}"$POWERLINE_SEPARATOR
POWERLINE_LEFT_B="%k%f%F{white}%K{blue} "'${vcs_info_msg_0_}'" %k%f%F{blue}%K{black}"$POWERLINE_SEPARATOR
POWERLINE_LEFT_C=" %k%f%F{white}%K{black}"'$(git_time_details)'" %k%f%F{black}"$POWERLINE_SEPARATOR"%f "
PROMPT=$POWERLINE_LEFT_A$POWERLINE_LEFT_B$POWERLINE_LEFT_C
# RPROMPT=$POWERLINE_COLOR_FG_WHITE$POWERLINE_R_SEPARATOR"%f$POWERLINE_COLOR_BG_WHITE $POWERLINE_COLOR_FG_GRAY$powerline_right_b "$POWERLINE_R_SEPARATOR"%f%k$POWERLINE_COLOR_BG_GRAY$POWERLINE_COLOR_FG_WHITE $powerline_right_a %f%k"
# RPROMPT=$POWERLINE_COLOR_FG_WHITE$POWERLINE_R_SEPARATOR"%f$POWERLINE_COLOR_BG_WHITE $POWERLINE_COLOR_FG_GRAY"'$powerline_right_b'" "$POWERLINE_R_SEPARATOR"%f%k$POWERLINE_COLOR_BG_GRAY$POWERLINE_COLOR_FG_WHITE "'$powerline_right_a'" %f%k"
RPROMPT=$POWERLINE_COLOR_FG_WHITE$POWERLINE_R_SEPARATOR"%f$POWERLINE_COLOR_BG_WHITE $POWERLINE_COLOR_FG_GRAY"'$(rvm_info_for_prompt)'" "
}
prompt_powerline_setup "$@"