-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathps1.bash
56 lines (48 loc) · 1.27 KB
/
ps1.bash
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
# Inspired by https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
function count_git_ahead_behind {
local count
local commits
if commits="$(git rev-list --left-right @{upstream}...HEAD 2>/dev/null)"
then
local commit behind=0 ahead=0
for commit in $commits
do
case "${commit}" in
"<"*) ((behind++)) ;;
*) ((ahead++)) ;;
esac
done
count="${behind} ${ahead}"
else
count=""
fi
case "$count" in
"") # no upstream
echo -n "" ;;
"0 0") # equal to upstream
echo -n "" ;;
"0 "*) # ahead of upstream
echo -n " ${count#0 }↑" ;;
*" 0") # behind upstream
echo -n " ${count% 0}↓" ;;
*) # diverged from upstream
echo -n " ${count#* }↓ ${count% *}↑" ;;
esac
}
function number_of_background_jobs {
number_of_jobs=$(jobs | wc -l | tr -d ' ')
if [[ $number_of_jobs != "0" ]]; then
echo "bg($number_of_jobs) "
fi
}
export GIT_PS1_SHOWDIRTYSTATE=true
PS1='`number_of_background_jobs`\[\033[00;33m\]$\[\033[00m\] '
if [[ "$(type -t __git_ps1)" == "function" ]]; then
PS1="\$(__git_ps1 \"git(%s\$(count_git_ahead_behind)) \")${PS1}"
fi
if [[ "$(type -t fancy_directory)" == "function" ]]; then
PS1="\`fancy_directory\` ${PS1}"
else
PS1="\`pwd\` ${PS1}"
fi
export PS1