@@ -13,78 +13,64 @@ geometry_git_time() {
13
13
local seconds_since_last_commit
14
14
last_commit=$( git log -1 --pretty=format:' %at' 2> /dev/null)
15
15
16
- [[ -z " $last_commit " ]] && ansi ${GEOMETRY_COLOR_NO_TIME:= default} ${GEOMETRY_GIT_NO_COMMITS_MESSAGE:= no-commits} && return
16
+ [[ -z " $last_commit " ]] && ansi ${GEOMETRY_COLOR_NO_TIME:- default} ${GEOMETRY_GIT_NO_COMMITS_MESSAGE:- no-commits} && return
17
17
18
18
now=$( date +%s)
19
19
seconds_since_last_commit=$(( now - last_commit))
20
- geometry::time $seconds_since_last_commit ${GEOMETRY_GIT_TIME_DETAILED:= false}
20
+ geometry::time $seconds_since_last_commit ${GEOMETRY_GIT_TIME_DETAILED:- false}
21
21
}
22
22
23
23
geometry_git_branch () {
24
- ansi ${GEOMETRY_GIT_COLOR_BRANCH:= 242} $( git symbolic-ref --short HEAD || git rev-parse --short HEAD)
24
+ ansi ${GEOMETRY_GIT_COLOR_BRANCH:- 242} $( git symbolic-ref --short HEAD || git rev-parse --short HEAD)
25
25
}
26
26
27
27
geometry_git_status () {
28
- : ${GEOMETRY_GIT_COLOR_DIRTY:= red}
29
- : ${GEOMETRY_GIT_COLOR_CLEAN:= green}
30
- : ${GEOMETRY_GIT_SYMBOL_DIRTY:= " ⬡" }
31
- : ${GEOMETRY_GIT_SYMBOL_CLEAN:= " ⬢" }
32
- local _status
33
28
command git rev-parse --git-dir > /dev/null 2>&1 || return
34
- _status=$( [[ -z " $( git status --porcelain --ignore-submodules HEAD) " ]] && [[ -z " $( git ls-files --others --modified --exclude-standard $( git rev-parse --show-toplevel) ) " ]] && echo CLEAN || echo DIRTY)
35
- ansi ${(e):- \$ GEOMETRY_GIT_COLOR_${_status} } ${(e):- \$ GEOMETRY_GIT_SYMBOL_${_status} }
29
+
30
+ [[ -z " $( git status --porcelain --ignore-submodules HEAD) " ]] \
31
+ && [[ -z " $( git ls-files --others --modified --exclude-standard $( git rev-parse --show-toplevel) ) " ]] \
32
+ && ansi ${GEOMETRY_GIT_COLOR_DIRTY:- red} ${GEOMETRY_GIT_SYMBOL_DIRTY:- " ⬡" } \
33
+ || ansi ${GEOMETRY_GIT_COLOR_CLEAN:- green} ${GEOMETRY_GIT_SYMBOL_CLEAN:- " ⬢" }
36
34
}
37
35
38
36
geometry_git_rebase () {
39
- : ${GEOMETRY_GIT_SYMBOL_REBASE:= " ®" }
40
37
local git_dir
41
38
git_dir=$( git rev-parse --git-dir)
42
39
[[ -d " $git_dir /rebase-merge" ]] || [[ -d " $git_dir /rebase-apply" ]] || return
43
- echo " $ GEOMETRY_GIT_SYMBOL_REBASE"
40
+ echo ${ GEOMETRY_GIT_SYMBOL_REBASE:- " ® " }
44
41
}
45
42
46
43
geometry_git_remote () {
47
- : ${GEOMETRY_GIT_SYMBOL_UNPUSHED:= " ⇡" }
48
- : ${GEOMETRY_GIT_SYMBOL_UNPULLED:= " ⇣" }
49
- : ${GEOMETRY_GIT_SYMBOL_CONFLICTS_SOLVED:= " ◆" }
50
- : ${GEOMETRY_GIT_SYMBOL_CONFLICTS_UNSOLVED:= " ◈" }
51
-
52
- local common_base
53
- local local_commit
54
- local remote_commit
55
- local_commit=$( git rev-parse " @" 2> /dev/null)
56
- remote_commit=$( git rev-parse " @{u}" 2> /dev/null)
44
+ local unpushed=${GEOMETRY_GIT_SYMBOL_UNPUSHED:- " ⇡" }
45
+ local unpulled=${GEOMETRY_GIT_SYMBOL_UNPULLED:- " ⇣" }
46
+ local local_commit && local_commit=$( git rev-parse " @" 2> /dev/null)
47
+ local remote_commit && remote_commit=$( git rev-parse " @{u}" 2> /dev/null)
57
48
58
49
[[ $local_commit == " @" || $local_commit == $remote_commit ]] && return
59
50
60
- common_base=$( git merge-base " @" " @{u}" 2> /dev/null) # last common commit
61
- [[ $common_base == $remote_commit ]] && echo $GEOMETRY_GIT_SYMBOL_UNPUSHED && return
62
- [[ $common_base == $local_commit ]] && echo $GEOMETRY_GIT_SYMBOL_UNPULLED && return
51
+ local common_base && common_base=$( git merge-base " @" " @{u}" 2> /dev/null) # last common commit
52
+ [[ $common_base == $remote_commit ]] && echo $unpushed && return
53
+ [[ $common_base == $local_commit ]] && echo $unpulled && return
63
54
64
- echo " $GEOMETRY_GIT_SYMBOL_UNPUSHED $GEOMETRY_GIT_SYMBOL_UNPULLED "
55
+ echo " $unpushed $unpulled "
65
56
}
66
57
67
58
geometry_git_symbol () { echo ${(j: : ):- $(geometry_git_rebase) $(geometry_git_remote)} ; }
68
59
69
60
geometry_git_conflicts () {
70
- : ${GEOMETRY_GIT_COLOR_CONFLICTS_UNSOLVED:= red}
71
- : ${GEOMETRY_GIT_COLOR_CONFLICTS_SOLVED:= green}
72
- local conflicts
73
61
local _grep
74
- local conflict_list
75
- local raw_file_count
76
- local file_count
77
- local raw_total
78
- local total
62
+ local conflicts conflict_list
63
+ local file_count raw_file_count
64
+ local total raw_total
79
65
conflicts=$( git diff --name-only --diff-filter=U)
80
66
81
67
[[ -z " $conflicts " ]] && return
82
68
83
69
pushd -q $( git rev-parse --show-toplevel)
84
70
85
71
_grep=${GEOMETRY_GIT_GREP:= ${commands[rg]:= ${commands[ag]:= ${commands[grep]} } } }
86
-
87
72
conflict_list=$( $_grep -cH ' ^=======$' $conflicts )
73
+
88
74
popd -q
89
75
90
76
raw_file_count=" ${# ${(@ f)conflict_list} } "
@@ -93,9 +79,11 @@ geometry_git_conflicts() {
93
79
raw_total=$( echo $conflict_list | cut -d ' :' -f2 | paste -sd+ - | bc)
94
80
total=${raw_total##* ( )}
95
81
96
- [[ -z " $total " ]] && ansi $GEOMETRY_GIT_COLOR_CONFLICTS_SOLVED $GEOMETRY_GIT_SYMBOL_CONFLICTS_SOLVED && return
82
+ [[ -z " $total " ]] && ansi ${GEOMETRY_GIT_COLOR_CONFLICTS_SOLVED:- green} ${GEOMETRY_GIT_SYMBOL_CONFLICTS_SOLVED:- " ◆" } && return
83
+
84
+ count=" (${file_count} f|${total} c)"
97
85
98
- ansi $GEOMETRY_GIT_COLOR_CONFLICTS_UNSOLVED " $GEOMETRY_GIT_SYMBOL_CONFLICTS_UNSOLVED ( ${file_count} f| ${total} c) "
86
+ ansi ${ GEOMETRY_GIT_COLOR_CONFLICTS_UNSOLVED:- red} " ${ GEOMETRY_GIT_SYMBOL_CONFLICTS_UNSOLVED:- ' ◈ ' } $count "
99
87
}
100
88
101
89
geometry_git () {
@@ -105,16 +93,13 @@ geometry_git() {
105
93
&& ansi ${GEOMETRY_GIT_COLOR_BARE:= blue} ${GEOMETRY_GIT_SYMBOL_BARE:= " ⬢" } \
106
94
&& return
107
95
108
- echo -n $( geometry_git_symbol) $( geometry_git_branch) \
109
- $( geometry::git_wrapper \
110
- $( geometry_git_conflicts) \
111
- $( geometry_git_time) \
112
- $( geometry_git_stashes) \
113
- $( geometry_git_status)
114
- )
115
- }
96
+ local geometry_git_details && geometry_git_details=(
97
+ $( geometry_git_conflicts)
98
+ $( geometry_git_time)
99
+ $( geometry_git_stashes)
100
+ $( geometry_git_status)
101
+ )
116
102
117
- geometry::git_wrapper () {
118
- : ${GEOMETRY_GIT_SEPARATOR:= " :: " }
119
- echo -n ${(pj.$GEOMETRY_GIT_SEPARATOR .)$(print -r " $@ " )}
103
+ local separator=${GEOMETRY_GIT_SEPARATOR:- " :: " }
104
+ echo -n $( geometry_git_symbol) $( geometry_git_branch) ${(pj.$separator .)geometry_git_details}
120
105
}
0 commit comments