♻️ refactor(full-scope)!: major revision refactoring

Code layout has been changed and improoved. Annotations are added for documentation. Automated through utility functions and data tables

BREAKING CHANGE: Tested from clean. Now properly uses LuaRocks to install dependencies.
This commit is contained in:
2024-09-04 16:07:12 -04:00
parent b2731cff01
commit 273580f533
48 changed files with 1962 additions and 750 deletions
+37 -4
View File
@@ -9,6 +9,7 @@ ignored_sources=""
# Flags for disabling functionality
disable_wakatime=false
no_music=false
custom_cache_dir=""
# Function to print usage
print_usage() {
@@ -18,6 +19,7 @@ print_usage() {
echo " -i, --ignore Comma-separated list of sources to ignore"
echo " -d, --disable-wakatime Disable wakatime integration"
echo " -n, --no-music Disable music integration"
echo " -c, --cache-dir Specify a custom cache directory"
exit 0
}
@@ -42,6 +44,15 @@ while [[ $# -gt 0 ]]; do
-n | --no-music)
no_music=true
;;
-c | --cache-dir)
if [[ -n $2 && $2 != -* ]]; then
custom_cache_dir=$2
shift
else
echo "Error: --cache-dir requires an argument."
exit 1
fi
;;
*)
echo "Unknown option: $1"
print_usage
@@ -50,15 +61,20 @@ while [[ $# -gt 0 ]]; do
shift
done
# Use custom cache directory if provided, else use Neovim's cache directory
cache_dir="${custom_cache_dir:-\
${NVIM_CACHE_DIR:-\
${XDG_CACHE_HOME:-$HOME/.cache}/nvim}}"
mkdir -p "$cache_dir"
# Lock file path
lock_file="/tmp/music_wakatime_update.lock"
lock_file="$cache_dir/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
@@ -68,10 +84,27 @@ cleanup() {
}
trap cleanup EXIT
# Check if playerctl is available
if ! command -v playerctl &>/dev/null; then
echo "Warning: playerctl not found. Disabling music integration."
no_music=true
fi
# Check if wakatime-cli is available
if ! command -v wakatime-cli &>/dev/null; then
echo "Warning: wakatime-cli not found. Disabling wakatime integration."
disable_wakatime=true
fi
# Update the music cache file every second, if not disabled
if ! $no_music; then
while true; do
playerctl --ignore-player "${ignored_sources}" metadata --format "{{ artist }}${separator}{{ title }}${separator}{{ album }}${separator}{{ status }}${separator}{{ volume }}${separator}{{ loop }}${separator}{{ shuffle }}" >~/.cache/music_cache.txt
playerctl --ignore-player "${ignored_sources}" \
metadata \
--format "{{ artist }}${separator}{{ title }}${separator} \
{{ album }}${separator}{{ status }}${separator}{{ volume }}${separator} \
{{ loop }}${separator}{{ shuffle }}" \
>"$cache_dir/music_cache.txt"
sleep 1
done & # Run this loop in the background
fi
@@ -79,7 +112,7 @@ fi
# Update the Wakatime cache file every 60 seconds, if not disabled
if ! $disable_wakatime; then
while true; do
~/.wakatime/wakatime-cli --today >~/.cache/wakatime_cache.txt 2>/dev/null
wakatime-cli --today >"$cache_dir/wakatime_cache.txt" 2>/dev/null
sleep 60
done & # Run this loop in the background
fi