Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bash prompt fixes

  • Loading branch information...
commit c2277371f346f65253539d29f2a4620a4c0ea364 1 parent 57925a8
@gabesoft authored
Showing with 26 additions and 4 deletions.
  1. +25 −3 .bashrc
  2. +1 −1  .gitconfig
View
28 .bashrc
@@ -153,10 +153,32 @@ source ~/.dirs # Initialization for the above 'save' facility: source the .sdir
shopt -s cdable_vars # set the bash option so that no '$' is required when using the above facility
# --------------------------------------------------------------------------------
-# prompt: show git branch
+# prompt: show git branch and status
# --------------------------------------------------------------------------------
-export PS1="\[${COLOR_BROWN}\]\w\[${COLOR_CYAN}\]\$(__git_ps1)\[${COLOR_RED}\]> \[${COLOR_NC}\]"
-export PROMPT_COMMAND='echo -ne "\033]0;${PWD/$HOME/~}\007"'
+function _git_prompt() {
+ local git_status="`git status -unormal 2>&1`"
+ if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
+ if [[ "$git_status" =~ nothing\ to\ commit ]]; then
+ local branch_color=$COLOR_CYAN
+ elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
+ local branch_color=$COLOR_PURPLE
+ else
+ local branch_color=$COLOR_RED
+ fi
+ if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then
+ branch=${BASH_REMATCH[1]}
+ else
+ # Detached HEAD. (branch=HEAD is a faster alternative.)
+ branch="(`git describe --all --contains --abbrev=4 HEAD 2> /dev/null ||
+ echo HEAD`)"
+ fi
+ echo -n '\['"$branch_color"'\]'"$branch"
+ fi
+}
+function _prompt_command() {
+ PS1="\[${COLOR_BROWN}\]\w\[${COLOR_CYAN}\] (`_git_prompt`\[${COLOR_CYAN}\])\[${COLOR_RED}\]> \[${COLOR_NC}\]"
+}
+PROMPT_COMMAND=_prompt_command
# --------------------------------------------------------------------------------
# colors
View
2  .gitconfig
@@ -8,7 +8,7 @@
rs = rm --cached ; delete from staging
st = status
ci = commit -av
- br = checkout -b
+ br = checkout -b ; create a new branch and switch to it
ms = checkout master
mg = merge
ch = diff --name-status -r
Please sign in to comment.
Something went wrong with that request. Please try again.