DEV Community

Garett Dunn
Garett Dunn

Posted on • Updated on

Brewlette - Discover homebrew packages

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)
Not installed
==> Dependencies
Build: cmake βœ”
==> Options
    Install HEAD version

Command "brew install flvmeta" copied to clipboard
Enter fullscreen mode Exit fullscreen mode

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

rando=$((RANDOM % total))
package=$(basename "${files[rando]}" .rb)
printf "\\nTry out a random homebrew package!\\n\\n"
brew info "${package}"

if [[ $(command -v pbcopy) ]]
    echo "brew install ${package}" | pbcopy
    printf "\\nCommand \"brew install %s\" copied to clipboard\\n" "$package"
    printf "\\nUse \"brew install %s\" to try it out\\n" "$package"
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

ampersanda profile image

I store to my gist for better usage, Cheers :)

bash <(curl -s
garettmd profile image
Garett Dunn

Nice! I actually meant to put a link to my own gist in the post. Are you storing this as an alias?