Skip to content

Commit

Permalink
draft implementation for issue liquidprompt#110
Browse files Browse the repository at this point in the history
  • Loading branch information
jaesivsm committed Jan 19, 2014
1 parent 7f54e6d commit 9cc13dd
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ _lp_source_config()
LP_COLOR_NOWRITE=${LP_COLOR_NOWRITE:-$RED}
LP_COLOR_UP=${LP_COLOR_UP:-$GREEN}
LP_COLOR_COMMITS=${LP_COLOR_COMMITS:-$YELLOW}
LP_COLOR_COMMITS_BEHIND=${LP_COLOR_COMMITS_BEHIND:-$BOLD_RED}
LP_COLOR_CHANGES=${LP_COLOR_CHANGES:-$RED}
LP_COLOR_DIFF=${LP_COLOR_DIFF:-$PURPLE}
LP_COLOR_CHARGING_ABOVE=${LP_COLOR_CHARGING_ABOVE:-$GREEN}
Expand Down Expand Up @@ -722,14 +723,21 @@ _lp_git_branch_color()
remote="$(\git config --get branch.${branch}.remote 2>/dev/null)"

local has_commit
has_commit=0
local commit_ahead
local commit_behind
if [[ -n "$remote" ]] ; then
local remote_branch
remote_branch="$(\git config --get branch.${branch}.merge)"
if [[ -n "$remote_branch" ]] ; then
has_commit="$(\git rev-list --no-merges --count ${remote_branch/refs\/heads/refs\/remotes\/$remote}..HEAD 2>/dev/null)"
if [[ -z "$has_commit" ]] ; then
has_commit=0
commit_ahead="$(\git rev-list --no-merges --count ${remote_branch/refs\/heads/refs\/remotes\/$remote}..HEAD 2>/dev/null)"
commit_behind="$(\git rev-list --no-merges --count HEAD..${remote_branch/refs\/heads/refs\/remotes\/$remote} 2>/dev/null)"
if [[ "$commit_ahead" -ne 0 ]]; then
has_commit="${LP_COLOR_COMMITS}$commit_ahead${NO_COL}"
fi
if [[ -n "$has_commit" && "$commit_behind" -ne 0 ]] ; then
has_commit="$has_commit/${LP_COLOR_COMMITS_BEHIND}$commit_behind${NO_COL}"
elif [[ "$commit_behind" -ne 0 ]] ; then
has_commit="${LP_COLOR_COMMITS_BEHIND}-$commit_behind${NO_COL}"
fi
fi
fi
Expand Down Expand Up @@ -761,16 +769,20 @@ _lp_git_branch_color()
local has_lines
has_lines="+$i_lines/-$d_lines"

if [[ "$has_commit" -gt "0" ]] ; then
if [[ -n "$has_commit" ]] ; then
# Changes to commit and commits to push
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL},${LP_COLOR_COMMITS}$has_commit${NO_COL})"
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL},$has_commit)"
else
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL})" # changes to commit
fi
else
if [[ "$has_commit" -gt "0" ]] ; then
if [[ -n "$has_commit" ]] ; then
# some commit(s) to push
ret="${LP_COLOR_COMMITS}${branch}${NO_COL}(${LP_COLOR_COMMITS}$has_commit${NO_COL})"
if [[ "$commit_behind" -gt "0" ]]; then
ret="${LP_COLOR_COMMITS_BEHIND}${branch}${NO_COL}($has_commit)"
else
ret="${LP_COLOR_COMMITS}${branch}${NO_COL}($has_commit)"
fi
else
ret="${LP_COLOR_UP}${branch}" # nothing to commit or push
fi
Expand Down

0 comments on commit 9cc13dd

Please sign in to comment.