diff options
author | Michael Allen <michael@michaelallen.io> | 2015-07-24 09:50:52 +0100 |
---|---|---|
committer | Michael Allen <michael@michaelallen.io> | 2015-07-24 09:50:52 +0100 |
commit | 5e1372b1ee6b52e002c15d7b5a2575cebd7bceae (patch) | |
tree | 75bc6ebf3807aa39b923d00a33ed2c8e66f4f0a3 /git-base.sh | |
parent | 5c31b9242140877bef777dd37f0810457bd9b64a (diff) | |
download | git-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-x | git-base.sh | 41 |
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 +} |