Skip to content

Instantly share code, notes, and snippets.

@sp4ce
Last active August 3, 2022 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sp4ce/12503043453f3790aa72916639121256 to your computer and use it in GitHub Desktop.
Save sp4ce/12503043453f3790aa72916639121256 to your computer and use it in GitHub Desktop.
Brew outdated notification
# brew outdated notification
BREW_OUTDATED_CHECK_TIME=$(cat ~/.brew-outdated-check-time 2>/dev/null)
if [[ -z "${BREW_OUTDATED_CHECK_TIME}" || $(($BREW_OUTDATED_CHECK_TIME + 64800)) -le $(date +%s) ]]; then
date +%s >| ~/.brew-outdated-check-time
echo "Checking outdated brew formulae..."
if [[ -n "${BREW_OUTDATED_CHECK_TIME}" ]]; then
echo "It was previously checked on $(date -r $BREW_OUTDATED_CHECK_TIME)"
fi
brew update --quiet
outdated=$(brew outdated --quiet)
pinned=$(brew list --pinned)
# Remove pinned formulae from the list of outdated formulae
outdated=$(comm -1 -3 <(echo "${pinned}") <(echo "${outdated}"))
if [[ -n "${outdated}" ]]; then
# join lines together with ", " and remove possible trailing comma character
outdated=$(perl -pe 's/\n/, /g' <(echo "${outdated}") | sed 's/, $//g')
printf "The following formulae are outdated:\n${outdated}\n"
else
echo "No outdated formulae"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment