-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrew-check.zsh
More file actions
25 lines (23 loc) · 957 Bytes
/
brew-check.zsh
File metadata and controls
25 lines (23 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
## Homebrew update check (runs once per 24 hours)
BREW_CHECK_STAMP="$HOME/.cache/brew_check.stamp"
# Create stamp file if needed (~/.cache should already exist)
[[ -e "$BREW_CHECK_STAMP" ]] || touch "$BREW_CHECK_STAMP"
# Check if stamp is older than 24 hours (-mtime +0 means modified more than 24h ago)
if [[ -n "$(find "$BREW_CHECK_STAMP" -mtime +0 2>/dev/null)" ]]; then
print -P " %F{magenta}***%f Homebrew has not been checked in 24+ hours. Checking..."
brew update >/dev/null 2>&1
local outdated
outdated=$(brew outdated -v)
if [[ -n "$outdated" ]]; then
print -P " %F{magenta}***%f The following packages can be upgraded:"
while IFS= read -r line; do
print -P " %F{208}*%f $line"
done <<< "$outdated"
print -n " Upgrade now? [y/N] "
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
brew upgrade
fi
fi
touch "$BREW_CHECK_STAMP"
fi