7

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.

10

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.

  • Just a small improvement to the first command to highlight the executables themselves if you have gnu grep installed (brew install grep). Command is as follows: brew unlink --dry-run grep | ggrep --color=always -P "$(brew --prefix)/bin/\K.*" Output is as seen in this screenshot. – Ashutosh Jindal Jul 17 '18 at 12:10
1

I wrote Homebrew-command-not-found to do the reverse thing: get a formula from an executable. There isn’t any easy way to get a formula’s executables as other answers pointed out; so I installed all Homebrew formulae and recorded all executables in one file.

You can find it here. Each formula has its own line with the following format:

<name>: <executable-1> <executable-2> <...>

It’s thus as easy as grep ^git: executables.txt to get the executables installed by the git formula.

The file is updated every day and covers 20k+ commands for 5k+ formulae from the core and the official taps. Note however that some formulae install different executables when you use specific options; I don’t support them here.

0

In general - no.

Homebrew doesn't install package receipts which is the manner in which current tools decide what is installed where in an exhaustive and correct fashion.

Sometimes you can use brew list to check things, but I've found the best way to check on homebrew is via github - which publishes the source code for all the tools and all the packages.

My favorite search engine even has ! commands to make it easy to search github:

!gh homebrew lua

Google does a decent job as well ranking homebrew fairly high as well as github

!g homebrew lua

Also, brew info and brew home often give you a direct link to the project source to check if your suspicions are correct. As you surmise, the real check is to uninstall / reinstall and watch. Not fun, but effective.

  • Could you point me out to a documentation about those ! commands? – Iulian Onofrei Dec 27 '16 at 11:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .