Skip to content

Instantly share code, notes, and snippets.

@garettmd
Last active May 18, 2021 00:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garettmd/7731cfd71cbee6e7c891fc94072d05ab to your computer and use it in GitHub Desktop.
Save garettmd/7731cfd71cbee6e7c891fc94072d05ab to your computer and use it in GitHub Desktop.
Suggest a random package from homebrew
#!/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
@garettmd
Copy link
Author

Put this file under /usr/local/bin so that it's in your PATH. Then enjoy discovering new packages in homebrew.

@garettmd
Copy link
Author

garettmd commented Oct 3, 2018

4th revision tightened up code according to shellcheck suggestions

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