summaryrefslogtreecommitdiff
path: root/vcs
blob: 4802fff8ab1dd4cbcb066e0c23b64ce5e821f81d (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env sh

check() {
    echo "$2" | grep -q "$1";
};

VCS_STR=""
VCS_INF=""
VCS_NEW=""
VCS_MOD=""
VCS_REC=""
SPC=""

if [ "$1" = "--zsh-colour" ]; then
    nstr="%F{red}●%f"
    mstr="%F{11}●%f"
    rstr="%F{28}●%f"
    cFST="%F{green}"
    cSND="%F{blue}"
    cEND="%f"
else
    nstr="@"
    mstr="±"
    rstr="↑"
    cFST=""
    cSND=""
    cEND=""
fi

if [ -d ".git" ] || [ -d "../.git" ] || [ -d "../../.git" ]; then
    outp=$(git status)
    VCS_STR="*"
    VCS_INF=$(echo "$outp" | head -n 1 | cut -d' ' -f 3-)
    if check "^Untracked files:$" "$outp"; then
        VCS_NEW=$nstr
    fi;
    if check "^Changes not staged for commit:$" "$outp"; then
        VCS_MOD=$mstr
    fi;
    if check "^Changes to be committed:$" "$outp"; then
        VCS_REC=$rstr
    fi;
elif [ -d "_darcs" ] || [ -d "../_darcs" ] || [ -d "../../_darcs" ]; then
    fls=$(darcs show files)
    VCS_STR="+"
    VCS_INF=$(darcs show repo | grep Default | cut -d : -f 3-)
    for f in ./*; do
        if [ -f "$f" ]; then
            echo "$fls" | grep -q "$f"
        else
            true
        fi;
        if [ ! $? = 0 ]; then
            VCS_NEW=$nstr;
            break;
        fi;
    done;
    news=$(darcs what)$
    if check "^No changes" "$news"; then
        true
    else
        VCS_REC=$rstr;
    fi;
   
fi;

[ -n "$VCS_NEW$VCS_MOD$VCS_REC" ] && SPC=" "
[ -n "$VCS_STR" ] && echo "$cFST$VCS_STR$cEND{$cSND$VCS_INF$cEND$SPC$VCS_NEW$VCS_MOD$VCS_REC}"