Display your current git branch as part of your bash prompt
gist.github.com
gist.github.com
My prompt shows the git branch, svn revision, and active virtualenv ("workon" and "deactivate" are virtualenv commands in the screenshot below). Also, mine has COLORS! (Colors within the dynamic function are much harder than they sound)
Here's a quick screenshot: http://img.skitch.com/20090817-gtp7bgkmdn14j84ryhepa2edke.pn...
You can extend it pretty easily to show whatever you want by doing little more than adding another function. Throw this into ~/.profile if you want to try it: http://pastebin.com/f79a9af51
Barring that, logging out and back in will definitely fix it, as long as you didn't put it in one of your bash config files.
Had I known about `git symbolic-ref`, I might have used that instead of `git branch`. On the other hand, I would have needed to re-implement lots of what `git branch` does, such as detecting the difference between not being in a git repository and simply not being on a branch.
The interface of `git branch` seems stable enough that I doubt it will break this. If it does, it should take me no longer than 5 minutes to fix, since that's about how long it would take me to re-write the whole thing from scratch.
Is there any particular reason that using `git symbolic-ref` is better than `git branch` in this case, given that I want human-readable output, instead an unambiguous filesystem location?
For the case of not being on a branch, the output of 'git branch' is not very useful. I am currently using 'git name-rev --name-only HEAD', but the contrib script has an even fancier mechanism (via 'git describe') for coming up with something to display when HEAD isn't a symbolic ref.
export PS1='\w:$(__git_ps1 "%s")$ '
EDIT - here's mine btw: function parse_git_dirty {
git diff --quiet HEAD &>/dev/null
[[ $? == 1 ]] && echo "✎ " || echo "➜ "
}
function parse_git_branch {
local branch=$(__git_ps1 "%s")
[[ $branch ]] && echo "$branch$(parse_git_dirty)"
}
PS1='\u@\h $(parse_git_branch)\W $ '
If the branch has local changes it shows the pencil, in addition to the branch name. I'm still experimenting.The OP is an example of wheel reinvented, poorly.
http://img40.imageshack.us/img40/3738/zsh2.png - this shows a regular svn repo
This is what you need in your zshrc
# precmd is called just before the prompt is printed function precmd() { title “zsh” “$USER@%m” “%55<…<%~” psvar=() vcs_info [[ -n $vcs_info_msg_0_ ]] && psvar[1]=”$vcs_info_msg_0_” }
vcs_info export RPS1=”${YELLOW}%1v${NORM}”
Been using it for a while now. ;-)
It was based on this which I thought was too ugly: http://www.simplisticcomplexity.com/2008/03/13/show-your-git...
Also, if you use git+github+capistrano, I wrote a bash script where you type "tap" and it will add all new files, commit, push to github. If you type "tap /d" it will also cap deploy it to the server and reload in nginx passenger. For small projects I'll push something and then have to make a small change. Now I can just edit the file in textmate and can add-commit-push-deploy with one command.
Also, display your current branch in mercurial repos: http://stevelosh.com/blog/entry/2009/3/17/mercurial-bash-pro...