-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_git_prompt
78 lines (68 loc) · 2.14 KB
/
.bash_git_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
70
71
72
73
74
75
76
77
# From stconfig's .gitrc_st
COLOR_RESET="\[\033[0;39;49m\]"
COLOR_BRANCH="\[\033[0;1;32;44m\]"
COLOR_REPO="\[\033[0;1;33;44m\]"
COLOR_WORKDIR="\[\033[0;1;33;42m\]"
MOD_GLYPH="*"
STATE_GLYPH="|"
PS1_GLYPH="\$"
# shamelessly ripped off from http://github.com/rtomayko/git-sh/tree/master
# ... and Ubuntu's __git_ps1() in /etc/bash_completion.d/git
_git_prompt_color() {
local g r b rel loc mod
g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -z $g ]; then
export BASH_GIT_BRANCH=""
PS1="\u@\h:\w$PS1_GLYPH "
return
fi
if [ -d "$g/../.dotest" ]
then
if test -f "$g/../.dotest/rebasing"
then
r="${STATE_GLYPH}REBASE"
elif test -f "$g/../.dotest/applying"
then
r="${STATE_GLYPH}AM"
else
r="${STATE_GLYPH}AM/REBASE"
fi
b="$(git symbolic-ref HEAD 2>/dev/null)"
elif [ -f "$g/.dotest-merge/interactive" ]
then
r="${STATE_GLYPH}REBASE-i"
b="$(cat "$g/.dotest-merge/head-name")"
elif [ -d "$g/.dotest-merge" ]
then
r="${STATE_GLYPH}REBASE-m"
b="$(cat "$g/.dotest-merge/head-name")"
elif [ -f "$g/MERGE_HEAD" ]
then
r="${STATE_GLYPH}MERGING"
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
if [ -f "$g/BISECT_LOG" ]
then
r="${STATE_GLYPH}BISECTING"
fi
if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
then
if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
then
b="$(cut -c1-7 "$g/HEAD")..."
fi
fi
fi
b="${b##refs/heads/}" # make it a pretty name
export BASH_GIT_BRANCH="$b"
mod=`git ls-files --modified --deleted --others --exclude-standard 2>/dev/null | head -1`
if [ ! -z "$mod" ]; then
r="${MOD_GLYPH}$r"
fi
rel=$(git rev-parse --show-prefix 2>/dev/null)
rel="${rel%/}"
loc="${PWD%/$rel}"
PS1="\u@\h:${COLOR_BRANCH}${b}${r}${COLOR_RESET}!${COLOR_REPO}${loc/*\/}${COLOR_RESET}${COLOR_WORKDIR}${rel:+/$rel}${COLOR_RESET}${PS1_GLYPH} "
}
# write this after source-ing this file
#PROMPT_COMMAND=_git_prompt_color