git: bash-completion
July 4th, 2011 — 06:10 pmLooking for a way to easyly know if there’s something changed on my git repos I found out that git itself ships a bash script that perfectly satisfy my needs.
Introducing: __git_ps1
Usage:
Include a call to __git_ps1 in your promt string (for example in bash):
PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
This will show the current branch on your prompt.
Customization:
__git_ps1 allows to customize its output using environment variables. Here is a list of avaliable options:
- GIT_PS1_SHOWDIRTYSTATE. When set to something not empty, __git_ps1 will display unstaged (*) and staged (+) next to the branch name.
- GIT_PS1_SHOWSTASHSTATE. When set to something no empty, __git_ps1 will display $ next to the branch name when something is staged.
- GIT_PS1_SHOWUNTRACKEDFILES. When set to something no empty, __git_ps1 will display % next to the branch name when there’re untracked files.
- GIT_PS1_SHOWUPSTREAM. This cat take several (comma separated) values: auto, verbose, legacy, git and svn. __git_ps1 will show the difference between HEAD and its upstream.
Export them if your shell dotfile before calling __git_ps1.