Permalink
Browse files

fixed branch prompt for reload

  • Loading branch information...
1 parent e8b5b3e commit f576c793646b417fec738f70d7a67abcd0eb0d9e @roald committed Jan 26, 2012
Showing with 49 additions and 5 deletions.
  1. +49 −5 bash/branch.sh
View
@@ -1,7 +1,51 @@
-# Default Git enabled prompt
-export GIT_PS1_SHOWDIRTYSTATE=true # '*' for unstaged changes, '+' for staged
-export GIT_PS1_SHOWSTASHSTATE=true # '$' if smth is stashed
-export GIT_PS1_SHOWUNTRACKEDFILES=true # '%' if un-tracked files
+# Functions to determine Git branch and status
+
+function parse_git_branch {
+ git rev-parse --git-dir &> /dev/null
+ git_status="$(git status 2> /dev/null)"
+ branch_pattern="^# On branch ([^${IFS}]*)"
+ remote_pattern="# Your branch is (.*) of"
+ diverge_pattern="# Your branch and (.*) have diverged"
+ if [[ ! ${git_status}} =~ "working directory clean" ]]; then
+ state=" *"
+ fi
+ # add an else if or two here if you want to get more specific
+ if [[ ${git_status} =~ ${remote_pattern} ]]; then
+ if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
+ remote=" ${txtgrn}"
+ else
+ remote=" ${txtblu}"
+ fi
+ fi
+ if [[ ${git_status} =~ ${diverge_pattern} ]]; then
+ remote=" ${txtblu}"
+ fi
+ if [[ ${git_status} =~ ${branch_pattern} ]]; then
+ branch=${BASH_REMATCH[1]}
+ echo " (${branch}${state}${remote}${txtred})"
+ fi
+}
+
+function prompt_func() {
+ previous_return_value=$?;
+ #prompt="\[$txtgrn\]\u: \[$txtrst\]\w\[$txtred\]$(__git_ps1)\[$txtrst\]"
+ prompt="\[$txtgrn\]\u: \[$txtrst\]\w\[$txtred\]$(parse_git_branch)\[$txtrst\]"
+ if test $previous_return_value -eq 0
+ then
+ PS1="${prompt} $ "
+ else
+ PS1="${prompt} ${txtred}${txtrst} "
+ fi
+}
-export PS1="\[$txtgrn\]\u\[$txtrst\]: \w\[$txtred\]$(__git_ps1)\[$txtrst\] \$ "
+PROMPT_COMMAND=prompt_func
+
+
+# Default Git enabled prompt
+#source ~/.dotfiles/bash/git-completion.sh
+#export GIT_PS1_SHOWDIRTYSTATE=true
+#export GIT_PS1_SHOWSTASHSTATE=true
+#export GIT_PS1_SHOWUNTRACKEDFILES=true
+#export PS1="\[$txtgrn\]\u\[$txtrst\]: \w\[$txtred\] $(__git_ps1)\[$txtrst\] \$ "
+#export PS1="\[$txtgrn\]\u\[$txtrst\]: \w\[$txtred\] $(parse_git_branch)\[$txtrst\] \$ "

0 comments on commit f576c79

Please sign in to comment.