Skip to content

KarlHeitmann/rg_explorer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RipGrep Explorer

Explore the source code of your favorite projects using this TUI wrapper for RipGrep.

This project is heavily inspired on Vim, because you have two different modes to input commands. The normal mode, which you can switch tabs, span more or less context lines, change selected file, etc. And the insert mode, which you can use to input data: input a filter for folders, edit search term, etc.

Much of the functionality of this project is not documented neither the UI provides you clues on what you can do. This project was built as an educational project, for me to practice Rust language, and for others to collaborate with this project and practice their coding skills. The intention is that newcomers can read the source code, experiment, find out what this project does and then collaborate with simple tasks as inline documentation for the project.

It launches a rg instance with arguments defined by the user, and adds the --json flag so it can parse the output of rg command and creates a data structure with the parsed result. Take a look at this example, but first you must meet the dependencies in order to build this project

Dependencies

You need to install RipGrep in your local machine. Follow the steps on the repository to install RipGrep in your computer (Linux, Mac or Windows). To check if you have achieved to install RipGrep in your computer run this command:

rg

If you installed it correctly, you should see something like this:

error: The following required arguments were not provided:                                                                                                                                                                                                                                                                                                                             │
    <PATTERN>                                                                                                                                                                                                                                                                                                                                                                          │
  │                                                                                                                                                                                                                                                                                                                                                                                    │
USAGE:                                                                                                                                                                                                                                                                                                                                                                                 │
                                                                                                                                                                                                                                                                                                                                                                                       │
    rg [OPTIONS] PATTERN [PATH ...]                                                                                                                                                                                                                                                                                                                                                    │
    rg [OPTIONS] -e PATTERN ... [PATH ...]                                                                                                                                                                                                                                                                                                                                             │
    rg [OPTIONS] -f PATTERNFILE ... [PATH ...]                                                                                                                                                                                                                                                                                                                                         │
    rg [OPTIONS] --files [PATH ...]                                                                                                                                                                                                                                                                                                                                                    │
    rg [OPTIONS] --type-list                                                                                                                                                                                                                                                                                                                                                           │
    command | rg [OPTIONS] PATTERN                                                                                                                                                                                                                                                                                                                                                     │
    rg [OPTIONS] --help                                                                                                                                                                                                                                                                                                                                                                │
    rg [OPTIONS] --version                                                                                                                                                                                                                                                                                                                                                             │

For more information try --help                                                                                                                             

Example

Clone this project, go to the root path of this project on your local machine and type this command on your terminal:

cargo run -- fn

This will build the application and run it by passing to the executable the argument fn. This sole argument is the search term. rg_explorer will find inside this project all files that have the fn string inside. As you already know, in Rust the fn keyword is used to declare your functions. So the results will contain all rust source code files as result. rg_explorer will parse the output of rg command and will create its own data structure: RipGrep. RipGrep has a special field called Nodes. This is the meat of the application. On the "Home" page displayed right after entering the above command, you will see something like this

image

This is showing you the actual ripgrep command that rg_explorer has launched as child process. As you can see on the image, it is telling ripgrep to:

  • search_term = fn
  • format of output is JSON
  • Show 1 line of context after each match (-A 1 flag)
  • Show 1 line of context before each match (-B 1 flag)
  • Search inside the current folder (.)

To see the nodes hit the "n" key. You will go to "Nodes" page and will see something like this:

image

At the left side, you will see all the files inside the project that have the fn string inside. You can select one of them by hitting the up/down arrow key. The content of the "Detail" widget will show you each line with a match, surrounded by 1 lines of context after and 1 line of context before.

The rest of the application... you are invited to rg explore it!

Contribution

See the "Issues" tab of this github project to see what you can do. There are some issues labeled with Good first issue that you can try. If you have some ideas, check out the discussion tab of this project

Acknowledgement, inspiration.

  • This nice tutorial helped me get bootstraped with rust TUI library
  • In loving memory of Viktor Slüsarenko Stachniw. My best teacher at the Universidad Técnica Federico Santa María. Requiescat in pace, Maestro.

DSC01349

About

Rip Grep Explorer. A TUI wrapper for RipGrep

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages