-
Notifications
You must be signed in to change notification settings - Fork 1
/
.bash_prompt
55 lines (51 loc) · 1.47 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
# http://ezprompt.net/
# get current branch in git repo
parse_git_branch() {
BRANCH="$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')"
if [ -n "$BRANCH" ] ; then
STAT="$(parse_git_dirty)"
printf -- '%s\n' "[${BRANCH} ${STAT}]"
else
printf '\n'
fi
}
# get current status of git repo
parse_git_dirty() {
status="$(git status 2>&1)"
dirty=$(printf '%s' "$status" | grep "modified:" &> /dev/null; echo "$?")
untracked=$(printf '%s' "$status" | grep "Untracked files" &> /dev/null; echo "$?")
ahead=$(printf '%s' "$status" | grep "Your branch is ahead of" &> /dev/null; echo "$?")
newfile=$(printf '%s' "$status" | grep "new file:" &> /dev/null; echo "$?")
renamed=$(printf '%s' "$status" | grep "renamed:" &> /dev/null; echo "$?")
deleted=$(printf '%s' "$status" | 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 [ -n "$bits" ]; then
printf '%s' "$bits"
else
printf '\n'
fi
}
PROMPT_CHAR="○"
if [[ "$TERM" =~ 256color ]]; then
export PS1="${BOLD}${GREEN}\u${RESTORE} at ${BOLD}${LBLUE}\h${RESTORE} in ${BOLD}${LYELLOW}\W${RESTORE} \`parse_git_branch\`\n${BOLD}${PROMPT_CHAR}${RESTORE} "
else
export PS1='[\u@\h \W]\$ '
fi