Use oh-my-zsh. It is an auto-updating collection of several dozen plugins and themes that make zsh even better than it is already. Assuming that you have git installed already, it will automatically activate the git plugin, and then you're ready to go!
For those wanting something more lightweight, here's my heavily modified Zsh port of the bash prompt Gentoo came with by default when I was on it.
function parse_git_branch() {
# Speed up opening up a new terminal tab by not
# checking $HOME... which can't be a repo anyway
[ "$PWD" = "$HOME" ] && return
# Fastest way I know to check the current branch name
ref="$(command git symbolic-ref --short HEAD 2> /dev/null)" || return
echo " [$ref]"
}
prompt_gentoo_precmd() {
path_prompt="%B%F{blue}%1~$(parse_git_branch)"
PS1="$base_prompt$path_prompt $pre_prompt%# $post_prompt"
PS2="$base_prompt$path_prompt $pre_prompt%_> $post_prompt"
PS3="$base_prompt$path_prompt $pre_prompt?# $post_prompt"
}
prompt_gentoo_setup () {
base_prompt="%k%B%(!.%F{red}.%F{green}%n@)%m "
pre_prompt="%(0?..%F{yellow})%(1j.%%.)"
post_prompt="%b%f%k"
precmd_functions+='prompt_gentoo_precmd'
}
Use the
vcs_info
function in the zsh user contributions (included in thezsh
package). Quick start:It's likely that you'll want to make the output prettier. Since that's matter of personal taste, I refer you to the examples in the documentation.
Use oh-my-zsh. It is an auto-updating collection of several dozen plugins and themes that make
zsh
even better than it is already. Assuming that you havegit
installed already, it will automatically activate the git plugin, and then you're ready to go!For those wanting something more lightweight, here's my heavily modified Zsh port of the bash prompt Gentoo came with by default when I was on it.