Thursday, January 14, 2010

How to use git-completion on my openSUSE #2

(continued from phosphorescence: How to use git-completion on my openSUSE #1)

There are one more tips to use git-completion.bash conveniently. That is a PS1 hack. The way is written in git-completion.bash like below:
# 3) Consider changing your PS1 to also show the current branch:
# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
# The argument to __git_ps1 will be displayed only if you
# are currently in a git repository. The %s token will be
# the name of the current branch.

So I rewrite /etc/bash.bashrc.local to rewrite PS1, using bash's regexp.
test -s /etc/git-completion.bash && . /etc/git-completion.bash
[[ "$PS1" =~ ^(.*)(>|#|\$)(.*?)$ ]] && PS1="${BASH_REMATCH[1]}\$(__git_ps1)${BASH_REMATCH[2]}${BASH_REMATCH[3]}"

Then command prompt becomes git-completion.bash ready.

No comments:

Post a Comment