Skip to content

Instantly share code, notes, and snippets.

@logarytm
Last active June 11, 2023 03:45
Show Gist options
  • Save logarytm/575263a76d22f29ef721f40b2785d5c8 to your computer and use it in GitHub Desktop.
Save logarytm/575263a76d22f29ef721f40b2785d5c8 to your computer and use it in GitHub Desktop.
package update notifications for Arch Linux, easily portable to other distros
#!/usr/bin/env bash
# Configuration
cache_file=$HOME/.updates
# function to check updates, must work without root privileges and print
# the number of updates to stdout.
function update_count {
checkupdates | wc -l; return $?
}
# notification function, called: notify TOTAL [NEW]
function notify {
if [ $# -eq 2 ]; then
notify-send "$2 new updates ($1 total)" "Run pacman -Syu to upgrade"
else
notify-send "$1 updates" "Run pacman -Syu to upgrade"
fi
}
count=$(update_count)
if [ -f "$cache_file" ] && [ $(<$cache_file) -ge 0 ]; then
last_count=$(cat $cache_file)
if [ $last_count -lt $count ]; then
notify $count $((count-last_count))
echo $count > $cache_file
fi
elif [ $count -ge 0 ]; then
notify $count
echo $count > $cache_file
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment