summaryrefslogtreecommitdiff
path: root/vcs
blob: bb6aa905b9d4124219659f5c870920a4b8c3aa35 (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
#!/usr/bin/env sh

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

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

if git rev-parse --is-inside-work-tree &>/dev/null; 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="*"
    fi;
    if check "^Changes not staged for commit:$" "$outp"; then
        VCS_MOD="±"
    fi;
    if check "^Changes to be committed:$" "$outp"; then
        VCS_REC="↑"
    fi;
fi;

if [ -n "$VCS_STR" ]; then
    flags="$VCS_NEW$VCS_MOD$VCS_REC";
    [ -n "$flags" ] && SPC=" "
    echo "$VCS_STR{$VCS_INF$SPC$flags}"
fi;