summaryrefslogtreecommitdiffstats
path: root/git-base.sh
diff options
context:
space:
mode:
authorMichael Allen <michael@michaelallen.io>2015-07-24 09:50:52 +0100
committerMichael Allen <michael@michaelallen.io>2015-07-24 09:50:52 +0100
commit5e1372b1ee6b52e002c15d7b5a2575cebd7bceae (patch)
tree75bc6ebf3807aa39b923d00a33ed2c8e66f4f0a3 /git-base.sh
parent5c31b9242140877bef777dd37f0810457bd9b64a (diff)
downloadgit-sonar-5e1372b1ee6b52e002c15d7b5a2575cebd7bceae.tar.gz
git-sonar-5e1372b1ee6b52e002c15d7b5a2575cebd7bceae.zip
remove colors and use them in a function so that it isn't tied down to ZSH
Diffstat (limited to 'git-base.sh')
-rwxr-xr-xgit-base.sh41
1 files changed, 36 insertions, 5 deletions
diff --git a/git-base.sh b/git-base.sh
index 9152caf..917e46b 100755
--- a/git-base.sh
+++ b/git-base.sh
@@ -177,11 +177,6 @@ remote_ahead_of_master() {
#them="\xE2\x83\x96%{$reset_color%}"
#both="\xE2\x83\xA1%{$reset_color%}"
-staged="%{$fg_bold[green]%}"
-unstaged="%{$fg_bold[red]%}"
-conflicted="%{$fg_bold[yellow]%}"
-untracked="%{$fg_bold[white]%}"
-
is_dirty() {
if ! git rev-parse &> /dev/null; then
#not in repo, thus not dirty
@@ -302,3 +297,39 @@ untracked_status() {
fi
echo "$untracked_string"
}
+
+zsh_color_changes_status() {
+ local porcelain="$(porcelain_status)"
+ local changes=""
+
+ if [[ -n "$porcelain" ]]; then
+ local staged_prefix="%{$fg_bold[green]%}"
+ local unstaged_prefix="%{$fg_bold[red]%}"
+ local conflicted_prefix="%{$fg_bold[yellow]%}"
+ local untracked_prefix="%{$fg_bold[white]%}"
+ local suffix="%{$reset_color%}"
+
+ local staged_changes="$(staged_status "$porcelain")"
+ local unstaged_changes="$(unstaged_status "$porcelain")"
+ local untracked_changes="$(untracked_status "$porcelain")"
+ local conflicted_changes="$(conflicted_status "$porcelain")"
+ if [[ -n "$staged_changes" ]]; then
+ staged_changes=" $staged_changes"
+ fi
+
+ if [[ -n "$unstaged_changes" ]]; then
+ unstaged_changes=" $unstaged_changes"
+ fi
+
+ if [[ -n "$conflicted_changes" ]]; then
+ conflicted_changes=" $conflicted_changes"
+ fi
+
+ if [[ -n "$untracked_changes" ]]; then
+ untracked_changes=" $untracked_changes"
+ fi
+
+ changes="$staged_changes$conflicted_changes$unstaged_changes$untracked_changes"
+ fi
+ echo $changes
+}