ftblog

:: widerstand zwecklos ::
email jabber gpgkey
hackergotchi

September 17, 2008

VCSs+PS1

Filed under: computer -- 13:43

[Update]

It seems like vcs_info will be in the official zsh cvs repository pretty soon.
Due to some comments, that arose in reply to my submission, I did change one
or the other thing; most notably, the exported variables are now named
'${vcs_info_msg_N_}'. The behaviour of the 'disable' and 'enable' styles
changed a bit, too.

All of this is documented in 'zshcontrib' once the patch makes it into the
main repository. Including a small Quickstart section.

The features, shown below are still all there. The code just won't work, if
merely cut'n'pasted with the vcs_info version, that will be shipped with zsh.

I blogged about this before, but I removed the posting, as a lot in the
posting got inaccurate because the code changed quite a bit since.

I won't go into details this time, I'll just show off the feature a little.
Consider using the following .zshrc or sourced from 'zsh -f', with vcs_info
installed in ~/etc/zsh/functions (adjust to your directory if you want to
try this):

bindkey -e
fpath=( ~/etc/zsh/functions $fpath )
setopt promptsubst

autoload -Uz vcs_info && vcs_info

RED=$'%{\e[31m%}'
GR=$'%{\e[32m%}'
MA=$'%{\e[35m%}'
YE=$'%{\e[33m%}'
NC=$'%{\e[0m%}'

zstyle ':vcs_info:*' actionformats \
    " ${MA}[${GR}%b${YE}|${RED}%a${MA}]${NC}" \
    "${MA}(${GR}%s${MA})${NC}"

zstyle ':vcs_info:*' formats \
    " ${MA}[${GR}%b${MA}]${NC}" \
    "${MA}(${GR}%s${MA})${NC}"

zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b${RED}:${YE}%r"

precmd () { vcs_info }

PS1="${YE}%2~"'${VCS_INFO_message_0_}'"${NC}%# "
RPROMPT=' ${VCS_INFO_message_1_}'

Now, let's surf through a bunch of directories, that are under version
control by different systems. And that looks something like this:

vcs_info

I'm finding this rather useful. You can get different behaviour for each
VCS, for different repositories and more.

I'm planning to submit this to zsh for inclusion. If it gets accepted,
people get this without fiddeling with my zsh setup tarball. :-)

Powered by zblog
valid css | valid xhtml | utf-8 encoded | best viewed with anybrowser