summaryrefslogtreecommitdiffstats
path: root/git-base.sh
diff options
context:
space:
mode:
authorMichael Allen <michael@michaelallen.io>2015-08-11 19:54:34 +0100
committerMichael Allen <michael@michaelallen.io>2015-08-11 19:56:29 +0100
commit253e0090fb62f0a130c48e1f965749827db213ab (patch)
treef08ebbd9b557f9cf73c47daae88836841fe561a8 /git-base.sh
parent98e9081cd75adaf58ca7ccac721e99eb88044cdd (diff)
downloadgit-sonar-253e0090fb62f0a130c48e1f965749827db213ab.tar.gz
git-sonar-253e0090fb62f0a130c48e1f965749827db213ab.zip
Example of how to use the git-base.sh library
Diffstat (limited to 'git-base.sh')
-rwxr-xr-xgit-base.sh25
1 files changed, 25 insertions, 0 deletions
diff --git a/git-base.sh b/git-base.sh
index 87ad2cc..81616a5 100755
--- a/git-base.sh
+++ b/git-base.sh
@@ -444,3 +444,28 @@ bash_color_remote_commits() {
printf %s "$remote"
}
+
+zsh_color_remote_commits() {
+ local remote_master="\xF0\x9D\x98\xAE" # an italic m to represent master
+ local green_ahead_arrow="%{$fg_bold[green]%}←%{$reset_color%}"
+ local red_behind_arrow="%{$fg_bold[red]%}→%{$reset_color%}"
+ local yellow_diverged_arrow="%{$fg_bold[yellow]%}⇄%{$reset_color%}"
+ local not_upstream="%{$fg_bold[red]%}⚡%{$reset_color%}"
+
+ if remote_branch="$(remote_branch_name)"; then
+ remote_ahead="$(remote_ahead_of_master "$remote_branch")"
+ remote_behind="$(remote_behind_of_master "$remote_branch")"
+
+ if [[ "$remote_behind" -gt "0" && "$remote_ahead" -gt "0" ]]; then
+ remote="$remote_master $remote_behind $yellow_diverged_arrow $remote_ahead "
+ elif [[ "$remote_ahead" -gt "0" ]]; then
+ remote="$remote_master $green_ahead_arrow $remote_ahead "
+ elif [[ "$remote_behind" -gt "0" ]]; then
+ remote="$remote_master $remote_behind $red_behind_arrow "
+ fi
+ else
+ remote="upstream $not_upstream "
+ fi
+
+ printf %s "$remote"
+}