-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript
53 lines (46 loc) · 1.66 KB
/
script
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
# COPY EVERYTHING BELOW TO ~/.profile or (if doesn't work) ~/.bashrc
# IT WAS WRITTEN FOR MY OWN PS1, BUT I SUPPOSE IT IS THE DEFAULT ONE. - UBUNTU 18.04
# EVERYTHING IS NAMED SO I HOPE YOU WILL CUSTOMIZE IT QUICKLY FOR YOUR OWN USAGE.
# BASED ON https://coderwall.com/p/pn8f0g/show-your-git-status-and-branch-in-color-at-the-command-prompt
#
# Add git branch to prompt
#
COLOR_RED="\033[01;31m"
COLOR_YELLOW="\033[01;33m"
COLOR_GREEN="\033[01;32m"
function git_color {
local git_status="$(git status 2> /dev/null)"
if [[ -n "$git_status" ]];
then
local is_git_repository=true
fi
if [[ ${is_git_repository} == true ]]; then
if [[ ${git_status} =~ "Your branch is ahead of" ]]; then
echo -e ${COLOR_YELLOW}
elif [[ ${git_status} =~ "nothing to commit" ]]; then
echo -e ${COLOR_GREEN}
else
echo -e ${COLOR_RED}
fi
fi
}
function git_branch {
local git_status="$(git status 2> /dev/null)"
local on_branch="On branch ([^${IFS}]*)"
local on_commit="HEAD detached at ([^${IFS}]*)"
if [[ ${git_status} =~ $on_branch ]]; then
local branch=${BASH_REMATCH[1]}
echo "($branch)"
elif [[ ${git_status} =~ $on_commit ]]; then
local commit=${BASH_REMATCH[1]}
echo "($commit)"
fi
}
# original PS1 - for reference
#export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}" #default from original PS1
PS1+="\[\033[01;32m\]\u@\h\[\033[00m\]" #default from original PS1
PS1+="\[\$(git_color)\]"
PS1+="\$(git_branch)"
PS1+=":\[\033[01;34m\]\w\[\033[00m\]\$ " #default from original PS1
export PS1