Skip to content

Instantly share code, notes, and snippets.

@joshmanders
Last active February 2, 2017 23:10
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 joshmanders/515d869a1fc059a1692c20ecdbaae2d3 to your computer and use it in GitHub Desktop.
Save joshmanders/515d869a1fc059a1692c20ecdbaae2d3 to your computer and use it in GitHub Desktop.
Homebrew Cask Upgrade
#!/usr/bin/env bash
readonly local caskroom="/usr/local/Caskroom"
upgrade () {
casks=($(brew cask list))
for cask in ${casks[@]}; do
current="$(brew cask info ${cask} | sed -n '1p' | sed -n 's/^.*: \(.*\)$/\1/p')"
installed=($(ls ${caskroom}/${cask}))
if (! [[ " ${installed[@]} " == *" ${current} "* ]]); then
echo "Upgrading ${cask} to v${current}."
(set -x; brew cask install ${cask} --force; rm -rf ${caskroom}/${cask}/${installed[@]})
else
echo "${cask}@${current} already installed."
fi
done
}
main () {
local args=("$@")
case "$1" in
upgrade) upgrade "${args[@]}" ;;
*) brew cask "${args[@]}" ;;
esac
}
main "$@"
@ibrokemypie
Copy link

does this support upgrading a single cask supplied as an arg?

@joshmanders
Copy link
Author

@ibrokemypie sorry I missed this comment, no it doesn't. It just loops through and updates all casks like brew upgrade does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment