Intelligent command line tool-betty

Source: Internet
Author: User

This article is first published in

The CSDN Article editor is too bad. We recommend that you use Cmd Markdown. It not only supports markdown, but also supports VIM mode.

Intelligent command line tool-betty

Betty tool command ruby

Betty is a simple and interesting intelligent command line prompt tool implemented in Ruby. The main problem solved is to translate English into unix commands that can be understood by machines. In its official documentation, We can find detailed instructions and explanations. The main purpose of this article is to customize our own "English commands" based on betty ".

Basic Principles

The main. rb file is the entrance of the entire program. Its main function is

  1. Use the command line parameters to load all executable files from lib/*. rb to find executable commands.

    If the installation is successful, you will find ~ /. Bash_profile or another system configuration file contains a line of code similar to the following:
    Alias betty = "xxx/betty/main. rb"

    From the above analysis, we can see that betty is not responsible for specific command execution, but for converting our popular language (such as English) into commands that can be executed by the system.

    File in lib/*. rb, responsible

    • Determine whether the command matches (use regular match)

      If yes, return the matching command and description in JSON format.

       
          
      1. responses << {
        • :command => "grep --include=#{ pattern } -Rn #{ contains } #{ directory }",
          • :explanation => "Find files with extension that contains string."
            • }

      Let's take betty find me all files that contain california as an example to explain the program running process.

      The betty command maps to main. in the rb file, the main method is triggered to call the interpret method interpret. The main responsibility is to find matching commands in $ executors, the executor implemented by calling the interpret method in executor is the module defined in lib.Customize your executor

      Objectives:
      To implement a prompt command, for example, enter betty give me a help and all command prompts will be displayed on the screen.

      Based on the above analysis, we found that implementing our executor is very simple. The basic steps are as follows:

      1. Define a new module in lib to define a class method interpret (command) if it matches the command, return response to register executor to $ executors

        For specific code, see https://github.com/chucai/betty

        Summary

        Betty is really a fun tool, and it is very simple to implement your own specific commands. In addition, this project can develop in a more complex direction. For example, voice prompts similar to siri, and you can also customize your own Chinese prompts. Since this project was just started, there are still many shortcomings. For example, when we are processing a specific speech, we use regular expressions, which are not intelligent enough and the logic is very simple, if you want to customize your own requirements, you need to implement more details on your own. But in general, this is a great tool!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.