Giter Site home page Giter Site logo

rg_wrapper's Introduction

OVERVIEW

This is a ripgrep wrapper. The idea is to have a main loop in which the program will ask you an option, and then it runs ripgrep with --json flag, and the wrapper can take the output of ripgrep and do other things with the output.

It can be pretty useful to explore an unknown source code. You can navigate the code by greping something, and do some sort of "nested greps" inside the results

DEPENDENCIES

You must install ripgrep to run this program, because rg_wrapper will launch an instance of ripgrep each time it is used. To check if you have ripgrep installed type in the following command on your terminal and you should see a biiiig help message.

rg --help

You should see something starting with this, and you're ready to go:

ripgrep 13.0.0 Andrew Gallant [email protected]

ripgrep (rg) recursively searches the current directory for a regex pattern. By default, ripgrep will respect gitignore rules and automatically skip hidden files/directories and binary files.

If you see something like "error" when typing the rg --help command, then you need to install ripgrep or found out what did happened with your rip grep installation (if you're running windows, did you install ripgrep in the same shell you are running this project? eg: bash shell, powershell, wsl, etc)

RELATED PROJECTS

rg_wrapper_text_analysis

rg_wrapper's People

Contributors

karlheitmann avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

jpcostan

rg_wrapper's Issues

Add a nested `rg` command

I want to create a new issue for this, because this user command I think it may be difficult. This can be an option to add on this feature #7 and is blocked by #3 .

Sometimes we want to grep something, for example let's grep all places where we use the useState hook on a React Project.

rg 'const.*useState` 

This will probably give us hundreds of matches in a medium sized project. But let's imagine the user inputs a refined rg command that will narrow down that list of matches into 3 results:

  const [infoUsers, setInfoUsers] = useState([])
  const [posts, setPosts] = useState([])
  const [userPhotos, setUserPhotos] = useState([])

We can add a user action on #7 so rip grep can take each one of these matches, and ripgrep what has being matched with .*, and will show the results to the user for each case. With the results mentioned above, rg_wrapper will run this:

  rg '[infoUsers, setInfoUsers] = '
  <waits user to press enter>
  rg '[posts, setPosts] = '
  <waits user to press enter>
  rg '[userPhotos, setUserPhotos] = '
  <waits user to press enter>
  <finishes>

We can refine the rg commands by asking the user if he wants to remove some patterns from the matches, so if the user adds [ at the beginning and ] = at the end, the commands to be run will become

  rg 'infoUsers, setInfoUsers'
  <waits user to press enter>
  rg 'posts, setPosts'
  <waits user to press enter>
  rg 'userPhotos, setUserPhotos'
  <waits user to press enter>
  <finishes>

Furthermore, we can add a user option to split by commas so you can have rg_wrapper run this:

  rg 'infoUsers`
  <waits user to press enter>
  rg 'setInfoUsers'
  <waits user to press enter>
  rg 'posts' 
  <waits user to press enter>
  etc....
  <finishes>

Once an `rg` command is run, make a summary for the user.

Once the command is run, you can give the user some options so he can do something with the results:

  • Print which is the file with more matches.
  • Print only the name of the files that has matches.
  • Print the total matches of the pattern in all files.
  • Add a user command: if user inputs number 1 for example, rg_wrapper will print the output of the command in a user friendly way. This is related to #6

Parse `rg` output.

This function runs rg command, and currently it's output is being printed to STDOUT.

Take the output data from rg command and parse it. I did something similar on this other project called chuletas_cleanup_warning, a hook for git. I think there may be a better way to do it, but you can have some inspiration by looking at this code (or better understand what I want to do in this project).

Feature to find partials with keywords on a rails application.

This feature is related to #8 . And is blocked by #3

In the views of a Rails application, you usually render other files inside a layout, these files are called "partials".

Sometimes you need to search a keyword that is displayed on the browser, and you need to find where this keyword is in the source code. You can grep your codebase to find it. But what if the place where is the keyword is a partial file? The partial file can be rendered inside any other view file.

In Rails, partial files starts with underscore, and have extension .html.erb. eg app/views/_mypartialfile.html.erb. The ruby instruction to render this partial is: <%= render partial: 'mypartialfile', locals: {foo: bar} %>. So one regex that can match the pattern render...mypartialfile can be: render.*mypartialfile

This feature for consists in these steps:

  1. Do the search
  2. if the match is inside a file that starts with underscore and ends with .html.erb extension, do another search with ripgrep. This new search will be: rg 'render.*name_file_matched_without_underscore_without_extension'.
  3. Present results to user.

The idea of this feature, is to first search a keyword on the codebase, if there are any matches inside rails partial files, take the name of the file, and find which files are rendering the partial that contains the keyword. This way around, using ruby on rails convention over configuration, you can easily see which route you will visit on the browser, and you will see the keyword you were searching for.

Show a main menu with options to the user.

Show a main menu to the user, the menu should have a "welcome" message, and then show the options the user can take. Up until now, there may be two options

  1. introduce the command you want to send to ripgrep (something like that). The user input will go to this line
  2. Run the example command. You can repeat the command that is run here

When a `rg` command is run, display the results in the same version of `rg` without `--json` flag

This issue is blocked by #3

Currently, when an rg command is run, we can see it's output with the --json flag.

The --json flag is pretty useful FOR THE COMPUTER: the computer can read the data, parse it, and later on do some cool stuff with that parsed data. But for an human the format is AWFUL.

The easy way to run the command for the computer and for the user. Is to run the command the first time with the --json flag, the program will read the data and store the information like described on #3 , and run it a second time without the --json flag, take the output and show it directly to the user.

What would be really cool (and save an unnecesary second call to the OS, imagine you are running the command in a folder with hundreds of thousands of files), would be to run the command only once, and adapt the Struct generated by parsing the json data, and add a function to the Struct to display the data on a human friendly format.

Challenge: add a great TUI framework to the project.

In Go, there is a TUI framework called Bubbletea. Take a look at it and you will see there are awesome things you can do with a terminal and that framework.

I'm pretty sure Rust must have a similar framework, try to find one, mention it here, and let's see if we can implement it on the project. But first I think this project should have some basic functionality

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.