Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add replacement into json output #2883

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MagicDuck
Copy link

@MagicDuck MagicDuck commented Sep 8, 2024

fixes #1872

Hi, I am new to this repo so feel free to let me know if there is any way I can improve this PR. As detailed in the liked issue, this functionality is useful for quite a few cases where search/replace type tooling is built around ripgrep. My own neovim plugin is an example of a tool built on top of your great work 😄 : https://github.com/MagicDuck/grug-far.nvim
This change would allow me to show diffs, a much requested feature.

Example:

Given the following text in file /home/andrew/sherlock:

For the Doctor Watsons of this world, as opposed to the Sherlock
Holmeses, success in the province of detective work must always

Searching for Watson with a replacement parameter of Moriarity, here's what a match type item would looks like:

{
  "type": "match",
  "data": {
    "path": {"text": "/home/andrew/sherlock"},
    "lines": {"text": "For the Doctor Watsons of this world, as opposed to the Sherlock\n"},
    "line_number": 1,
    "absolute_offset": 0,
    "submatches": [
      {"match": {"text": "Watson"}, "replacement": {"text": "Moriarity"}, "start": 15, "end": 21}
    ]
  }
}

P.S. Your documentation in code is amazing!

@MagicDuck
Copy link
Author

hmm, not sure why the musleabihf test failed, it just says This job failed...

@MagicDuck
Copy link
Author

hmm, passed now after changing a comment, just a blip I guess 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "replace" text field in --json output that contains replace string for respective matches
1 participant