git and shell prompt

Cyrille Berger Skott cberger at cberger.net
Thu Dec 16 08:54:04 GMT 2010


Hi,

Yesterday I have introduced the commands related to branches, and I am 
expecting that really soon we will all be working with multiple branch. The 
problem is to remember in which branch you are at the moment, of course you 
can run "git branch" and you will know. But frankly, you are going to commit 
to the wrong branch more than once, unless the name of the branch is screamed 
in your face.

But with bash and zsh, it is possible to have the name of the current branch 
in the prompt (you can have other things, but for me the branch name is what 
is interesting).

For zsh, I added this to my .zshrc :


#
# VCS support
#

autoload -Uz vcs_info

precmd() {
  psvar=()
  vcs_info
  [[ -n $vcs_info_msg_0_ ]] && psvar[1]="$vcs_info_msg_0_"
}

PS1VCS=%(1v.%F{yellow}%1v%f.)


And then you just need to add $PS1VCS to your PS1 line. For instance, mine 
looks like this:

export PS1="%B%F{cyan}%T%f %F{red}%n%f%F{%{$(echo -n '\e[1;33m')%}@%f%m 
%F{green}%~%f$PS1VCS%F{%{$(echo -n '\e[1;33m')%}%%%f%b "


And I get this in my calligra prompt:
9:53 cyrille at navis 
~/Projects/kde4/src/calligra/krita/plugins/extensions/dockers (git)-[master]-% 

(with some colors :) )

I am no user of bash, but here is an example of how to achieve the same 
result: http://glandium.org/blog/?p=170 .

-- 
Cyrille Berger Skott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/calligra-devel/attachments/20101216/a117b626/attachment.htm>


More information about the calligra-devel mailing list