summaryrefslogtreecommitdiff
path: root/i3/.config/i3blocks/bin/repos
blob: 48b8b279d6a39695908603146e1108397dc8594c (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
#!/usr/bin/env bash

color_changes() {
    if [[ $1 -gt 100 ]]; then
        echo 'red'
    elif [[ $1 -gt 10 ]]; then
        echo 'yellow'
    elif [[ $1 -gt 0 ]]; then
        echo 'lightgreen'
    else
        echo 'gray'
    fi
}

if command -v mr > /dev/null; then
    total_changes=0
    for title_dir in $BLOCK_INSTANCE; do
        title="${title_dir%:*}"
        cd "${title_dir##*:}" || exit
        n_changes=$(mr status | grep -vc "^$\\|^mr")
        [[ n_changes -gt total_changes ]] && total_changes=n_changes
        color=$(color_changes "$n_changes")
        output+="$sep$title:<span color='$color'>$n_changes</span>"
        sep=" - "
    done
    color_label=$(color_changes $total_changes)
    echo "<span color='$color_label'> </span> $output"
fi