From 87c8f642278cf82e9c9011413624b64a878b23a9 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 6 Aug 2015 09:49:57 +0100 Subject: Provide example of local commit difference --- git-base.sh | 26 ++++++++++++++++++++++++++ prompt.sh | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/git-base.sh b/git-base.sh index e60f9fc..aca271b 100755 --- a/git-base.sh +++ b/git-base.sh @@ -369,3 +369,29 @@ zsh_color_changes_status() { fi echo $changes } + +zsh_color_local_commits() { + local ahead_arrow="%{$fg_bold[green]%}↑%{$reset_color%}" + local behind_arrow="%{$fg_bold[red]%}↓%{$reset_color%}" + local diverged_arrow="%{$fg_bold[yellow]%}⇵%{$reset_color%}" + + local local_commits="" + if is_repo; then + + if remote_branch="$(remote_branch_name)"; then + local_ahead="$(commits_ahead_of_remote "$remote_branch")" + local_behind="$(commits_behind_of_remote "$remote_branch")" + remote_ahead="$(remote_ahead_of_master "$remote_branch")" + remote_behind="$(remote_behind_of_master "$remote_branch")" + + if [[ "$local_behind" -gt "0" && "$local_ahead" -gt "0" ]]; then + local_commits=" $local_behind$diverged_arrow$local_ahead" + elif [[ "$local_behind" -gt "0" ]]; then + local_commits=" $local_behind$behind_arrow" + elif [[ "$local_ahead" -gt "0" ]]; then + local_commits=" $local_ahead$ahead_arrow" + fi + fi + fi + echo $local_commits +} diff --git a/prompt.sh b/prompt.sh index 82155fb..5fd8b27 100755 --- a/prompt.sh +++ b/prompt.sh @@ -18,6 +18,6 @@ else local_behind="" fi -prompt="$(branch_name)$local_behind$local_ahead $(bash_color_changes_status)" +prompt="$(branch_name) $(zsh_color_local_commits) $(bash_color_changes_status)" echo $prompt -- cgit v1.2.3