Last active
December 24, 2016 09:46
-
-
Save omega/1c3d72a1f076a2a37c50dc2f57283218 to your computer and use it in GitHub Desktop.
A script that will attempt to show you which of your brew casks are outdated compared to current versions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
vercomp () { | |
if [[ $1 == $2 ]] | |
then | |
return 0 | |
fi | |
local IFS=. | |
local i ver1=($1) ver2=($2) | |
# fill empty fields in ver1 with zeros | |
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) | |
do | |
ver1[i]=0 | |
done | |
for ((i=0; i<${#ver1[@]}; i++)) | |
do | |
if [[ -z ${ver2[i]} ]] | |
then | |
# fill empty fields in ver2 with zeros | |
ver2[i]=0 | |
fi | |
if ((10#${ver1[i]} > 10#${ver2[i]})) | |
then | |
return 1 | |
fi | |
if ((10#${ver1[i]} < 10#${ver2[i]})) | |
then | |
return 2 | |
fi | |
done | |
return 0 | |
} | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
BLUE='\033[0;33m' | |
NC='\033[0m' # No Color | |
warn () { | |
lapp=$1 | |
lmsg=$2 | |
printf "%-20s: %-47s %b%s%b\n" $lapp "" $RED "$lmsg" $NC | |
} | |
applist=$@ | |
if [ -z "$applist" ]; then | |
applist=$(brew cask list) | |
fi | |
for app in $applist; do | |
latest=$(brew cask info $app | grep "$app: " | sed -e 's/^.*: //') | |
if [[ "$latest" == "latest" ]]; then | |
warn "$app" "no version info found in brew cask info" | |
continue | |
fi | |
appname=$(brew cask info $app | egrep '\((app|prefpane)\)' | sed -e 's/(app)//' -e 's/(prefpane)//' -e 's/.app//' -e 's/.prefPane//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/.*\///') | |
while read -r subapp; do | |
if [[ -z "$subapp" ]]; then | |
warn "$app" "didn't find any actual apps in brew cask info" | |
continue | |
fi | |
installed=$(osascript -e "version of app \"$subapp\"") | |
new="" | |
if [[ -z "$installed" ]]; then | |
warn "$app" "no installed version found :(" | |
continue | |
fi | |
./version-compare "$installed" "$latest" | |
case $? in | |
0) new="";; | |
1) new="${BLUE}cask outdated, consider PR?${NC}";; | |
2) new="${GREEN}new version in cask${NC}";; | |
esac | |
printf "%-20s: %-20s (%10s vs %10s) %b\n" "$app" "$subapp" "$installed" "$latest" "$new" | |
done <<< "$appname" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment