-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_ps1
69 lines (63 loc) · 2.1 KB
/
.bash_ps1
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
###PS1###
if [ "$USER" = "raghav" ]; then
r="\[\033[01;38;5;52m\]r"
a="\[\033[01;38;5;124m\]a"
g="\[\033[01;38;5;196m\]g"
h="\[\033[01;38;5;202m\]h"
a2="\[\033[01;38;5;208m\]a"
v="\[\033[01;38;5;214m\]v"
_user_and_host="$r$a$g$h$a2$v"
else
_user_and_host="\[\033[01;36m\]\u"
fi
# get current branch in git repo
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo "[${BRANCH}${STAT}]"
else
echo ""
fi
}
# get current status of git repo
function parse_git_dirty {
status=`git status 2>&1 | tee`
dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
bits=''
if [ "${renamed}" == "0" ]; then
bits=">${bits}"
fi
if [ "${ahead}" == "0" ]; then
bits="*${bits}"
fi
if [ "${newfile}" == "0" ]; then
bits="+${bits}"
fi
if [ "${untracked}" == "0" ]; then
bits="?${bits}"
fi
if [ "${deleted}" == "0" ]; then
bits="x${bits}"
fi
if [ "${dirty}" == "0" ]; then
bits="!${bits}"
fi
if [ ! "${bits}" == "" ]; then
echo " ${bits}"
else
echo ""
fi
}
function nonzero_return() {
RETVAL=$?
[ $RETVAL -ne 0 ] && echo "[$RETVAL]"
}
export PS1='`if [ -n "$(jobs -p)" ]; then echo "\[\e[33m\](\j)+ "; fi`'
export PS1+="\[\e[31m\]\`nonzero_return\`\[\e[m\]\[\e[33m\][\[\e[m\]\[\e[33m\]\t\[\e[m\]\[\e[33m\]]\[\e[m\] \u:\[\e[36m\][\[\e[m\]\[\e[36m\]\w\[\e[m\]\[\e[36m\]]\[\e[m\] \[\e[32m\]\`parse_git_branch\`\[\e[m\]\n\[\e[33m\] \\$\[\e[m\] "