• Stars
    star
    373
  • Rank 110,413 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 10 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ” Ubuntuโ€™s command-not-found equivalent for Homebrew on macOS

Homebrew Command Not Found

This project reproduces Ubuntuโ€™s command-not-found for Homebrew users on macOS.

GitHub Actions

On Ubuntu, when you try to use a command that doesnโ€™t exist locally but is available through a package, Bash will suggest you a command to install it. Using this script, you can replicate this feature on macOS:

# on Ubuntu
$ when
The program 'when' is currently not installed.  You can install it by typing:
sudo apt-get install when

# on macOS with Homebrew
$ when
The program 'when' is currently not installed. You can install it by typing:
  brew install when

Over 5000 formulae are supported, representing more than 17000 different commands (100% of the main Homebrew repo).

Install

First, tap this repository:

brew tap homebrew/command-not-found
  • Bash and Zsh: Add the following line to your ~/.bash_profile (bash) or ~/.zshrc (zsh):

    HB_CNF_HANDLER="$(brew --repository)/Library/Taps/homebrew/homebrew-command-not-found/handler.sh"
    if [ -f "$HB_CNF_HANDLER" ]; then
    source "$HB_CNF_HANDLER";
    fi
  • Fish: Add the following line to your ~/.config/fish/config.fish:

    set HB_CNF_HANDLER (brew --repository)"/Library/Taps/homebrew/homebrew-command-not-found/handler.fish"
    if test -f $HB_CNF_HANDLER
       source $HB_CNF_HANDLER
    end

Requirements

This tool requires one of the following:

  • Zsh (the default on macOS Catalina and above)
  • Bash (version 4 and higher)
  • Fish

How it works

When you tap the repo youโ€™ll get two more brew commands: brew which-formula and brew which-update. The first one uses a database file which gives you the formula you have to install in order to get a specific command. The file is generated by the second command by crawling all installed formulae and collecting their binaries. Having this as a tap means you get an up-to-date binaries database each time you run brew update.

The handler.sh script defines a command_not_found_handle function which is used by Bash when you try a command that doesnโ€™t exist. The function calls brew which-formula on your command, and if it finds a match itโ€™ll print it to you. If not, youโ€™ll get an error as expected.

More Repositories

1

brew

๐Ÿบ The missing package manager for macOS (or Linux)
Ruby
38,957
star
2

legacy-homebrew

๐Ÿ’€ The former home of Homebrew/homebrew (deprecated)
27,030
star
3

homebrew-cask

๐Ÿป A CLI workflow for the administration of macOS applications distributed as binaries
Ruby
20,458
star
4

homebrew-core

๐Ÿป Default formulae for the missing package manager for macOS (or Linux)
Ruby
13,114
star
5

homebrew-bundle

๐Ÿ“ฆ Bundler for non-Ruby dependencies from Homebrew, Homebrew Cask and the Mac App Store.
Ruby
4,852
star
6

homebrew-cask-fonts

๐Ÿ–‹ Casks of ๏ผฆ๐Ÿ…พ๐“๐“๐š‚
Ruby
2,836
star
7

install

๐Ÿ“ฅ Homebrew (un)installer
Shell
2,024
star
8

homebrew-services

๐Ÿš€ Manage background services using the daemon manager launchctl on macOS or systemctl on Linux.
Ruby
1,915
star
9

formulae.brew.sh

๐ŸŽ An online formulae browser for Homebrew
HTML
1,341
star
10

homebrew-cask-versions

๐Ÿ”ข Alternate versions of Casks
Ruby
1,175
star
11

linuxbrew-core

๐Ÿ’€Formerly the core formulae for the Homebrew package manager on Linux
Ruby
1,160
star
12

homebrew-cask-drivers

๐Ÿ’€ Casks of Drivers (deprecated)
461
star
13

discussions

๐Ÿ—ฃ Public open-ended discussions. Replacement for our Discourse.
372
star
14

ruby-macho

๐Ÿ”ฉ A pure-Ruby library for parsing Mach-O files.
Ruby
232
star
15

homebrew-aliases

โžก๏ธ Aliases for Homebrew
Ruby
144
star
16

brew.sh

๐Ÿ”– The Homebrew homepage
HTML
131
star
17

homebrew-portable-ruby

๐Ÿš— Versions of Ruby that can be installed and run from anywhere on the filesystem.
Ruby
114
star
18

actions

๐Ÿš€ Homebrew's GitHub Actions
JavaScript
99
star
19

homebrew-livecheck

๐Ÿ’€ Homebrew/homebrew-livecheck (deprecated)
96
star
20

homebrew-test-bot

๐ŸŽฐ Tests the full lifecycle of a Homebrew change.
Ruby
74
star
21

formula-patches

๐Ÿฅ Patches for Homebrew formulae
C
63
star
22

gsoc

๐Ÿ’€ Homebrew's Google Summer of Code (deprecated)
52
star
23

.github

๐Ÿ‘ฉโ€โš•๏ธ Default community health files for the Homebrew organisation on GitHub.
34
star
24

rubydoc.brew.sh

๐Ÿ“– An online Ruby documentation browser for Homebrew/brew
Ruby
23
star
25

homebrew-linux-dev

๐Ÿ’€ Homebrew/homebrew-linux-dev (deprecated)
Ruby
20
star
26

homebrew-formula-analytics

๐Ÿ”ข Query Homebrew's analytics from the command-line.
Ruby
12
star
27

homebrew-governance

๐Ÿ’€Homebrew's governance (deprecated)
10
star
28

brew-pip-audit

๐Ÿ“‹ Bulk auditing Python dependencies in Homebrew with pip-audit
Ruby
8
star
29

glibc-bootstrap

Shell
6
star
30

orka_api_client

A Ruby gem for interfacing with MacStadium's Orka API
Ruby
5
star
31

ci-orchestrator

Manager of CI machine deployment and teardown (for internal Homebrew use)
Ruby
5
star