summaryrefslogtreecommitdiff
path: root/_posts/2008-06-26-git-branch-everywhere.textile
blob: 1c32000fe8de61111e7f69e0f9b3133d78a07ab7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
---
layout: post
category: app
title: Git branch everywhere
---

The current trend is to have the name of the current git branch everywhere. Personnaly I display it in my vim's status bar, and in my zsh prompt.

Here is my vimrc configuration for this (I'm not the author of this function, and can't remember where I saw it first):

{% highlight bash %}
set statusline=%<[%n]%m%r%h%w%{'['.(&fenc!=''?&fenc:&enc).':'.&ff}%{g:gitCurrentBranch}%{']'}%y\ %F%=%l,%c%V%8P
autocmd BufEnter * :call CurrentGitBranch()

let g:gitCurrentBranch = ''
function! CurrentGitBranch()
    let cwd = getcwd()
    cd %:p:h
    let branch = matchlist(system('/usr/local/git/bin/git  branch -a --no-color'), '\v\* (\w*)\r?\n')
    execute 'cd ' . cwd
    if (len(branch))
        let g:gitCurrentBranch = '][git:' . branch[1] . ''
    else
        let g:gitCurrentBranch = ''
    endif
    return g:gitCurrentBranch
endfunction
{% endhighlight %}

and my zshrc:

{% highlight bash %}
local git_b
git_b='$(get_git_prompt_info '%b')'
PROMPT="%(?..%U%?%u:) $git_b %40<...<%/%(#.%U>%u.%B>%b) "
{% endhighlight %}

with the following script "S55_git":http://www.jukie.net/~bart/conf/zsh.d/S55_git