Merge pull request #183 from dolmen/optimize/git
More Git optimizations
This commit is contained in:
commit
e10595144a
37
liquidprompt
37
liquidprompt
@ -691,11 +691,11 @@ _lp_git_branch()
|
|||||||
local branch="$(git symbolic-ref HEAD 2>/dev/null)"
|
local branch="$(git symbolic-ref HEAD 2>/dev/null)"
|
||||||
if [[ $? -ne 0 || -z "$branch" ]] ; then
|
if [[ $? -ne 0 || -z "$branch" ]] ; then
|
||||||
# In detached head state, use commit instead
|
# In detached head state, use commit instead
|
||||||
branch="$(git rev-parse --short HEAD 2>/dev/null)"
|
# No escape needed
|
||||||
|
git rev-parse --short HEAD 2>/dev/null
|
||||||
|
else
|
||||||
|
_lp_escape "${branch#refs/heads/}"
|
||||||
fi
|
fi
|
||||||
[[ $? -ne 0 || -z "$branch" ]] && return
|
|
||||||
branch="${branch#refs/heads/}"
|
|
||||||
echo $(_lp_escape "$branch")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set a color depending on the branch state:
|
# Set a color depending on the branch state:
|
||||||
@ -712,14 +712,6 @@ _lp_git_branch_color()
|
|||||||
branch=$(_lp_git_branch)
|
branch=$(_lp_git_branch)
|
||||||
if [[ -n "$branch" ]] ; then
|
if [[ -n "$branch" ]] ; then
|
||||||
|
|
||||||
local GD
|
|
||||||
git diff --quiet >/dev/null 2>&1
|
|
||||||
GD=$?
|
|
||||||
|
|
||||||
local GDC
|
|
||||||
git diff --cached --quiet >/dev/null 2>&1
|
|
||||||
GDC=$?
|
|
||||||
|
|
||||||
local end="$NO_COL"
|
local end="$NO_COL"
|
||||||
if git status 2>/dev/null | grep -q '\(# Untracked\)'; then
|
if git status 2>/dev/null | grep -q '\(# Untracked\)'; then
|
||||||
end="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED$end"
|
end="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED$end"
|
||||||
@ -744,24 +736,29 @@ _lp_git_branch_color()
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ "$GD" -eq 1 || "$GDC" -eq "1" ]] ; then
|
|
||||||
local has_line
|
local shortstat=$(LANG=C git diff --shortstat 2>/dev/null)
|
||||||
has_lines=$(git diff --numstat 2>/dev/null | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d/-%d\n", plus, minus)}')
|
if [[ -n "$shortstat" ]] ; then
|
||||||
|
#has_lines=$(git diff --numstat 2>/dev/null | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d/-%d\n", plus, minus)}')
|
||||||
|
local has_lines=${shortstat/*changed, /+}
|
||||||
|
has_lines=${has_lines/ insertions(+), /\/-}
|
||||||
|
has_lines=${has_lines/ del*/}
|
||||||
|
|
||||||
if [[ "$has_commit" -gt "0" ]] ; then
|
if [[ "$has_commit" -gt "0" ]] ; then
|
||||||
# Changes to commit and commits to push
|
# 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})${end}"
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL},${LP_COLOR_COMMITS}$has_commit${NO_COL})"
|
||||||
else
|
else
|
||||||
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL})${end}" # changes to commit
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL})" # changes to commit
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ "$has_commit" -gt "0" ]] ; then
|
if [[ "$has_commit" -gt "0" ]] ; then
|
||||||
# some commit(s) to push
|
# some commit(s) to push
|
||||||
ret="${LP_COLOR_COMMITS}${branch}${NO_COL}(${LP_COLOR_COMMITS}$has_commit${NO_COL})${end}"
|
ret="${LP_COLOR_COMMITS}${branch}${NO_COL}(${LP_COLOR_COMMITS}$has_commit${NO_COL})"
|
||||||
else
|
else
|
||||||
ret="${LP_COLOR_UP}${branch}${end}" # nothing to commit or push
|
ret="${LP_COLOR_UP}${branch}" # nothing to commit or push
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo -ne "$ret"
|
echo -ne "$ret$end"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user