66# ------------------------------------------------------------------------------
77# Configuration
88# ------------------------------------------------------------------------------
9+ RED=' \033[0;31m'
10+ CYAN=' \033[0;36m'
11+ LIGHT_GREEN=' \033[1;32m'
12+ YELLOW=' \033[1;33m'
13+ NC=' \033[0m'
914
1015SPACESHIP_GIT_STATUS_SHOW=" ${SPACESHIP_GIT_STATUS_SHOW=true} "
1116SPACESHIP_GIT_STATUS_PREFIX=" ${SPACESHIP_GIT_STATUS_PREFIX=" [" } "
1217SPACESHIP_GIT_STATUS_SUFFIX=" ${SPACESHIP_GIT_STATUS_SUFFIX=" ]" } "
1318SPACESHIP_GIT_STATUS_COLOR=" ${SPACESHIP_GIT_STATUS_COLOR=" red" } "
1419SPACESHIP_GIT_STATUS_UNTRACKED=" ${SPACESHIP_GIT_STATUS_UNTRACKED=" ?" } "
15- SPACESHIP_GIT_STATUS_ADDED=" ${SPACESHIP_GIT_STATUS_ADDED=" + " } "
16- SPACESHIP_GIT_STATUS_MODIFIED=" ${SPACESHIP_GIT_STATUS_MODIFIED=" ! " } "
20+ SPACESHIP_GIT_STATUS_ADDED=" ${SPACESHIP_GIT_STATUS_ADDED=" ${LIGHT_GREEN} + ${NC} " } "
21+ SPACESHIP_GIT_STATUS_MODIFIED=" ${SPACESHIP_GIT_STATUS_MODIFIED=" ${YELLOW} ! ${NC} " } "
1722SPACESHIP_GIT_STATUS_RENAMED=" ${SPACESHIP_GIT_STATUS_RENAMED=" »" } "
18- SPACESHIP_GIT_STATUS_DELETED=" ${SPACESHIP_GIT_STATUS_DELETED=" ✘ " } "
23+ SPACESHIP_GIT_STATUS_DELETED=" ${SPACESHIP_GIT_STATUS_DELETED=" ${RED} ✘ ${NC} " } "
1924SPACESHIP_GIT_STATUS_STASHED=" ${SPACESHIP_GIT_STATUS_STASHED=" $" } "
2025SPACESHIP_GIT_STATUS_UNMERGED=" ${SPACESHIP_GIT_STATUS_UNMERGED=" =" } "
21- SPACESHIP_GIT_STATUS_AHEAD=" ${SPACESHIP_GIT_STATUS_AHEAD=" ⇡ " } "
26+ SPACESHIP_GIT_STATUS_AHEAD=" ${SPACESHIP_GIT_STATUS_AHEAD=" ${CYAN} ⇡ ${NC} " } "
2227SPACESHIP_GIT_STATUS_BEHIND=" ${SPACESHIP_GIT_STATUS_BEHIND=" ⇣" } "
2328SPACESHIP_GIT_STATUS_DIVERGED=" ${SPACESHIP_GIT_STATUS_DIVERGED=" ⇕" } "
2429
@@ -36,86 +41,82 @@ SPACESHIP_GIT_STATUS_DIVERGED="${SPACESHIP_GIT_STATUS_DIVERGED="⇕"}"
3641
3742# spaceship::is_git || return
3843
39- INDEX=' '
40- git_status=" "
41-
42-
43- INDEX=$( cd " $1 " && command git status --porcelain -b 2> /dev/null)
44-
45- # Check for untracked files
46- if $( echo " $INDEX " | command grep -E ' ^\?\? ' & > /dev/null) ; then
47- git_status=" $SPACESHIP_GIT_STATUS_UNTRACKED$git_status "
48- fi
49-
50- # Check for staged files
51- if $( echo " $INDEX " | command grep ' ^A[ MDAU] ' & > /dev/null) ; then
52- git_status=" $SPACESHIP_GIT_STATUS_ADDED$git_status "
53- elif $( echo " $INDEX " | command grep ' ^M[ MD] ' & > /dev/null) ; then
54- git_status=" $SPACESHIP_GIT_STATUS_ADDED$git_status "
55- elif $( echo " $INDEX " | command grep ' ^UA' & > /dev/null) ; then
56- git_status=" $SPACESHIP_GIT_STATUS_ADDED$git_status "
57- fi
58-
59- # Check for modified files
60- if $( echo " $INDEX " | command grep ' ^[ MARC]M ' & > /dev/null) ; then
61- git_status=" $SPACESHIP_GIT_STATUS_MODIFIED$git_status "
62- fi
63-
64- # Check for renamed files
65- if $( echo " $INDEX " | command grep ' ^R[ MD] ' & > /dev/null) ; then
66- git_status=" $SPACESHIP_GIT_STATUS_RENAMED$git_status "
67- fi
68-
69- # Check for deleted files
70- if $( echo " $INDEX " | command grep ' ^[MARCDU ]D ' & > /dev/null) ; then
71- git_status=" $SPACESHIP_GIT_STATUS_DELETED$git_status "
72- elif $( echo " $INDEX " | command grep ' ^D[ UM] ' & > /dev/null) ; then
73- git_status=" $SPACESHIP_GIT_STATUS_DELETED$git_status "
74- fi
75-
76- # Check for stashes
77- if $( command git rev-parse --verify refs/stash > /dev/null 2>&1 ) ; then
78- git_status=" $SPACESHIP_GIT_STATUS_STASHED$git_status "
79- fi
80-
81- # Check for unmerged files
82- if $( echo " $INDEX " | command grep ' ^U[UDA] ' & > /dev/null) ; then
83- git_status=" $SPACESHIP_GIT_STATUS_UNMERGED$git_status "
84- elif $( echo " $INDEX " | command grep ' ^AA ' & > /dev/null) ; then
85- git_status=" $SPACESHIP_GIT_STATUS_UNMERGED$git_status "
86- elif $( echo " $INDEX " | command grep ' ^DD ' & > /dev/null) ; then
87- git_status=" $SPACESHIP_GIT_STATUS_UNMERGED$git_status "
88- elif $( echo " $INDEX " | command grep ' ^[DA]U ' & > /dev/null) ; then
89- git_status=" $SPACESHIP_GIT_STATUS_UNMERGED$git_status "
90- fi
91-
92- # Check whether branch is ahead
93- is_ahead=false
94- if $( echo " $INDEX " | command grep ' ^## [^ ]\+ .*ahead' & > /dev/null) ; then
95- is_ahead=true
96- fi
97-
98- # Check whether branch is behind
99- is_behind=false
100- if $( echo " $INDEX " | command grep ' ^## [^ ]\+ .*behind' & > /dev/null) ; then
101- is_behind=true
102- fi
103-
104- # Check wheather branch has diverged
105- if [[ " $is_ahead " == true && " $is_behind " == true ]]; then
106- git_status=" $SPACESHIP_GIT_STATUS_DIVERGED$git_status "
107- else
108- [[ " $is_ahead " == true ]] && git_status=" $SPACESHIP_GIT_STATUS_AHEAD$git_status "
109- [[ " $is_behind " == true ]] && git_status=" $SPACESHIP_GIT_STATUS_BEHIND$git_status "
110- fi
111-
112- echo " $git_status "
113- # if [[ -n $git_status ]]; then
114- # # Status prefixes are colorized
115- # spaceship::section \
116- # "$SPACESHIP_GIT_STATUS_COLOR" \
117- # "$SPACESHIP_GIT_STATUS_PREFIX$git_status$SPACESHIP_GIT_STATUS_SUFFIX"
118- # fi
119- # }
120-
121- # $spaceship_git_status $1
44+ INDEX=' '
45+ git_status=" "
46+
47+ INDEX=$( cd " $1 " && command git status --porcelain -b 2> /dev/null)
48+
49+ # Check for untracked files
50+ if $( echo " $INDEX " | command grep -E ' ^\?\? ' & > /dev/null) ; then
51+ git_status=" $SPACESHIP_GIT_STATUS_UNTRACKED$git_status "
52+ fi
53+
54+ # Check for staged files
55+ if $( echo " $INDEX " | command grep ' ^A[ MDAU] ' & > /dev/null) ; then
56+ git_status=" $SPACESHIP_GIT_STATUS_ADDED$git_status "
57+ elif $( echo " $INDEX " | command grep ' ^M[ MD] ' & > /dev/null) ; then
58+ git_status=" $SPACESHIP_GIT_STATUS_ADDED$git_status "
59+ elif $( echo " $INDEX " | command grep ' ^UA' & > /dev/null) ; then
60+ git_status=" $SPACESHIP_GIT_STATUS_ADDED$git_status "
61+ fi
62+
63+ # Check for modified files
64+ if $( echo " $INDEX " | command grep ' ^[ MARC]M ' & > /dev/null) ; then
65+ git_status=" $SPACESHIP_GIT_STATUS_MODIFIED$git_status "
66+ fi
67+
68+ # Check for renamed files
69+ if $( echo " $INDEX " | command grep ' ^R[ MD] ' & > /dev/null) ; then
70+ git_status=" $SPACESHIP_GIT_STATUS_RENAMED$git_status "
71+ fi
72+
73+ # Check for deleted files
74+ if $( echo " $INDEX " | command grep ' ^[MARCDU ]D ' & > /dev/null) ; then
75+ git_status=" $SPACESHIP_GIT_STATUS_DELETED$git_status "
76+ elif $( echo " $INDEX " | command grep ' ^D[ UM] ' & > /dev/null) ; then
77+ git_status=" $SPACESHIP_GIT_STATUS_DELETED$git_status "
78+ fi
79+
80+ # Check for stashes
81+ if $( command git rev-parse --verify refs/stash > /dev/null 2>&1 ) ; then
82+ git_status=" $SPACESHIP_GIT_STATUS_STASHED$git_status "
83+ fi
84+
85+ # Check for unmerged files
86+ if $( echo " $INDEX " | command grep ' ^U[UDA] ' & > /dev/null) ; then
87+ git_status=" $SPACESHIP_GIT_STATUS_UNMERGED$git_status "
88+ elif $( echo " $INDEX " | command grep ' ^AA ' & > /dev/null) ; then
89+ git_status=" $SPACESHIP_GIT_STATUS_UNMERGED$git_status "
90+ elif $( echo " $INDEX " | command grep ' ^DD ' & > /dev/null) ; then
91+ git_status=" $SPACESHIP_GIT_STATUS_UNMERGED$git_status "
92+ elif $( echo " $INDEX " | command grep ' ^[DA]U ' & > /dev/null) ; then
93+ git_status=" $SPACESHIP_GIT_STATUS_UNMERGED$git_status "
94+ fi
95+
96+ # Check whether branch is ahead
97+ is_ahead=false
98+ if $( echo " $INDEX " | command grep ' ^## [^ ]\+ .*ahead' & > /dev/null) ; then
99+ is_ahead=true
100+ fi
101+
102+ # Check whether branch is behind
103+ is_behind=false
104+ if $( echo " $INDEX " | command grep ' ^## [^ ]\+ .*behind' & > /dev/null) ; then
105+ is_behind=true
106+ fi
107+
108+ # Check wheather branch has diverged
109+ if [[ " $is_ahead " == true && " $is_behind " == true ]]; then
110+ git_status=" $SPACESHIP_GIT_STATUS_DIVERGED$git_status "
111+ else
112+ [[ " $is_ahead " == true ]] && git_status=" $SPACESHIP_GIT_STATUS_AHEAD$git_status "
113+ [[ " $is_behind " == true ]] && git_status=" $SPACESHIP_GIT_STATUS_BEHIND$git_status "
114+ fi
115+
116+ if [[ " $2 " == " -c" ]]; then
117+ echo -e " $git_status "
118+ else
119+ echo $( echo -e " $git_status " | sed -r " s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" )
120+ fi
121+
122+
0 commit comments