#!/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