Skip to content

Instantly share code, notes, and snippets.

@kkumler
Forked from SimonSimCity/brew-update-notifier.sh
Last active August 29, 2015 14:08
Show Gist options
  • Save kkumler/282cb91a902699bd06c2 to your computer and use it in GitHub Desktop.
Save kkumler/282cb91a902699bd06c2 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Notify of Homebrew updates via Notification Center on Mac OS X
#
# Author: Chris Streeter http://www.chrisstreeter.com
# KLK: Fixed package lists and do not show notification when there are no updates
#
# Requires: terminal-notifier. Install with:
# brew install terminal-notifier
BREW_EXEC=$(which brew)
TERMINAL_NOTIFIER=$(which terminal-notifier)
#TERMINAL_NOTIFIER=/bin/echo
NOTIF_ARGS="-sender com.apple.Terminal"
$BREW_EXEC update > /dev/null 2>&1
outdated=$($BREW_EXEC outdated)
pinned=$($BREW_EXEC list --pinned)
# Remove pinned formulae from the list of outdated formulae
outdated=$(comm -1 -3 <(echo -e "$pinned") <(echo -e "$outdated"))
if [ -z "$outdated" ] ; then
if [ -e $TERMINAL_NOTIFIER ]; then
# No updates available
#$TERMINAL_NOTIFIER $NOTIF_ARGS \
#-title "No Homebrew Updates Available" \
#-message "No updates available yet for any homebrew packages."
exit 0
fi
else
# We've got an outdated formula or two
# Nofity via Notification Center
if [ -e $TERMINAL_NOTIFIER ]; then
lc=$(echo "$outdated" | wc -l)
outdated=$(echo "$outdated" | tail -n ${lc})
message=$(echo "$outdated" | head -5)
if [ "$outdated" != "$message" ]; then
message="Some of the outdated formulae are:
$message"
else
message="The following formulae are outdated:
$message"
fi
# Send to the Nofication Center
$TERMINAL_NOTIFIER ${NOTIF_ARGS} -title "Homebrew Update(s) Available" -message "${message}"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment