forked from stephenpaulger/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_bash_profile_prompt
70 lines (61 loc) · 1.75 KB
/
custom_bash_profile_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
# Command prompt formatting
# source this from your .bash_profile
#################################################################################
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
LIGHT_GREEN="\[\033[1;32m\]"
COLOR_NONE="\[\e[0m\]"
function parse_git_branch {
git rev-parse --git-dir &> /dev/null
git_status="$(git status 2> /dev/null)"
state=""
if [[ ${git_status} =~ "Changes to be committed:" ]]; then
state+="s"
fi
if [[ ${git_status} =~ "Changes not staged for commit:" ]]; then
state+="m"
fi
if [[ ${git_status} =~ "Untracked files:" ]]; then
state+="u"
fi
if [[ "$state" != "" ]]; then
state="${RED}["$state"]"
fi
remote_pattern="Your branch is (behind|ahead)"
diverge_pattern="Your branch and (.*) have diverged"
branch_pattern="^On branch ([^${IFS}]*)"
if [[ ${git_status} =~ ${remote_pattern} ]]; then
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
remote="${YELLOW}↑"
else
remote="${YELLOW}↓"
fi
fi
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
remote="${YELLOW}↕"
fi
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]:0:15}
echo "(${branch})${remote}${state}"
fi
}
function prompt_func() {
previous_return_value=$?;
if [ -n "${VIRTUAL_ENV:+x}" ]
then
#vdir=`basename ${VIRTUAL_ENV}`
ve="${BLUE}["${VIRTUAL_ENV##*/}"]" #`basename \` dirname ${VIRTUAL_ENV}\``]"
else
ve=""
fi
prompt="${LIGHT_GREEN}\u@\h:${ve}${BLUE}${YELLOW}\W${GREEN}$(parse_git_branch)${COLOR_NONE}"
if test $previous_return_value -eq 0
then
PS1="${prompt}➔ "
else
PS1="${prompt}${RED}➔${COLOR_NONE} "
fi
}
PROMPT_COMMAND=prompt_func