-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.bash_git
49 lines (39 loc) · 1.24 KB
/
.bash_git
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
red=$(tput setaf 1)
green=$(tput setaf 2)
cyan=$(tput setaf 6)
reset=$(tput sgr0)
bold=$(tput bold)
get_git_branch() {
branch=$(git branch | grep "\*" | tr -d \*| tr -d ' ')
echo $branch
}
get_git_color() {
status=$(git status)
if echo "$status" | egrep -q "nichts zum Commit|nichts zu committen|nothing added to commit|nothing to commit"; then
color=$green
else
color=$red
fi
if echo "$status" | egrep -q "unbeobachtet|untracked|Unbeobachtet|Untracked|Unversioniert|Unversioned"; then
color=$bold$color
fi
echo $color
}
check_git() {
if [[ "$(__git_ps1)" != "" ]]; then
export GIT_PROMPT_BEGIN=" "[
export GIT_COLOR=$(get_git_color)
export GIT_BRANCH=$(get_git_branch)
export GIT_PROMPT_END=]
else
export GIT_PROMPT_BEGIN=''
export GIT_BRANCH=''
export GIT_PROMPT_END=''
fi
}
PROMPT_COMMAND='check_git'
if [ "$1" = colored_prompt ]; then
export PS1='\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]:$GIT_PROMPT_BEGIN\[$GIT_COLOR\]$GIT_BRANCH\[$reset\]$GIT_PROMPT_END\$ '
else
export PS1='\u@\h:\w$GIT_PROMPT_BEGIN\[$GIT_COLOR\]$GIT_BRANCH\[$reset\]$GIT_PROMPT_END\$ '
fi