Hello everyone :)
I have this in a script which I call from my .zshrc:
#!/bin/zsh
# ~/.bin/check_last_update.sh
GREEN='\033[92m'
YELLOW='\033[93m'
RED='\033[91m'
RESET='\033[0m'
# Check if there are available updates for packages
num_packages_to_update=$(checkupdates | wc -l)
if (( num_packages_to_update >= 0 && num_packages_to_update <= 20 )); then
echo -e "${GREEN}Available updates: $num_packages_to_update${RESET}" >> /dev/tty
elif (( num_packages_to_update > 20 && num_packages_to_update <= 50 )); then
echo -e "${YELLOW}Available updates: $num_packages_to_update${RESET}" >> /dev/tty
else
echo -e "${RED}Available updates: $num_packages_to_update${RESET}" >> /dev/tty
fi
# Kernel version check
running_kernel=$(uname -r)
installed_kernel=$(pacman -Q linux | awk '{print $2}' | cut -d '-' -f1 | cut -d '.' -f1,2,3)
running_kernel_base=$(echo "$running_kernel" | cut -d '-' -f1)
if [[ "$running_kernel_base" != "$installed_kernel" ]];
then
echo -e "${RED}Kernel mismatch detected. Reboot recommended.${RESET}" >> /dev/tty
fi
It works, but when I open a new terminal it may take up to 2 seconds for the prompt to show up. Is there a way of speeding this up?
Would it be a good idea to perform the checks in the background every hour or so, maybe with a systemd timer or something, and cache the results (or possibly to make it even more efficient, just store a file somewhere out of the way containing the number of updates and if there is a kernel mismatch - maybe on separate lines so when I open a terminal I can easily query the file and get exactly what I need) so that when I open a new terminal instead of checking with the live repositories it checks the cached data? Also, I guess this would mean that if a package has become available for update after the last time the check script runs, then the number it tells me will be less than the actual number of available updates, right?
Thanks in advance!


It takes that long to run. Remove it if you don’t like it, or background the task on execution, though you won’t see it’s output if you do so.
You don’t need this in your zsh profile. Run it in a cronjob if you’re that concerned.