-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathps1.bash
More file actions
71 lines (59 loc) · 1.63 KB
/
Copy pathps1.bash
File metadata and controls
71 lines (59 loc) · 1.63 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
70
71
# Inspired by https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
# Capture exit code before anything else runs
PROMPT_COMMAND='__last_exit=$?'
function last_exit_code {
if [[ $__last_exit != 0 ]]; then
echo -n "[$__last_exit] "
fi
}
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
}
function keychain_locked_indicator {
if ! security show-keychain-info ~/Library/Keychains/login.keychain-db &>/dev/null 2>&1; then
echo -n "🔒 "
fi
}
export GIT_PS1_SHOWDIRTYSTATE=true
PS1='\[\033[00;31m\]$(keychain_locked_indicator)\[\033[00m\]'
PS1+='\[\033[00;31m\]$(last_exit_code)\[\033[00m\]'
PS1+='$(number_of_background_jobs)'
PS1+='\[\033[00;33m\]$\[\033[00m\] '
if [[ "$(type -t __git_ps1)" == "function" ]]; then
PS1="\$(__git_ps1 \"git(%s\$(count_git_ahead_behind)) \")${PS1}"
fi
PS1="\$(pwd) ${PS1}"
export PS1