Files
neovim-config/scripts/update_cache.sh
T
rootiest 0c50bcd14b ♻️ refactor(cache-stats)!: refactor the wakatime and music stats modules
Modules now spawn the scripts automatically at startup and kill them at exit. Both stats are handled by a single script and a lockfile is used to avoid multiple instances spawning.

BREAKING CHANGE: Please remove any user services previously used to spawn scripts.
2024-08-08 22:40:00 -04:00

38 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
# Separator variable
separator="␟"
# Lock file path
lock_file="/tmp/music_wakatime_update.lock"
# Create a lock file to ensure only one instance of the script runs
if [[ -e $lock_file ]]; then
echo "Another instance of this script is already running."
exit 1
else
# Create the lock file
touch "$lock_file"
fi
# Function to clean up lock file on exit
cleanup() {
rm -f "$lock_file"
}
trap cleanup EXIT
# Update the music cache file every second
while true; do
playerctl --ignore-player firefox,kdeconnect,haruna,plasma-browser-integration metadata --format "{{ artist }}${separator}{{ title }}${separator}{{ album }}${separator}{{ status }}${separator}{{ volume }}${separator}{{ loop }}${separator}{{ shuffle }}" >~/.cache/music_cache.txt
sleep 1
done & # Run this loop in the background
# Update the Wakatime cache file every 60 seconds
while true; do
~/.wakatime/wakatime-cli --today >~/.cache/wakatime_cache.txt 2>/dev/null
sleep 60
done & # Run this loop in the background
# Wait for all background processes to finish
wait