summaryrefslogtreecommitdiffstats
path: root/clerk_updater
blob: 425cb05edc2f87350130ace794d4bdc95ad0bb16 (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
#!/bin/bash

# create cached album list
source $HOME/.config/clerk/config

# Use GNU coreutils on OSX
sed=$([[ "$OSTYPE" == "darwin"* ]] && echo 'gsed' || echo 'sed')

notify()
{
    if hash notify-send 2>/dev/null; then
      notify-send "clerk" "Creating caches"
    elif hash say 2>/dev/null; then
      say "Updating clerk caches"
    fi
}


update() {
    new_db="$(mpc stats | grep Updated | $sed 's/ //g')"
    if [[ "$change_db" == "$new_db" ]]; then
        if [[ -f $HOME/.config/clerk/album.cache && -f $HOME/.config/clerk/tracks.cache && -f $HOME/.config/clerk/last.cache ]]; then
            :
        else
            notify
            export separator="$separator"; mppc albumcache
            export separator="$separator"; mppc trackcache
            export separator="$separator"; mppc lastcache
        fi
    else
        notify
        $sed -i "s/change_db=".*"/change_db=""$new_db""/" $HOME/.config/clerk/config
        export separator="$separator"; mppc albumcache
        export separator="$separator"; mppc trackcache
        export separator="$separator"; mppc lastcache
    fi
}

force() {
    notify
    new_db="$(mpc stats | grep Updated | $sed 's/ //g')"
    $sed -i "s/change_db=".*"/change_db=""$new_db""/" $HOME/.config/clerk/config
    export separator="$separator"; mppc albumcache
    export separator="$separator"; mppc trackcache
    export separator="$separator"; mppc lastcache
}

if [[ $1 == "--force" ]]; then
    force
else
    update
fi