From 0a858c855845c02a7f4c32bc2a43e68449beb69d Mon Sep 17 00:00:00 2001 From: Yehor Lvivski Date: Fri, 8 Nov 2013 02:26:26 +0200 Subject: [PATCH] remove external commands --- prompt.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/prompt.sh b/prompt.sh index 9501053..589f553 100644 --- a/prompt.sh +++ b/prompt.sh @@ -91,9 +91,15 @@ function build_prompt { can_fast_forward=false commits_diff=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} 2> /dev/null) + commits_ahead=0 + commits_behind=0 - commits_ahead=$(grep -c '^<' <<< "$commits_diff") - commits_behind=$(grep -c '^>' <<< "$commits_diff") + if [[ $commits_diff =~ ^\<(..) ]]; then + commits_ahead = ${#BASH_REMATCH[@]} + fi + if [[ $commits_diff =~ ^\>(..) ]]; then + commits_behind = ${#BASH_REMATCH[@]} + fi if [[ $commits_ahead -gt 0 && $commits_behind -gt 0 ]]; then has_diverged=true