Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🔍 Ubuntu’s command-not-found equivalent for Homebrew on macOS

License

NotificationsYou must be signed in to change notification settings

Homebrew/homebrew-command-not-found

Repository files navigation

This project reproduces Ubuntu’scommand-not-found for Homebrew users onmacOS.

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

# on Ubuntu$ whenThe program'when' is currently not installed.  You can install it by typing:sudo apt-get install when# on macOS with Homebrew$ whenThe 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" ];thensource"$HB_CNF_HANDLER";fi
  • Fish: Add the following line to your~/.config/fish/config.fish:

    set-l __hb_cnf_handler (brew--repository)"/Library/Taps/homebrew/homebrew-command-not-found/handler.fish"iftest-f$__hb_cnf_handler   source$__hb_cnf_handlerend

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 morebrew commands:brew which-formulaandbrew which-update. The first one uses a database file which gives you theformula you have to install in order to get a specific command. The file isgenerated by the second command by crawling all installed formulae andcollecting their binaries. Having this as a tap means you get an up-to-datebinaries database each time you runbrew update.

Thehandler.sh script defines acommand_not_found_handle function which isused by Bash when you try a command that doesn’t exist. The function callsbrew which-formula on your command, and if it finds a match it’ll print it toyou. If not, you’ll get an error as expected.

About

🔍 Ubuntu’s command-not-found equivalent for Homebrew on macOS

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Contributors30


[8]ページ先頭

©2009-2025 Movatter.jp