Find executables associated with Homebrew Formula

command linehomebrew

Some Homebrew formulas have names that do not correspond with any of the installed commands (e.g., coreutils, speech-tools), other formulas provide an command that matches up with the name, but also provide others alongside it (e.g., lua).

Is there a simple way to determine what commands are associated with a given formula? Ideally as a brew <arg> command before installing, but even a shell script I could use post-install would help.

I thought I might be able to figure this info out with a brew link --dry-run <formula>, but that typically just gives me a warning that the formula is already linked (even with --overwrite or --force added to the command). I don't want to have to unlink each time I want to see the commands, so this route doesn't seem helpful.

Best Answer

As bmike's answer points out, aside from digging through the projects source to determine what executables they install, there's no good way to determine what commands come with a given formula before installing it.

After a formula is installed, running

brew unlink --dry-run formula | grep "$(brew --prefix)/bin"

is a workable option now that --dry-run is available for brew unlink.

Before that was added I wrote an external command called brew executables that still has some benefits over the above (mainly in formatting and handling some links a bit differently). I'll include a simplified (and probably non-working, due to missing some variable assignments) version of it here:

version_in_use=$(echo "$brew_info" | grep "$HOMEBREW_PREFIX.*\*$" | sed -e "s|.*$formula/\([^ ]*\).*|\1|i")

cd "$HOMEBREW_CELLAR/$formula/$version_in_use" 
for dir in `find . -type d -mindepth 1 -maxdepth 1 -name "bin"`; do
    for file in `find "$dir" -type f -o -type l -perm +111`
    do
            filename=$(basename $file)
            echo $filename
    done        
done

In short, it pulls the list of executables out of $(brew --prefix)/$formula/$version_in_use/bin. The version on my GitHub is a bit more fleshed out, including some added ability to identify/indicate when there are commands that link to each other in this bin directory.