#!/bin/bash

# Always read from cache and return immediately
count=$(cat /tmp/checkupdates 2>/dev/null)
# nohup checkupdates > /tmp/checkupdates & disown
# $(checkupdates | wc -l > /tmp/checkupdates) & disown

if [[ $? -ne 0 ]] || [[ -z "$count" ]]; then
    status="Unknown"
else
    if [[ $count == "Unknown" ]]; then
        status="Unknown"
    elif [[ $count -eq 0 ]]; then
        status="Up to date"
    elif [[ $count -eq 1 ]]; then
        status="$count update"
    else
        status="$count updates"
    fi
fi

echo "$status"

exec "$HOME/.config/fastfetch/scripts/fetch_update_count.sh" & disown
