-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zsh.prompt
210 lines (176 loc) · 6.37 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
autoload -Uz vcs_info
zstyle ':vcs_info:*' disable bzr cdv cvs darcs mtn tla hg p4 svk
zstyle ':vcs_info:*' enable cvs svn git
# show symbol
function +vi-symbol() {
case ${hook_com[vcs_orig]} in
"git") hook_com[vcs]="±" ;;
"cvs") hook_com[vcs]="❌" ;;
"svn") hook_com[vcs]="®" ;;
"git-svn") hook_com[vcs]="±®" ;;
esac
}
# show local repository name
function +vi-git-localname() {
local old_base_name="${hook_com[base-name]}"
local new_base_name="${REPOSITORIES[$old_base_name]}"
if [[ -n "${new_base_name}" ]] ; then
hook_com[base-name]="${new_base_name}"
else
hook_com[base-name]="${old_base_name}"
fi
}
if which starship > /dev/null ; then
unset RPROMPT
eval "$(starship init zsh)"
zstyle ':vcs_info:git+set-message:*' hooks symbol git-localname
zstyle ':vcs_info:*' formats "[%s%b%m%c%u]" "%s%r"
vcs_stuff() { vcs_info }
else
# note that you'll also need to "setopt prompt_subst", as below
### git: Show +N/-N when your local branch is ahead-of or behind remote HEAD.
function +vi-git-st() {
local ahead behind
local -a gitstatus
# for git prior to 1.7
# ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
(( $ahead )) && gitstatus+=( "(↑${ahead})" )
# for git prior to 1.7
# behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l)
behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
(( $behind )) && gitstatus+=( "(↓${behind})" )
hook_com[misc]+=${(j:/:)gitstatus}
}
### git: stashes present?
function +vi-git-stash() {
local stashed
stashed=$(git stash list | wc -l)
(( $stashed )) && hook_com[misc]+="%{${fg_bold[white]}%}⚑%{${fg_no_bold[default]}%} "
}
### git: show remote branch name for remote-tracking branches
function +vi-git-remotebranch() {
local remote
# Are we on a remote-tracking branch?
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
--symbolic-full-name 2>/dev/null)/refs\/remotes\/}
if [[ -n "${remote}" ]] && [[ ! $remote =~ "(origin|salsa|salsa-freexian)/${hook_com[branch]/+/\+}" ]] && [[ ! $remote =~ refs/heads ]] ; then
hook_com[branch]="${hook_com[branch]}→${remote}"
fi
}
function +vi-git-untracked() {
blacklisted-vcs-dir && return 0
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]] ; then
hook_com[unstaged]+="%{${fg_bold[yellow]}%}!%{${fg_no_bold[default]}%}"
fi
}
function blacklisted-vcs-dir() {
local d
local -a blacklisted_dirs
blacklisted_dirs=( "dd-wrt/src" "dd-wrt/firmware-mod-kit" "src/router" "kernel" "dd-wrt-github" "openwrt-github" "vcs/linux")
for d in ${blacklisted_dirs}; do
[[ ${PWD}/ == */${d}/* ]] && return 0
done
return 1
}
zstyle -e ':vcs_info:*' check-for-changes 'blacklisted-vcs-dir && reply=(false) || reply=(true)'
zstyle ':vcs_info:*' stagedstr "%{${fg_bold[yellow]}%}↺%{${fg_no_bold[default]}%}"
zstyle ':vcs_info:*' unstagedstr "%{${fg_bold[yellow]}%}↯%{${fg_no_bold[default]}%}"
zstyle ':vcs_info:*' formats "[%s%b%m%c%u]" "%s%r"
zstyle ':vcs_info:*' actionformats "[%s%b %m|%a%c%u]" "%s%r"
zstyle ':vcs_info:svn*+set-message:*' hooks symbol
zstyle ':vcs_info:cvs*+set-message:*' hooks symbol
zstyle ':vcs_info:git-svn+set-message:*' hooks symbol git-st git-untracked git-localname git-stash
zstyle ':vcs_info:git+set-message:*' hooks symbol git-st git-untracked git-remotebranch git-localname git-stash
vcs_stuff() {
vcs_info
if [[ -n $vcs_info_msg_0_ ]] ; then
PSEXTRA="%{${fg_bold[magenta]}%}${vcs_info_msg_0_}%{${fg_no_bold[default]}%} "
else
unset PSEXTRA
fi
}
local terminalColors=$(echotc Co)
if [[ $? == 0 ]] && [[ $terminalColors == 256 ]] ; then
usernameColor=237
hostColor=white
else # default for older terminals
usernameColor=grey
hostColor=cyan
fi
PROMPT=$'${PSEXTRA}%F{green}%80<...<%~%f%(1j.%F{cyan} %j&%f.) %F{33}${elapsed_str}%f%(?..%B%F{red} %??%b%f) # '
if [[ "$EUID" == 0 ]] ; then
RPROMPT="%S${RPROMPT}%s"
else
RPROMPT=$'[%B%F{'${usernameColor}'}%n%f%b %B%U%F{'${hostColor}'}'${hostnicks[$HOST_SHORT]:-$HOST_SHORT}$'%f%u%b]'
fi
precmd_elapsed() {
# REPORTTIME=10
local elapsed=$(( SECONDS - cmd_start_ts ))
elapsed_str=$(printf "%02d:%02d" $(( ${elapsed} / 60 )) $(( ${elapsed} % 60 )))
}
precmd_functions+=(precmd_elapsed)
fi
getTmuxWindowIndex() {
local windowShortcuts=(0 1 2 3 4 5 6 7 8 9 j k l a b)
let index="$(tmux display-message -p '#{window_index}') + 1"
if [ "$index" -gt 10 ] ; then
echo $windowShortcuts[$index]
fi
}
case $TERM in
rxvt*|xterm*|alacritty)
TITLE_ESCAPE_BEGIN="\e]0;"
TITLE_ESCAPE_END="\a" ;;
sun*|vt*|screen*|tmux*|linux)
TITLE_ESCAPE_BEGIN="\ek"
TITLE_ESCAPE_END="\e\\" ;;
esac
_setTerminalTitle() {
print -Pn "${TITLE_ESCAPE_BEGIN}${1}${TITLE_ESCAPE_END}"
}
setTerminalTitle() {
# setopt localoptions xtrace
case $TERM in
rxvt*|xterm*|screen*|tmux*|alacritty)
local cmd="$1"
if env | grep -q TMUX= ; then
terminalTitle="$(getTmuxWindowIndex):"
else
terminalTitle="_:"
fi
if [[ $HOST_SHORT != $(hostname -s) ]] || [[ -z "$STY$TMUX" ]] ; then
terminalTitle="$terminalTitle@${hostnicks[$HOST_SHORT]:-$HOST_SHORT}"
else
if [[ -n "${vcs_info_msg_1_}" ]] ; then
terminalTitle="${terminalTitle}${vcs_info_msg_1_}"
fi
if [[ -n "${cmd}" ]] ; then
terminalTitle="${terminalTitle}|${cmd}"
fi
fi
if [[ $TERM != (screen|tmux)* ]] ; then
terminalTitle="${TERM_TITLE_PREFIX}${hostnicks[$HOST_SHORT]:-$HOST_SHORT}${TERM_TITLE_SUFFIX}"
fi
[[ -z $terminalTitle ]] && terminalTitle=" "
_setTerminalTitle "$terminalTitle"
esac
}
precmd_vcs() {
vcs_stuff 2> /dev/null
}
precmd_functions+=(precmd_vcs)
if [[ -z "$is_console" ]] ; then
precmd_window_title() {
# those 2 are only set once, by sc(), to add the tmux/screen session
# name; when detaching, they need to be reset
unset TERM_TITLE_PREFIX
unset TERM_TITLE_SUFFIX
# just strip previous title from cmd marker
terminalTitle=${terminalTitle/\|*}
_setTerminalTitle "$terminalTitle"
}
precmd_functions+=(precmd_window_title)
else
setTerminalTitle() { : }
fi