-
Notifications
You must be signed in to change notification settings - Fork 3
/
.bash_prompt
62 lines (54 loc) · 1.96 KB
/
.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
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
prompt_function() {
local previous_return_value=$?;
local BLACK="\[\033[0;30m\]"
local RED="\[\033[0;31m\]"
local GREEN="\[\033[0;32m\]"
local YELLOW="\[\033[0;33m\]"
local BLUE="\[\033[0;34m\]"
local MAGENTA="\[\033[0;35m\]"
local CYAN="\[\033[0;36m\]"
local LIGHT_GRAY="\[\033[0;37m\]"
local LIGHT_RED="\[\033[1;31m\]"
local LIGHT_GREEN="\[\033[1;32m\]"
local LIGHT_YELLOW="\[\033[1;33m\]"
local LIGHT_BLUE="\[\033[1;34m\]"
local LIGHT_MAGENTA="\[\033[1;35m\]"
local LIGHT_CYAN="\[\033[1;36m\]"
local WHITE="\[\033[1;37m\]"
local COLOR_NONE="\[\e[0m\]"
local unclean_state="${LIGHT_YELLOW}⚡"
local changes_to_push="${LIGHT_YELLOW}↑"
local changes_to_pull="${LIGHT_YELLOW}↓"
local changes_to_push_and_pull="${LIGHT_YELLOW}↕"
local git_status="$(git status 2> /dev/null)"
local branch_pattern="#? ?On branch ([^${IFS}]*)"
local remote_pattern="#? ?Your branch is (.*) of"
local diverge_pattern="#? ?Your branch and (.*) have diverged"
if [[ ! ${git_status} =~ "working directory clean" ]]; then
local state="$unclean_state"
fi
# add an else if or two here if you want to get more specific
if [[ ${git_status} =~ ${remote_pattern} ]]; then
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
local remote="$changes_to_push"
else
local remote="$changes_to_pull"
fi
fi
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
local remote="$changes_to_push_and_pull"
fi
if [[ ${git_status} =~ ${branch_pattern} ]]; then
local branch=${BASH_REMATCH[1]}
local git_branch=" (${branch})${remote}${state}"
fi
[[ $(who am i) =~ \([0-9\.]+\)$ ]] && local host=" \\u@\h "
local path="${LIGHT_BLUE}\w"
local branch="${LIGHT_MAGENTA}$git_branch"
local prompt="$path$branch$host${COLOR_NONE}"
if test $previous_return_value -eq 0; then
PS1="${prompt}\\\$ "
else
PS1="${prompt}${RED}\\\$${COLOR_NONE} "
fi
}