Code Monkey home page Code Monkey logo

homebrew-command-not-found's Introduction

homebrew-command-not-found

Build Status

This project tries to reproduce Ubuntu’s command-not-found for Homebrew users on OSX.

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 OSX:

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

# on OSX 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 almost 20000 different commands (99% of the main Homebrew repo + 91% of all official taps).

Install

First, tap this repository:

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

    if brew command command-not-found-init > /dev/null; then eval "$(brew command-not-found-init)"; fi
  • Fish: Add the following line to your ~/.config/fish/config.fish:

    brew command command-not-found-init > /dev/null; and . (brew command-not-found-init)

Upgrade from 0.1.1

Before the 0.2.0 version this was a simple handler.sh script which grep-ed in formulae to find the binaries. It worked well for most formulae but wasn’t exhaustive.

The 0.2.0 version changed how it works. If you’d like to keep your existing handler script, it’s fine, it’ll continue to work. If instead you’d like to upgrade to 0.2.0 just remove it and follow the install instructions above.

Support

This tool supports Bash (version 4 and higher), Zsh and Fish.

How does it work?

When you tap the repo you’ll get two more brew commands: brew which-formula and brew which-update. The first one uses a file database to gives you which 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 collect their binaries. If we regularly run this update script on multiple Homebrew installations I hope we’ll cover most of the formulae. 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.

homebrew-command-not-found's People

Contributors

alyssais avatar bfontaine avatar mcmahoniel avatar xu-cheng avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.