Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
My zsh prompt. No oh-my-zsh needed
## Find my full .zshrc at <>.
# setup
autoload colors; colors;
export LSCOLORS="Gxfxcxdxbxegedabagacad"
setopt prompt_subst
# prompt
# show git branch/tag, or name-rev if on detached head
parse_git_branch() {
(command git symbolic-ref -q HEAD || command git name-rev --name-only --no-undefined --always HEAD) 2>/dev/null
# show red star if there are uncommitted changes
parse_git_dirty() {
if command git diff-index --quiet HEAD 2> /dev/null; then
# if in a git repo, show dirty indicator + git branch
git_custom_status() {
local git_where="$(parse_git_branch)"
[ -n "$git_where" ] && echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX${git_where#(refs/heads/|tags/)}$ZSH_THEME_GIT_PROMPT_SUFFIX"
# show current rbenv version if different from rbenv global
rbenv_version_status() {
local ver=$(rbenv version-name)
[ "$(rbenv global)" != "$ver" ] && echo "[$ver]"
# put fancy stuff on the right
if which rbenv &> /dev/null; then
RPS1='$(git_custom_status)%{$fg[red]%}$(rbenv_version_status)%{$reset_color%} $EPS1'
RPS1='$(git_custom_status) $EPS1'
# basic prompt on the left
PROMPT='%{$fg[cyan]%}%~% %(?.%{$fg[green]%}.%{$fg[red]%})%B$%b '

Wow! nice! Any chance we can reproduce this on bash?

Nvm, this was just the nudge I need to switch to zsh.

Nemo157 commented Sep 6, 2012

Hmm, can't quite reproduce this using vcs_info (see man zshcontrib), seems it considers untracked files to not be unstaged and it doesn't support tags. It does distinguish between staged and unstaged changes though.

autoload -Uz vcs_info

zstyle ':vcs_info:*:prompt:*'     check-for-changes true
zstyle ':vcs_info:*:prompt:*'     stagedstr         "%{$fg[green]%}*%{$reset_color%}"
zstyle ':vcs_info:*:prompt:*'     unstagedstr       "%{$fg[red]%}*%{$reset_color%}"
zstyle ':vcs_info:*:prompt:*'     branchformat      "%r"
zstyle ':vcs_info:*:prompt:*'     formats           "%u%c%{$fg[green]%}[%b]%{$reset_color%}"
zstyle ':vcs_info:*:prompt:*'     nvcsformats       ""



buley commented Jan 29, 2013

Ran into an issue with this where I needed to source from within a directory to get git info about it. That info would then follow me around regardless of what directory I was in.

Makes sense, but unworkable for me as a oh-my-zsh-free git prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment