Posts tagged ‘prompt’

Git status in zsh prompt – the easy way

Copy the completion file to your home directory:

$ cp /usr/share/git/completion/git-completion.bash ~/.git-completion.bash

Add the following to your ~/.zshrc

75
76
77
78
79
80
81
source ~/.git-completion.bash
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM="auto"
PROMPT='%{$fg[cyan]%}%n%{$fg[blue]%}@%{$fg[magenta]%}%m %{$fg[yellow]%}%~ %{$fg[red]%}$(__git_ps1 " (%s)")
%{$fg[green]%}%#%{$reset_color%} '

You may be seeing the following error in your prompt whenever you cd into a local git repository:

local:2: command not found: svn_url_pattern

As discussed here, this is due to syntactical differences between bash and zsh. Make the following changes in ~/.git-completion.bash to fix this:

--- /usr/share/git/completion/git-completion.bash 2012-03-13 10:30:26.000000000 +1100
+++ ./git-completion.bash 2012-03-26 10:22:19.957256527 +1100
@@ -94,8 +94,9 @@ __gitdir ()
__git_ps1_show_upstream ()
{
local key value
- local svn_remote=() svn_url_pattern count n
+ local svn_remote svn_url_pattern count n
local upstream=git legacy="" verbose=""
+ svn_remote=()

# get some config options from git-config
local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\n' '\n ')"
@@ -291,7 +292,7 @@ __git_ps1 ()

if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
- u="%"
+ u="!"
fi
fi