DEV Community

Garett Dunn
Garett Dunn

Posted on • Edited on

2 2

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

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?

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay