-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtgit-status
More file actions
executable file
·120 lines (102 loc) · 4.38 KB
/
tgit-status
File metadata and controls
executable file
·120 lines (102 loc) · 4.38 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#
# Git status
#
# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
RED='\033[0;31m'
CYAN='\033[0;36m'
LIGHT_GREEN='\033[1;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
SPACESHIP_GIT_STATUS_SHOW="${SPACESHIP_GIT_STATUS_SHOW=true}"
SPACESHIP_GIT_STATUS_PREFIX="${SPACESHIP_GIT_STATUS_PREFIX=" ["}"
SPACESHIP_GIT_STATUS_SUFFIX="${SPACESHIP_GIT_STATUS_SUFFIX="]"}"
SPACESHIP_GIT_STATUS_COLOR="${SPACESHIP_GIT_STATUS_COLOR="red"}"
SPACESHIP_GIT_STATUS_UNTRACKED="${SPACESHIP_GIT_STATUS_UNTRACKED="?"}"
SPACESHIP_GIT_STATUS_ADDED="${SPACESHIP_GIT_STATUS_ADDED="${LIGHT_GREEN}+${NC}"}"
SPACESHIP_GIT_STATUS_MODIFIED="${SPACESHIP_GIT_STATUS_MODIFIED="${YELLOW}!${NC}"}"
SPACESHIP_GIT_STATUS_RENAMED="${SPACESHIP_GIT_STATUS_RENAMED="»"}"
SPACESHIP_GIT_STATUS_DELETED="${SPACESHIP_GIT_STATUS_DELETED="${RED}✘${NC}"}"
SPACESHIP_GIT_STATUS_STASHED="${SPACESHIP_GIT_STATUS_STASHED="$"}"
SPACESHIP_GIT_STATUS_UNMERGED="${SPACESHIP_GIT_STATUS_UNMERGED="="}"
SPACESHIP_GIT_STATUS_AHEAD="${SPACESHIP_GIT_STATUS_AHEAD="${CYAN}⇡${NC}"}"
SPACESHIP_GIT_STATUS_BEHIND="${SPACESHIP_GIT_STATUS_BEHIND="⇣"}"
SPACESHIP_GIT_STATUS_DIVERGED="${SPACESHIP_GIT_STATUS_DIVERGED="⇕"}"
# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------
# We used to depend on OMZ git library,
# But it doesn't handle many of the status indicator combinations.
# Also, It's hard to maintain external dependency.
# See PR #147 at https://git.io/vQkkB
# See git help status to know more about status formats
# spaceship_git_status() {
# [[ $SPACESHIP_GIT_STATUS_SHOW == false ]] && return
# spaceship::is_git || return
INDEX=''
git_status=""
INDEX=$(cd "$1" && command git status --porcelain -b 2> /dev/null)
# Check for untracked files
if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_UNTRACKED$git_status"
fi
# Check for staged files
if $(echo "$INDEX" | command grep '^A[ MDAU] ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
elif $(echo "$INDEX" | command grep '^M[ MD] ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
elif $(echo "$INDEX" | command grep '^UA' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
fi
# Check for modified files
if $(echo "$INDEX" | command grep '^[ MARC]M ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_MODIFIED$git_status"
fi
# Check for renamed files
if $(echo "$INDEX" | command grep '^R[ MD] ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_RENAMED$git_status"
fi
# Check for deleted files
if $(echo "$INDEX" | command grep '^[MARCDU ]D ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status"
elif $(echo "$INDEX" | command grep '^D[ UM] ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status"
fi
# Check for stashes
if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
git_status="$SPACESHIP_GIT_STATUS_STASHED$git_status"
fi
# Check for unmerged files
if $(echo "$INDEX" | command grep '^U[UDA] ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
elif $(echo "$INDEX" | command grep '^AA ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
elif $(echo "$INDEX" | command grep '^DD ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
elif $(echo "$INDEX" | command grep '^[DA]U ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
fi
# Check whether branch is ahead
is_ahead=false
if $(echo "$INDEX" | command grep '^## [^ ]\+ .*ahead' &> /dev/null); then
is_ahead=true
fi
# Check whether branch is behind
is_behind=false
if $(echo "$INDEX" | command grep '^## [^ ]\+ .*behind' &> /dev/null); then
is_behind=true
fi
# Check wheather branch has diverged
if [[ "$is_ahead" == true && "$is_behind" == true ]]; then
git_status="$SPACESHIP_GIT_STATUS_DIVERGED$git_status"
else
[[ "$is_ahead" == true ]] && git_status="$SPACESHIP_GIT_STATUS_AHEAD$git_status"
[[ "$is_behind" == true ]] && git_status="$SPACESHIP_GIT_STATUS_BEHIND$git_status"
fi
if [[ "$2" == "-c" ]]; then
echo -e "$git_status"
else
echo $(echo -e "$git_status" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g")
fi