-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.bash_prompt
More file actions
executable file
·53 lines (49 loc) · 1.99 KB
/
.bash_prompt
File metadata and controls
executable file
·53 lines (49 loc) · 1.99 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
###################################
# Color Declerations
###################################
TEAL_USER=$(tput setaf 29)
ORANGE_BRANCH=$(tput setaf 202)
WHITE_ACCENTS=$(tput setaf 230)
YELLOW_GIT_STATUS=$(tput setaf 220)
YELLOW_FOLDER=$(tput setaf 136)
###################################
# New Git Tracking System
###################################
__powerline() {
# Unicode symbols
GIT_BRANCH_SYMBOL='⑂ '
GIT_BRANCH_CHANGED_SYMBOL='+'
GIT_NEED_PUSH_SYMBOL='↾'
GIT_NEED_PULL_SYMBOL='⇂'
RESET="\[$(tput sgr0)\]"
__git_info() {
# git not found
[ -x "$(which git)" ] || return
# force git output in English to make our work easier
local git_eng="env LANG=C git"
# get current branch name or short SHA1 hash for detached head
local branch="$($git_eng symbolic-ref --short HEAD 2>/dev/null || $git_eng describe --tags --always 2>/dev/null)"
# git branch not found
[ -n "$branch" ] || return
local marks
# branch is modified?
[ -n "$($git_eng status --porcelain)" ] && marks+=" $GIT_BRANCH_CHANGED_SYMBOL"
# how many commits local branch is ahead/behind of remote?
local stat="$($git_eng status --porcelain --branch | grep '^##' | grep -o '\[.\+\]$')"
local aheadN="$(echo $stat | grep -o 'ahead [[:digit:]]\+' | grep -o '[[:digit:]]\+')"
local behindN="$(echo $stat | grep -o 'behind [[:digit:]]\+' | grep -o '[[:digit:]]\+')"
[ -n "$aheadN" ] && marks+=" $GIT_NEED_PUSH_SYMBOL$aheadN"
[ -n "$behindN" ] && marks+=" $GIT_NEED_PULL_SYMBOL$behindN"
# print the git branch segment without a trailing newline
printf "$WHITE_ACCENTS$GIT_BRANCH_SYMBOL$ORANGE_BRANCH$branch$YELLOW_GIT_STATUS$marks"
}
ps1() {
# Base PS1 prompt
PS1="\[$TEAL_USER\]\u\[ \]\[$WHITE_ACCENTS\]in\[ \]\[$YELLOW_FOLDER\]\w "
# Add Git Info and New Line and end to PS1 prompt
PS1+="$(__git_info)\[$WHITE_ACCENTS\]\n$\[$RESET\]\[ \]"
}
PROMPT_COMMAND=ps1
}
__powerline
unset __powerline