DEV Community

Garett Dunn
Garett Dunn

Posted on • Edited 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)
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
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

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
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
ampersanda profile image
Ampersanda

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

bash <(curl -s https://gist.githubusercontent.com/ampersanda/6b2e0ef0a395741e3a6f2c4c311a9419/raw/6642d03f42cb5c2c8bc2cfe4d7e42a1bca7722fa/brewlette)
Collapse
 
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?