-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitrc
110 lines (101 loc) · 3.01 KB
/
.gitrc
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# Configure colors for git prompt, if available.
if [ "$color_prompt" = yes ]; then
c_reset='\[\e[0m\]'
c_user='\[\e[1;33m\]'
c_path='\[\e[1;34m\]'
c_git_pending='\[\e[1;36m\]'
c_git_clean='\[\e[0;36m\]'
c_git_staged='\[\e[1;35m\]'
c_git_dirty='\[\e[1;31m\]'
prompt_use_colors=yes
else
c_reset=
c_user=
c_path=
c_git_pending=
c_git_clean=
c_git_staged=
c_git_dirty=
prompt_use_colors=no
fi
orig_user=$(id -u)
number_re='^[0-9]+$';
if [[ -z $prompt_host ]]; then
prompt_host="\h"
fi
# Function to assemble the Git part of our prompt.
git_prompt ()
{
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
git_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [ "$prompt_use_colors" = yes ]; then
if git diff --quiet 2>/dev/null >&2; then
staged=$(git status --porcelain 2>/dev/null| grep "^[MA]" | wc -l);
if ! [ $staged -eq 0 ]; then
git_color="$c_git_staged";
else
if ! [ $SUDO_UID ]; then
update_interval=$(git config --get prompt.updateinterval);
if ! [ -z "$update_interval" ]; then
if ! [[ $update_interval =~ $number_re ]]; then
echo "[ ${c_git_dirty}Bad value <$update_interval> in prompt.updateinterval (want a positive integer)${c_reset} ]";
return;
elif [ $update_interval -le 0 ]; then
echo "[ ${c_git_dirty}Bad value <$update_interval> in prompt.updateinterval (want a positive integer)${c_reset} ]";
return;
fi
last_up=$(git config --local --get prompt.lastupdate);
if [ -z "$last_up" ]; then
last_up=0;
fi
if [ $(expr $(date +%s) - $last_up ) -gt $update_interval ]; then
git remote update 2>/dev/null 1>&2;
git config --local prompt.lastupdate $(date +%s);
fi
fi
fi
pending=$(expr $(git log --oneline @{u}.. 2>/dev/null | wc -l) + $(git log --oneline ..@{u} 2>/dev/null | wc -l));
if ! [ $pending -eq 0 ]; then
git_color="$c_git_pending";
else
git_color="$c_git_clean";
fi
fi
else
git_color="$c_git_dirty";
fi
fi
echo " [$git_color$git_branch${c_reset}]"
}
gitrc_refresh_timeout() {
timeout=$1
re='^[0-9]+$'
if [ -z "$timeout" ]
then
timeout="off"
fi
if [ "$timeout" = "off" ]
then
echo "Turn autoupdate off"
git config --local --unset prompt.updateinterval
elif [[ $timeout =~ $re ]]
then
echo "Set autoupdate to $timeout seconds"
git config --local prompt.updateinterval $timeout
else
echo "Invalid parameter $timeout"
fi
}
if [ $(whoami) = "root" ]; then
prompt_symbol="#"
else
prompt_symbol="$"
fi
if [ "$color_prompt" = yes ]; then
PROMPT_COMMAND='PS1="${debian_chroot:+($debian_chroot)}${c_user}\u${c_reset}@${c_user}${prompt_host}${c_reset}:${c_path}\w${c_reset}$(git_prompt)${prompt_symbol} "'
else
PROMPT_COMMAND='PS1="${debian_chroot:+($debian_chroot)}\u@${prompt_host}:\w$(git_prompt)${prompt_symbol} "'
fi