-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathgit-prompt
More file actions
executable file
·67 lines (62 loc) · 1.42 KB
/
git-prompt
File metadata and controls
executable file
·67 lines (62 loc) · 1.42 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
#!/usr/bin/env sh
# Output a succinct, one-line Git status
#
# E.g.:
# 1ac744a5522d UUAM? master+1-5 origin/master
#
# Usage:
# git prompt
# git-prompt /path/to/repo
color=""
while getopts c: opt; do
case $opt in
c) color="$OPTARG";;
esac
done
shift $(( OPTIND - 1 ))
tgtdir="${1:-$PWD}"
git \
-C "$tgtdir" \
--no-optional-locks \
status \
--porcelain=v2 \
--branch \
2>/dev/null \
| awk -v color="$color" '
BEGIN {
if (color == "ansi") {
_reset = "\033[0m"
_red = "\033[31m"
_green = "\033[32;1m"
_yellow = "\033[33;1m"
} else if (color == "tmux") {
_reset = "#[fg=terminal]"
_red = "#[fg=red]"
_green = "#[fg=green,bold]"
_yellow = "#[fg=yellow,bold]"
}
}
/^# branch\.oid/ { sha=substr($3, 0, 12) }
/^# branch\.head/ { branch=$3 }
/^# branch\.upstream/ { upstream=$3 }
/^# branch\.ab/ {
a = $3 != "+0" ? $3 : ""
b = $4 != "-0" ? $4 : ""
}
/^\?/ { untracked="?" }
/^[0-9] [A-Z]. / { added="A" }
/^[0-9] .[A-Z] / { modified="M" }
/^u UU/ { conflicts="UU" }
END {
print (\
_reset sha,
_red conflicts \
_green added \
_red modified \
_yellow untracked ,
_reset branch \
_green a \
_red b,
_reset)
}
'