A simple Zsh script that automatically checks for outdated Homebrew packages and displays a notification when you open your terminal.
- Automatic Daily Checks: A cron job runs in the background to check for updates.
- Terminal Notification: Displays a clean, formatted list of packages, showing current and available versions.
- Lightweight: Just a simple shell script, no heavy dependencies.
The system has two components:
- The Update Script (
scripts/update_brew_notifier.sh): This script is run bycron. It callsbrew updateandbrew outdated, saving the list of outdated packages to a file in your home directory (~/.brew_updates_available). - The
.zshrcHook: A small piece of code in your~/.zshrcfile checks if the above file exists and has content. If it does, it prints a formatted notification to your terminal.
-
Clone or download this repository to a location on your computer, for example
~/.local/share/brew-notifier. -
Make the script executable:
chmod +x scripts/update_brew_notifier.sh
-
Add the notification hook to your
.zshrcfile. Open~/.zshrcwith a text editor and add the following lines at the end:# --- Brew Notifier --- _BREW_NOTIFIER_FILE="$HOME/.brew_updates_available" if [ -s "$_BREW_NOTIFIER_FILE" ]; then echo "" echo -e "\e[1;33m🍻 Homebrew updates available:\e[0m" echo "------------------------------------" sed 's/^/ /' "$_BREW_NOTIFIER_FILE" echo "------------------------------------" echo -e "To upgrade, run: \e[1;32mbrew upgrade\e[0m" echo "" # Remove the file to not show the notification again rm "$_BREW_NOTIFIER_FILE" fi unset _BREW_NOTIFIER_FILE # --- End Brew Notifier ---
-
Set up the cron job to run the script automatically.
-
Open the cron editor:
crontab -e
-
Add the following line. Remember to replace
/path/to/your/brew-notifierwith the actual absolute path to where you cloned the repository.# Run the brew-notifier script daily at 10 AM. 0 10 * * * /bin/zsh /path/to/your/brew-notifier/scripts/update_brew_notifier.sh > /tmp/brew_notifier.log 2>&1
-
That's it! The script will now run daily, and you'll be notified of any updates the next time you open a terminal.