-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.vsrc
49 lines (44 loc) · 1.28 KB
/
.vsrc
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
__vcs_dir() {
local vcs base_dir sub_dir ref
sub_dir() {
local sub_dir
sub_dir=$(readlink "${PWD}")
sub_dir=${sub_dir#$1}
echo ${sub_dir#/}
}
git_dir() {
base_dir=$(git-rev-parse --show-cdup 2>/dev/null) || return 1
base_dir=$(readlink "$base_dir/..")
sub_dir=$(git-rev-parse --show-prefix)
sub_dir=${sub_dir%/}
ref=$(git-symbolic-ref -q HEAD || git-name-rev --name-only HEAD 2>/dev/null)
ref=${ref#refs/heads/}
vcs="git"
}
svn_dir() {
[ -d ".svn" ] || return 1
base_dir="."
while [ -d "$base_dir/../.svn" ]; do base_dir="$base_dir/.."; done
base_dir=$(readlink "$base_dir")
sub_dir=$(sub_dir "${base_dir}")
ref=$(svn info "$base_dir" | awk '/^URL/ { sub(".*/","",$0); r=$0 } /^Revision/ { sub("[^0-9]*","",$0); print r":"$0 }')
vcs="svn"
}
svn_dir ||
git_dir ||
base_dir="$PWD"
if [ -n "$vcs" ]; then
__vcs_prefix="($vcs)"
__vcs_base_dir="${base_dir/$HOME/~}"
__vcs_ref="($ref)"
# __vcs_sub_dir="${sub_dir}"
else
__vcs_prefix=''
__vcs_base_dir=''
__vcs_ref=''
# __vcs_sub_dir=''
fi
}
PROMPT_COMMAND=__vcs_dir
export PS1='\[\033k\033\\\]\[\e[0;29m\][\u \w]${__vcs_base_dir}${__vcs_ref}\$\[\e[0;39m\] '
#export PS1='\[\033k\033\\\]\[[\u \w]\e[0;30m\]${__vcs_base_dir}${__vcs_ref}\e[0;39m\]\$ '