This repository was archived by the owner on Nov 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_git_prompt
More file actions
70 lines (56 loc) · 2.41 KB
/
bash_git_prompt
File metadata and controls
70 lines (56 loc) · 2.41 KB
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
#!/bin/bash
########################################################################
# Create a custom prompt with some useful Git info
########################################################################
# here is a specific bash (no zsh) customized git prompt
# it does less than provided git-prompt (https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh) but tries to be faster
# Load some colors constants
source ~/pretty-git-for-bash/bash_colors
source ~/pretty-git-for-bash/bash_unicode_chars
# Be sure to use a unicode compliant locale (to be able to display unicode chars in Prompt)
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LANG="en_US.UTF-8"
export LANGUAGE="en_US.UTF-8"
# Parse 'git status' result and put some info in PS1 prompt.
function parse_git_status {
git rev-parse --git-dir &> /dev/null
git_status="$(git status 2> /dev/null)"
# check if current directory is a git dir (if true, 'git status' must contain "On branch xxx")
if [[ ! -z `echo "${git_status}" | grep "On branch"` ]]; then
branch_name=`echo "${git_status}" | grep "On branch" | sed "s/.*On branch \(.*\)/\1/"`
# check if local branch is ahead/behing of remote branch, or if both have diverged.
if [[ ! -z `echo "${git_status}" | grep "have diverged"` ]]; then
remote=" ${BG_GREEN_FG_PURPLE}<>"
else
if [[ ! -z `echo "${git_status}" | grep "ahead"` ]]; then
remote=" ${BG_GREEN_FG_BLUE}>"
else
if [[ ! -z `echo "${git_status}" | grep "behind"` ]]; then
remote=" ${BG_GREEN_FG_BLUE}<"
fi
fi
fi
# check if we are working on clean directory (no untracked file) or not
if [[ ! ${git_status}} == *"working directory clean"* ]]; then
state="${BG_GREEN_FG_RED}¤"
fi
echo "${BG_GREEN_FG_BLACK} (${branch_name}${remote}${state}${BG_GREEN_FG_BLACK}) "
fi
}
function get_git_info {
branch_name=`(git symbolic-ref HEAD 2> /dev/null || git rev-parse --short HEAD 2> /dev/null) | sed "s#refs/heads/##"`
if [[ ! -z "$branch_name" ]]; then
echo "${BG_GREEN_FG_BLACK} (${branch_name})"
else
echo ""
fi
}
function prompt_func() {
if [[ ! -z "$PRETTY_GIT_FAST_MODE" ]]; then
PS1="${BG_YELLOW_FG_BLACK} \u@\h ${BG_BLUE_FG_WHITE} \W $(get_git_info)${COLOR_OFF} > "
else
PS1="${BG_YELLOW_FG_BLACK} \u@\h ${BG_BLUE_FG_WHITE} \W $(parse_git_status)${COLOR_OFF} > "
fi
}
PROMPT_COMMAND=prompt_func