-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt
executable file
·57 lines (51 loc) · 2.24 KB
/
prompt
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
#! /bin/bash
set -e
trap 'echo error$ ' ERR
source $(dirname "$BASH_SOURCE")/color.sh
ESCAPE_SEQUENCE_START="$1"
ESCAPE_SEQUENCE_END="$2"
prompt_color() {
color "$1" "$2" "$ESCAPE_SEQUENCE_START" "$ESCAPE_SEQUENCE_END"
}
print_stat() {
if [[ "$3" != "0" ]]; then
prompt_color "1;38;5;${2}m" "$1"
if [[ "$3" != "1" ]]; then
prompt_color "38;5;${2}m" "$3"
fi
fi
}
if $(git status >/dev/null 2>/dev/null); then
remote="origin"
repo="$(basename $(git config --get remote.${remote}.url) .git)"
reference_commit=$(git show-ref --verify -s "refs/remotes/$remote/HEAD")
current_branch="$(git branch --show-current)"
upstream_commit="$(git rev-parse --verify $current_branch@{upstream} 2>/dev/null || echo $reference_commit)"
root="$(git rev-parse --show-toplevel)"
path="${PWD/#${root}}"
path=${path/#\//>}
current_commit=$(git rev-parse --verify HEAD | tr -d "\n")
current_mergecount=$(git rev-list ${current_commit} ^${upstream_commit} ^${reference_commit} --count | tr -d "\n")
upstream_mergecount=$(git rev-list ${upstream_commit} ^${reference_commit} --count | tr -d "\n")
current_behind=$(git rev-list ${upstream_commit} ^${reference_commit} ^${current_commit} --count | tr -d "\n")
upstream_behind=$(git rev-list ${reference_commit} ^${upstream_commit} --count | tr -d "\n")
prompt_color "32m" "$repo"
print_stat "*" "21" $(git branch -l | grep -v '^\*' | wc -l) # branches
print_stat "*" "55" $(git stash list | wc -l | tr -d " \n") # stashes
echo -ne ">"
prompt_color "38;5;45m" "${current_branch:-(detached)}"
print_stat "^" "142" "$upstream_behind"
print_stat "*" "142" "$upstream_mergecount" # commits from reference to upstream
print_stat "^" "214" "$current_behind"
print_stat "*" "214" "$current_mergecount" # commits from upstream to HEAD
print_stat "*" "202" $(git status --porcelain | grep '^[A-Z].' | wc -l) # modified files in index
print_stat "*" "196" $(git status --porcelain | grep '^.[A-Z]' | wc -l) # modified files locally
print_stat "*" "201" $(git status --porcelain | grep '^??' | wc -l) # new files
echo -ne "$path"
# commits from reference to pr base branch
# commits from pr base branch to pr head
# How far ahead is reference? PR base?
else
echo -ne "$PWD";
fi
echo -ne '$ '