This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
_S67_prompt
164 lines (144 loc) · 4.12 KB
/
_S67_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
#! /bin/zsh
#
# vi-mode colour changing
# http://www.zsh.org/mla/users/2006/msg01196.html
setopt prompt_subst
autoload colors
colors
rst="%{%b%s%u$reset_color%}"
bgc="%{%(?.$rst.%S)%}"
function _lprompt_env {
local active="$(active_virtualenv)"
local enclosing="$(enclosing_virtualenv)"
if [ -z "$active" -a -z "$enclosing" ]; then
# no active virtual env, no enclosing virtualenv, just leave
return
fi
if [ -z "$active" ]; then
local color=white
local text="$enclosing"
else
if [ -z "$enclosing" ]; then
if [ -d "$VIRTUAL_ENV" ]; then
local color=yellow
local text="$active"
else
local color=magenta
local text="$active (deleted)"
fi
elif [ "$enclosing" = "$active" ]; then
local color=green
local text="$active"
else
local color=red
local text="$active":"$enclosing"
fi
fi
#local result="%{$fg[$color]%}${text}%{$rst%} "
local result="%{$fg[$color]%}${text}$rst "
echo -n $result
}
function lprompt {
local col1 col2 ch1 ch2
col1="%{%b$fg[$2]%}"
col2="%{$4$fg[$3]%}"
ch1=$col1${1[1]}
ch2=$col1${1[2]}
local _env='$(_lprompt_env)'
local col_b col_s
col_b="%{$fg[green]%}"
col_s="%{$fg[red]%}"
PROMPT="\
$bgc$ch1\
$_env\
%{$fg_bold[white]%}%m:\
$bgc$col2%B%1~%b\
$ch2$rst \
$col2%#$rst "
}
function _format_git_position {
local git_position_ahead="$(echo $_git_status_cache | head -1 | egrep -o "ahead [0-9]+" | cut -f2 -d' ')"
local git_position_behind="$(echo $_git_status_cache | head -1 | egrep -o "behind [0-9]+" | cut -f2 -d' ')"
if [ -n "$git_position_ahead" ]; then
local position=" %{$fg[green]%}+$git_position_ahead$rst"
fi
if [ -n "$git_position_behind" ]; then
if [ -z "$position" ]; then
local position=" %{$fg[red]%}-$git_position_behind$rst"
else
local position="$position%{$fg[white]%}/$rst%{$fg[red]%}-$git_position_behind$rst"
fi
fi
if [ "$(echo "$_git_status_cache" | wc -l)" -gt 1 ]; then
local position="$position %{$fg[yellow]%}!$rst"
fi
echo -n $position
}
function _rprompt_dvcs {
_git_status_cache="$(git status -sb 2> /dev/null)"
if [ -n "$_git_status_cache" ]; then
local result=":%{$fg[blue]%}$(parse_git_branch)$rst$(_format_git_position)"
unset _git_status_cache
else
local hg_branch="($(parse_hg_branch))"
if [ "()" != "$hg_branch" ]; then
local result=":%{$fg[green]%}$hg_branch$rst"
fi
fi
echo -n $result
}
function rprompt {
local col1 col2 ch1 ch2
col1="%{$fg[$2]%}"
col2="%{$4$fg[$3]%}"
ch1=$col1${1[1]}
ch2=$col1${1[2]}
local _dvcs='$(_rprompt_dvcs)'
RPROMPT="\
$rst$ch1\
$col2%*:%n\
${col1}\
$col2%B${_dvcs}%b\
$ch2$rst"
}
if [ $UID -eq 0 ]; then
PROMPT="$bgc%{%B$fg[yellow]%}[%{$fg[red]%}%n %m%{$fg[yellow]%}]$rst "
RPROMPT="$rst%{$fg[red]%}(%B%{$fg[red]%}%~%b%{$fg[red]%})$rst "
elif [ -f ~/.zsh.prompt ]; then
source ~/.zsh.prompt
else
case $HOST in
*)
lprompt '{}' green green
rprompt '()' yellow white
;;
esac
fi
unset rst bgc
case $TERM in
xterm*)
# this updates title bar before prompt is printed
precmd () { print -Pn '\033];%~\007' }
# this updates title bar while command is running
xterm-accept-line () { print -nr -- "]2;$BUFFER"; zle .accept-line; }
zle -N accept-line xterm-accept-line
;;
*)
;;
esac
# ------------------------
# PS1=$'%{\e[34;1m%}%20>..>%1~%>>>%{\e[0m%}'
#
# function zle-keymap-select {
# PS1=${${1/vicmd/$'%{\e[31;1m%}'}/(viins|main)/$'%{\e[34;1m%}'}${PS1#*%\}}
# zle reset-prompt
# }
# ------------------------
# function zle-line-init zle-keymap-select {
# RPS1="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}"
# RPS2=$RPS1
# RPS3=$RPS1
# RPS4=$RPS1
# zle reset-prompt
# }
# zle -N zle-line-init