From 5e1372b1ee6b52e002c15d7b5a2575cebd7bceae Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 24 Jul 2015 09:50:52 +0100 Subject: remove colors and use them in a function so that it isn't tied down to ZSH --- git-base.sh | 41 ++++++++++++++++++++++++++++++++++++----- prompt.sh | 2 +- 2 files changed, 37 insertions(+), 6 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 +} diff --git a/prompt.sh b/prompt.sh index 99ac6b3..0828b5e 100755 --- a/prompt.sh +++ b/prompt.sh @@ -18,6 +18,6 @@ else local_behind="" fi -prompt="$(branch_name)$local_ahead$local_behind" +prompt="$(branch_name)$local_behind$local_ahead $(zsh_color_changes_status)" echo $prompt -- cgit v1.2.3