Skip to content

Instantly share code, notes, and snippets.

@chris
Created November 8, 2008 05:32
Show Gist options
  • Save chris/23031 to your computer and use it in GitHub Desktop.
Save chris/23031 to your computer and use it in GitHub Desktop.
zsh Git branch in your prompt
# zsh Git branch in your prompt, etc.
function precmd() {
# define colors
local RED="%{%}"
local LIGHT_RED="%{%}"
local CYAN="%{%}"
local LIGHT_CYAN="%{%}"
local BLUE="%{%}"
local LIGHT_BLUE="%{%}"
local GREEN="%{%}"
local LIGHT_GREEN="%{%}"
local MAGENTA="%{%}"
local LIGHT_MAGENTA="%{%}"
local YELLOW="%{%}"
local LIGHT_YELLOW="%{%}"
local GRAY="%{%}"
local LIGHT_GRAY="%{%}"
local ORANGE="%{%}"
local WHITE="%{%}"
local NO_COLOUR="%{%}"
git_prompt_info() {
ref=$(git-symbolic-ref HEAD 2> /dev/null) || return
echo "${ref#refs/heads/}"
}
# set the prompt (login cwd git-branch)
PS1="$GRAY%n@%m$NO_COLOUR $LIGHT_YELLOW%~$NO_COLOUR $GREEN$(git_prompt_info)$NO_COLOUR
$ "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment