Garett Dunn
Posted on June 11, 2019
I'm kind of OCD about keeping packges updated, maybe to a fault. One result of this obsession is that I run brew update every morning on my Mac. This command updates the list of packages, even ones you don't use, so after running it you're presented with a list of all sorts of packages. If I'm not in a hurry, I'll usually spot 1 or 2 packages that sound interesting, and might end up installing them. After doing this for a while, I decided that it would be cool if I could just issue a command and get a random package at will. Turns out this is actually easy to do.
Without further ado, I present: brewlette!
$ brewlette
Try out a random homebrew package!
flvmeta: stable 1.2.1 (bottled), HEAD
Manipulate Adobe flash video files (FLV)
https://www.flvmeta.com/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/flvmeta.rb
==> Dependencies
Build: cmake ✔
==> Options
--HEAD
Install HEAD version
Command "brew install flvmeta" copied to clipboard
Really, it's just a simple shell script that I put in /usr/local/bin (where brew usually installs packages). It works by picking a random package from the list of formulas that brew caches. One little nifty addition I made is that it copies the brew commmand to install the package to your clipboard. Just ⌘+v and enjoy the new package. For now the script is on a Github gist. Feel free to comment/fork if you want to make a contribution. Here's the script:
#!/usr/bin/env bash
# Utility to suggest a new package to try from Homebrew
# Simply run and it will give you a new package to try out
files=(/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/*)
total=${#files[@]}
rando=$((RANDOM % total))
package=$(basename "${files[rando]}" .rb)
printf "\\nTry out a random homebrew package!\\n\\n"
brew info "${package}"
if [[ $(command -v pbcopy) ]]
then
echo "brew install ${package}" | pbcopy
printf "\\nCommand \"brew install %s\" copied to clipboard\\n" "$package"
else
printf "\\nUse \"brew install %s\" to try it out\\n" "$package"
fi
Posted on June 11, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.