-
Notifications
You must be signed in to change notification settings - Fork 0
/
.ps1_vcs
executable file
·151 lines (129 loc) · 6.07 KB
/
.ps1_vcs
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
# This code was auto generated by with these options:
# http://andrewray.me/bash-prompt-builder/index.html#git=1&color-git=3&color-git-prefix=3&git-ahead=1&color-git-ahead=6b&git-modified=1&color-git-modified=3&git-conflicted=1&color-git-conflicted=1&color-git-revno=3&git-bisect=1&color-git-bisect=5&option-submodule=1&color-option-submodule=5&git-ontag=1&color-git-ontag=3b&hg=1&color-hg=5&hg-prefix=1&color-hg-prefix=5&hg-modified=1&color-hg-modified=5&hg-conflicted=1&color-hg-conflicted=1&color-hg-revno=5&hg-bisect=1&color-hg-bisect=3&hg-patches=1&color-hg-patches=3&svn=1&color-svn=6&svn-modified=1&color-svn-modified=6&svn-revno=1&color-svn-revno=6&option-modified=%E2%96%B3&option-conflict=%E2%98%A2&color-option-conflict=1b&max-conflicted-files=2&option-nobranch=no%20branch&color-option-nobranch=1&bisecting-text=bisect&submodule-text=%5Bsubmod%5D%20
MAX_CONFLICTED_FILES=2
DELTA_CHAR="△"
CONFLICT_CHAR="▼"
BISECTING_TEXT="bisect"
NOBRANCH_TEXT="no branch"
REBASE_TEXT="rebase"
SUBMODULE_TEXT="[submod] "
# Colors for prompt
COLOR_RED=$(tput sgr0 && tput setaf 1)
COLOR_GREEN=$(tput sgr0 && tput setaf 2)
COLOR_YELLOW=$(tput sgr0 && tput setaf 3)
COLOR_BLUE=$(tput sgr0 && tput setaf 4)
COLOR_MAGENTA=$(tput sgr0 && tput setaf 5)
COLOR_CYAN=$(tput sgr0 && tput setaf 6)
COLOR_GRAY=$(tput sgr0 && tput setaf 7)
COLOR_WHITE=$(tput sgr0 && tput setaf 7 )
COLOR_LIGHTRED=$(tput sgr0 && tput setaf 196)
COLOR_LIGHTGREEN=$(tput sgr0 && tput setaf 118)
COLOR_LIGHTYELLOW=$(tput sgr0 && tput setaf 226)
COLOR_LIGHTBLUE=$(tput sgr0 && tput setaf 033)
COLOR_LIGHTMAGENTA=$(tput sgr0 && tput setaf 201)
COLOR_LIGHTCYAN=$(tput sgr0 && tput setaf 51)
COLOR_REVERSE=$(tput rev)
COLOR_RESET=$(tput sgr0)
_git_dir=""
_git_svn_dir=""
function _git_check {
_git_dir=`git rev-parse --show-toplevel 2> /dev/null`
if [[ "$_git_dir" == "" ]]; then
return 1
else
_gsvn_check=`cd "$_git_dir"; ls .git/svn/.metadata 2> /dev/null`
if [[ ! -z "$_gsvn_check" ]]; then
_git_svn_dir=$_git_dir
fi
return 0
fi
}
function is_submodule() {
local parent_git=`cd "$_git_dir/.." && git rev-parse --show-toplevel 2> /dev/null`
if [[ -n $parent_git ]]; then
local submodules=`cd "$parent_git" && git submodule --quiet foreach 'echo $path'`
for line in $submodules; do
cd "$parent_git/$line"
if [[ `pwd` = $_git_dir ]]; then return 0; fi
done
fi
return 1
}
dvcs_function="
# Figure out what repo we are in
_git_check
# Build the prompt!
prompt=\"\"
# If we are in git ...
if [ -n \"\$_git_dir\" ]; then
# find current branch
gitBranch=\$(git symbolic-ref HEAD 2> /dev/null)\
gitStatus=\$(git status)
# Figure out if we are rebasing
if [[ -d \"\$_git_dir/.git/rebase-apply\" || -d \"\$_git_dir/.git/rebase-merge\" ]]; then
is_rebase=1
fi
# Figure out current branch, or if we are bisecting, or lost in space
bisecting=\"\"
if [ -z \"\$gitBranch\" ]; then
if [ -n \"\$is_rebase\" ]; then
rebase_prompt=\" \\[\$COLOR_LIGHT_CYAN\\]\"
rebase_prompt=\$rebase_prompt\"\\[`tput sc`\\] \\[`tput rc`\\]\\[\$REBASE_TEXT\\] \"
rebase_prompt=\$rebase_prompt\"\\[\$COLOR_LIGHTYELLOW\\]\"
else
bisect=\$(git rev-list --bisect 2> /dev/null | cut -c1-7)
if [ -z \"\$bisect\" ]; then
gitBranch=\"\\[\$COLOR_LIGHTBLUE\\]\$NOBRANCH_TEXT\\[\$COLOR_LIGHTYELLOW\\]\"
else
bisecting=\"\\[\$COLOR_LIGHTMAGENTA\\]\$BISECTING_TEXT:\"\$bisect\"\\[\$COLOR_LIGHTYELLOW\\]\"
gitBranch=\"\"
fi
fi
fi
gitBranch=\${gitBranch#refs/heads/}
#: git-svn
if [ -z \"\$bisect\" ]; then
if [ -n \"\$_git_svn_dir\" ]; then
gitBranch=\"\\[\$COLOR_LIGHTBLUE\\]git-svn\\[\$COLOR_LIGHTYELLOW\\] \$gitBranch \"
fi
fi
if [ -z \"\$is_rebase\" ]; then
# changed *tracked* files in local directory?
gitChange=\$(echo \"\$gitStatus\" | grep 'modified:\|deleted:\|new file:')
if [ -n \"\$gitChange\" ]; then
gitChange=\" \\[`tput sc`\\]\\[`tput rc`\\]\\[\$COLOR_LIGHTYELLOW\\]\\[\$DELTA_CHAR\\] \"
fi
fi
# output the branch and changed character if present
prompt=\$prompt\"\\[\$COLOR_GREEN\\] \"
if is_submodule; then
prompt=\$prompt\"\\[\$COLOR_LIGHTBLUE\\]\$SUBMODULE_TEXT\\[\$COLOR_LIGHTYELLOW\\]\"
fi
prompt=\$prompt\$gitBranch\$bisecting
tag=\$(gtags)
if [ -n \"\$tag\" ]; then
prompt=\"\$prompt \\[\$COLOR_LIGHTYELLOW\\]\$tag\\[\$COLOR_LIGHTYELLOW\\]\"
fi
prompt=\$prompt\"\$gitChange\\[\$COLOR_RESET\\]\"
# How many local commits do you have ahead of origin?
# Need to quote 'gitStatus' for echo to output the newlines.
# Git status output sometimes appears with preceding '#':
# '# Your branch is ahead of 'origin/master' by 2 commits.'
# 'Your branch is ahead of 'origin/master' by 1 commit.'
# Don't know why.
num=\$(echo \"\$gitStatus\" | grep \"Your branch is ahead of\" | sed -E 's/.+by (.+) commit.+/\1/' ) || return
if [ -n \"\$num\" ]; then
prompt=\$prompt\"\\[\$COLOR_LIGHTBLUE\\]+\$num\"
fi
# any conflicts? (sed madness is to remove line breaks)
files=\$(git ls-files -u | cut -f 2 | sort -u | sed '$(($MAX_CONFLICTED_FILES+1)),1000d' | sed -e :a -e '\$!N;s/\\\n/, /;ta' -e 'P;D')
fi
# Show conflicted files if any
if [ -n \"\$files\" ]; then
prompt=\$prompt\" \\[\$COLOR_RED\\](\\[\$COLOR_LIGHTYELLOW\\]\"
prompt=\$prompt\"\\[`tput sc`\\] \\[`tput rc`\\]\\[\$COLOR_LIGHTRED\\]\\[\$CONFLICT_CHAR\\] \"
prompt=\$prompt\"\\[\$COLOR_RED\\] \${files})\"
fi
echo -e \$prompt"
# End code auto generated by http://andrewray.me/bash-prompt-builder/index.html
PS1="\$(${dvcs_function})\[$COLOR_RESET\] \$ "