svn.plugin.zsh 1.14 KB
Newer Older
1

2
function svn_prompt_info {
3
    if [ $(in_svn) ]; then
4
5
6
7
8
9
10
11
12
13
14
15
16
        echo "$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_SVN_PROMPT_PREFIX\
$ZSH_THEME_REPO_NAME_COLOR$(svn_get_repo_name)$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_SVN_PROMPT_SUFFIX$ZSH_PROMPT_BASE_COLOR$(svn_dirty)$ZSH_PROMPT_BASE_COLOR"
    fi
}


function in_svn() {
    if [[ -d .svn ]]; then
        echo 1
    fi
}

function svn_get_repo_name {
17
    if [ $(in_svn) ]; then
18
        svn info | sed -n 's/Repository\ Root:\ .*\///p' | read SVN_ROOT
Drarok Ithaqua's avatar
Drarok Ithaqua committed
19

20
        svn info | sed -n "s/URL:\ .*$SVN_ROOT\///p"
21
22
23
24
    fi
}

function svn_get_rev_nr {
25
    if [ $(in_svn) ]; then
26
27
28
29
30
        svn info 2> /dev/null | sed -n s/Revision:\ //p
    fi
}

function svn_dirty_choose {
31
    if [ $(in_svn) ]; then
32
        svn status 2> /dev/null | grep -Eq '^\s*[ACDIM!?L]'
33
34
        if [ $pipestatus[-1] -eq 0 ]; then
            # Grep exits with 0 when "One or more lines were selected", return "dirty".
35
            echo $1
Drarok Ithaqua's avatar
Drarok Ithaqua committed
36
        else
37
            # Otherwise, no lines were found, or an error occurred. Return clean.
38
39
40
41
42
43
44
            echo $2
        fi
    fi
}

function svn_dirty {
    svn_dirty_choose $ZSH_THEME_SVN_PROMPT_DIRTY $ZSH_THEME_SVN_PROMPT_CLEAN
45
}