-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.bash_prompt
32 lines (29 loc) · 888 Bytes
/
.bash_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
parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo "$(tput setaf 4)git:($(tput sgr0)$(tput setaf 1)${BRANCH}$(tput sgr0)$(tput setaf 4))$(tput sgr0)$(tput sgr0)${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 "$?"`
ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
bits=''
if [ "${ahead}" == "0" ]; then
bits="$(tput setaf 2)↑$(tput sgr0)${bits}"
fi
if [ "${dirty}" == "0" ]; then
bits="$(tput setaf 3)✗$(tput sgr0)${bits}"
fi
if [ ! "${bits}" == "" ]; then
echo " ${bits}"
else
echo ""
fi
}
export PS1="\[\e[32m\]→\[\e[m\] \W \`parse_git_branch\`"