-
Notifications
You must be signed in to change notification settings - Fork 0
/
.git-prompt.bash
90 lines (80 loc) · 1.98 KB
/
.git-prompt.bash
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
78
79
80
81
82
83
84
85
86
87
88
89
90
in_git_repos() {
test "`git rev-parse --is-inside-work-tree 2>/dev/null`" = "true"
}
git_current_branch() {
if in_git_repos; then
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
fi
}
git_status_is_clean() {
if in_git_repos; then
local lines=$(git status --porcelain | egrep -v '^\?\? ' | wc -l)
test $lines = 0
fi
}
git_unknown_files() {
if in_git_repos; then
local lines=$(git status --porcelain | egrep '^\?\? ' | wc -l)
test $lines = 0
fi
}
git_stash_is_clean() {
if in_git_repos; then
local lines=$(git stash list | wc -l)
test $lines = 0
fi
}
git_no_branches() {
if in_git_repos; then
local lines=$(git branch | wc -l)
test $lines = 1
fi
}
git_single_remote() {
if in_git_repos; then
local lines=$(git remote | wc -l)
test $lines -le 1
fi
}
git_no_remote() {
if in_git_repos; then
local lines=$(git remote | wc -l)
test $lines = 0
fi
}
git_branch_is_pushed() {
if in_git_repos; then
if git branch -r | grep "origin/master" >/dev/null 2>&1; then
git_no_remote || git diff-tree --quiet origin/master heads/master
fi
fi
}
#-----------------------------------------------------------------------------
git_prompt_precmd() {
GITINFO=""
if [ ! -z `git_current_branch` ]; then
GITINFO="<`git_current_branch`"
if ! git_status_is_clean; then
GITINFO="$GITINFO**"
fi
if ! git_unknown_files; then
GITINFO="$GITINFO*?"
fi
if ! git_branch_is_pushed; then
GITINFO="$GITINFO*"
fi
if ! git_stash_is_clean; then
GITINFO="$GITINFO?"
fi
if ! git_no_branches; then
GITINFO="$GITINFO?"
fi
if ! git_single_remote; then
GITINFO="$GITINFO®"
fi
GITINFO="$GITINFO>"
fi
echo $GITINFO
}