-
Notifications
You must be signed in to change notification settings - Fork 4
/
git_prompt.fish
78 lines (63 loc) · 1.66 KB
/
git_prompt.fish
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
72
73
74
75
76
77
78
#
# Git Prompt for Fish.
#
#
#
function git_prompt
set -l text (command git status --porcelain=v2 --branch ^/dev/null)
if [ $status -ne 0 ] >/dev/null
return
end
set -l branch_oid
set -l branch_head
# Flags.
set -l changes ''
set -l untracked ''
set -l conflict ''
set -l ahead ''
set -l behind ''
for line in $text
set -l words (string split " " $line)
switch $words[1]
# Why doesn't this work if the '#' case is last?
case '#'
switch $words[2]
case 'branch.oid'
set oid $words[3]
case 'branch.head'
set head $words[3]
case 'branch.ab'
if [ $words[3] != "+0" ]
set ahead '↑'
end
if [ $words[4] != "-0" ]
set behind '↓'
end
end
case 'u'
set conflict '!'
case '1' '2'
set changes '*'
case '?'
set untracked '?'
end
end
if [ $oid = "(initial)" ]
set head ":initial"
else if [ $head = "(detached)" ]
set head ':'(string sub -l 6 $oid)
end
set -l color green
if [ $conflict != '' ]
set color red
else if [ $changes$untracked != '' ]
set color yellow
end
set -l flags $changes$untracked$conflict$ahead$behind
if [ $flags != "" ]
set flags " $flags"
end
set_color $color
echo "[$head$flags]"
set_color normal
end