-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_ps1
64 lines (57 loc) · 1.98 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
fill="--- "
beutify_ps1() {
if [ $? = 0 ]; then
local last_state="${BCYAN}:)${COFF} "
else
local last_state="${BRED}:(${COFF} "
fi
# create a $fill of all screen width minus the time string and a space
prefix_str="$USER@$HOSTNAME"
let fillsize=${COLUMNS}-${#prefix_str}-10
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="-${fill}" # fill with underscores to work on
let fillsize=${fillsize}-1
done
# indicator treatment
if [ "${PWD}" = $HOME ]; then
local indicator="${BASE0}>${COFF} "
else
local indicator=" ${BASE0}~>${COFF} "
fi
pwd="${BASE0}\w${COFF}"
git rev-parse --git-dir &> /dev/null
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} =~ "nothing" ]]; then
local git_state="${BORANGE}*${COFF}"
else
unset git_state
fi
if [[ ${git_status} =~ ${remote_pattern} ]]; then
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
local git_remote="${YELLOW}↑${COFF}"
else
local git_remote="${YELLOW}↓${COFF}"
fi
fi
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
local git_remote="${BRED}↕${COFF}"
else
unset git_remote
fi
if [[ ${git_status} =~ ${branch_pattern} ]]; then
local git_branch="${BYELLOW}@${COFF}${CYAN}${BASH_REMATCH[1]}${COFF}"
local git_string="${git_branch}${git_remote}${git_state}"
fi
OLD_PS1="${last_state}${pwd}${git_string}${indicator}"
export PS1="${BASE00}\u@\h "'$fill \t\n'"${COFF}$OLD_PS1"
# Temporarily comment out the trap DEBUG line due to a Linux specific bug
# Wait until it get fixed
# Related forum post: http://gnu-bash.2382.n7.nabble.com/Latest-fix-for-DEBUG-causes-pipes-to-fail-when-used-with-trap-and-an-interactive-shell-td13044.html
#trap 'echo -ne "\e[0m"' DEBUG # this one is invoked every time before a command is executed
}
PROMPT_COMMAND=beutify_ps1