summaryrefslogtreecommitdiffstats
path: root/bashrc
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-12-10 20:14:28 -0600
committerJesse Luehrs <doy@tozt.net>2009-12-10 20:14:28 -0600
commit724683faf1e079e1adb31bd5f4eaaa6342441b0d (patch)
tree11cee9aa65665a1984c96b9acaff71cfb79acbc0 /bashrc
parentd71c8987ce6d65c91b3a0747b498fbe95eca01f7 (diff)
downloadconf-724683faf1e079e1adb31bd5f4eaaa6342441b0d.tar.gz
conf-724683faf1e079e1adb31bd5f4eaaa6342441b0d.zip
add number of unmerged/unpushed commits to prompt
Diffstat (limited to 'bashrc')
-rw-r--r--bashrc28
1 files changed, 22 insertions, 6 deletions
diff --git a/bashrc b/bashrc
index 1e4942e..be55792 100644
--- a/bashrc
+++ b/bashrc
@@ -181,6 +181,7 @@ function _set_vcs {
local vcs_branch
local vcs_dir
local vcs_state
+ local vcs_local_commits
__vcs=''
function _find_upwards {
local pwd
@@ -224,16 +225,28 @@ function _set_vcs {
vcs_branch=
;;
git)
- vcs_dir=$(git rev-parse --git-dir)
+ local git_dir
+ local git_base
+ git_dir=$(git rev-parse --git-dir)
vcs_dirty=$(git status -a > /dev/null 2>&1; echo $?)
- vcs_branch=$(git symbolic-ref -q HEAD 2>/dev/null || git rev-parse --short HEAD)
- if [[ -e "${vcs_dir}/MERGE_HEAD" ]]; then
+ vcs_branch=$(git symbolic-ref -q HEAD 2>/dev/null)
+ if [[ -z "${vcs_branch}" ]]; then
+ vcs_branch=$(git rev-parse --short HEAD)
+ else
+ vcs_branch=${vcs_branch#refs/heads/}
+ git_base=$(git merge-base HEAD origin/$vcs_branch)
+ if [[ "${git_base}" == "$(git rev-parse HEAD)" ]]; then
+ vcs_local_commits="-$(git rev-list HEAD..origin/$vcs_branch | wc -l)"
+ else
+ vcs_local_commits="+$(git rev-list origin/${vcs_branch}..HEAD | wc -l)"
+ fi
+ fi
+ if [[ -e "${git_dir}/MERGE_HEAD" ]]; then
vcs_state='merge'
fi
- if [[ -d "${vcs_dir}/rebase-apply" || -d "${vcs_dir}/rebase-merge" ]]; then
+ if [[ -d "${git_dir}/rebase-apply" || -d "${git_dir}/rebase-merge" ]]; then
vcs_state='rebase'
fi
- vcs_branch=${vcs_branch#refs/heads/}
if [[ "x$vcs_branch" == "xmaster" ]]; then
vcs_branch=''
fi
@@ -251,7 +264,10 @@ function _set_vcs {
if [[ -n "$vcs_state" ]]; then
vcs_state="(${vcs_state:0:1})"
fi
- __vcs="(${vcs:0:1}${vcs_dirty}${vcs_branch}${vcs_state})"
+ if [[ "$vcs_local_commits" == "-0" ]]; then
+ vcs_local_commits=''
+ fi
+ __vcs="(${vcs:0:1}${vcs_dirty}${vcs_branch}${vcs_local_commits}${vcs_state})"
}
export PROMPT_COMMAND="_set_error;_set_vcs;$PROMPT_COMMAND"
export PS1="\[\$__error_color\]\$__error \[${HIYELLOW}\][\t] \[${HIGREEN}\]\u@\h \[${HIBLUE}\]\W\[${CYAN}\]\$__vcs \[${HIBLUE}\]\\$\[${NORM}\] "