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

trim whitespace from lines #917

Closed
eljulians opened this issue May 11, 2018 · 7 comments · Fixed by #1017
Closed

trim whitespace from lines #917

eljulians opened this issue May 11, 2018 · 7 comments · Fixed by #1017
Labels
enhancement An enhancement to the functionality of the software. libripgrep An issue related to modularizing ripgrep into libraries.
Milestone

Comments

@eljulians
Copy link

eljulians commented May 11, 2018

What version of ripgrep are you using?

ripgrep 0.8.1 (rev c8e9f25b85)
-SIMD -AVX 

How did you install ripgrep?

From .deb binary.

What operating system are you using ripgrep on?

Linux Mint 18.1 Serena.

Describe your question, feature request, or bug.

First of all, thanks and congratulations for this tool.

I've searched in the help and in the issues, and as I didn't find anything related, I'm opening this suggestion.

I think that would be nice to add an option for trimming the output of the coincident lines. In other words, not to print the indentation of the lines. I think that this could improve the readability of the output.

Currently, for this search:

rg POST views/

I would get the following output:

views/modals/contact.twig
13:               <form action="/contact/send" method="POST" id="form-contact">

(Note the code indentation).

With an option for trimming (e.g. --trim), we would get the following:

views/modals/contact.twig
13:<form action="/contact/send" method="POST" id="form-contact">

(The indentation is now removed from the output).

I really think that this could be a very useful option, since almost every part of the code is indented, except class or function definitions.

PD: this could also work in combination with --max-columns option, so the trimming would be done before the output is filtered with this options. But as I know nothing about ripgrep internals and the feasibility and difficulty of this, I just leave it as a little extra suggestion. Actually this wouldn't be very relevant, since the --max-columns is thought for the output we actually don't want to see. So, if you find appropriate the original suggestion, just implement it as you think it's better for ripgrep. :)

Thanks again and keep up the great work!

@BurntSushi BurntSushi added enhancement An enhancement to the functionality of the software. question An issue that is lacking clarity on one or more points. labels May 11, 2018
@BurntSushi
Copy link
Owner

This is an interesting request. I'm not sure if it's a fit. What would you use it for? I see your example, but indentation is often a useful artifact to see in the output. Is it just an aesthetic thing?

@eljulians
Copy link
Author

@BurntSushi Thanks for such a quick response.

Actually, yes, just an aesthetic thing. Personally, when grepping code, I don't find the indentation interesting: if I later need to edit the file, I already know the line to go to; and if I just need to read the output, because of the lacking context, as we just get the single line, the indentation doesn't actually help in many cases, IMHO.

@BurntSushi
Copy link
Owner

@julenpardo Interesting. So if this flag were added, would you just have it always enabled? How would you use it?

@okdana
Copy link
Contributor

okdana commented May 11, 2018

For whatever it's worth, this is a feature that interests me too, and if you decide that it's a good idea i'd be willing to work on it. I mentioned in #544 that i used to have a wrapper script for ag that achieved this effect, but it was ugly and didn't always work well. Like @julenpardo says, the purpose is just readability; i find that indentation in the search output, disconnected as it is from the surrounding context, is very rarely useful — it just adds visual noise that makes it harder to understand the results.

If the feature were added, i would put --trim (or w/e) in my default options and then just add --no-trim (or w/e) in the rare cases where i needed it turned off.

@eljulians
Copy link
Author

@BurntSushi I was thinking about adding it as a non-default option and then adding it to my ripgrep config file. I mean, I wouldn't make as default such a significant visual change in the output just because it came to my mind :)

@BurntSushi
Copy link
Owner

BurntSushi commented May 11, 2018

@julenpardo Oh, no, yeah, this definitely can't be enabled by default. What I meant is whether you would enable it by default. :-) In any case, I think you and @okdana sold me.

I see two ways this can get added:

  • Someone wants to brave the current printer and do it.
  • I'll add it as part of work on libripgrep. (I have actually started this, and even written down some code. But realistically is probably still a ways away from completion.)

@BurntSushi BurntSushi removed the question An issue that is lacking clarity on one or more points. label May 11, 2018
@BurntSushi
Copy link
Owner

I am working on the new printer right now, and I should be able to add this in with very little fuss.

@BurntSushi BurntSushi added the libripgrep An issue related to modularizing ripgrep into libraries. label Jul 6, 2018
@BurntSushi BurntSushi added this to the libripgrep milestone Jul 6, 2018
@BurntSushi BurntSushi changed the title [Suggestion] Trim coincident lines trim coincident lines Jul 6, 2018
@BurntSushi BurntSushi changed the title trim coincident lines trim whitespace from lines Jul 6, 2018
BurntSushi added a commit that referenced this issue Aug 19, 2018
This commit updates the CHANGELOG to reflect all the work done to make
libripgrep a reality.

* Closes #162 (libripgrep)
* Closes #176 (multiline search)
* Closes #188 (opt-in PCRE2 support)
* Closes #244 (JSON output)
* Closes #416 (Windows CRLF support)
* Closes #917 (trim prefix whitespace)
* Closes #993 (add --null-data flag)
* Closes #997 (--passthru works with --replace)

* Fixes #2 (memory maps and context handling work)
* Fixes #200 (ripgrep stops when pipe is closed)
* Fixes #389 (more intuitive `-w/--word-regexp`)
* Fixes #643 (detection of stdin on Windows is better)
* Fixes #441, Fixes #690, Fixes #980 (empty matching lines are weird)
* Fixes #764 (coalesce color escapes)
* Fixes #922 (memory maps failing is no big deal)
* Fixes #937 (color escapes no longer used for empty matches)
* Fixes #940 (--passthru does not impact exit status)
* Fixes #1013 (show runtime CPU features in --version output)
BurntSushi added a commit that referenced this issue Aug 20, 2018
This commit updates the CHANGELOG to reflect all the work done to make
libripgrep a reality.

* Closes #162 (libripgrep)
* Closes #176 (multiline search)
* Closes #188 (opt-in PCRE2 support)
* Closes #244 (JSON output)
* Closes #416 (Windows CRLF support)
* Closes #917 (trim prefix whitespace)
* Closes #993 (add --null-data flag)
* Closes #997 (--passthru works with --replace)

* Fixes #2 (memory maps and context handling work)
* Fixes #200 (ripgrep stops when pipe is closed)
* Fixes #389 (more intuitive `-w/--word-regexp`)
* Fixes #643 (detection of stdin on Windows is better)
* Fixes #441, Fixes #690, Fixes #980 (empty matching lines are weird)
* Fixes #764 (coalesce color escapes)
* Fixes #922 (memory maps failing is no big deal)
* Fixes #937 (color escapes no longer used for empty matches)
* Fixes #940 (--passthru does not impact exit status)
* Fixes #1013 (show runtime CPU features in --version output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement to the functionality of the software. libripgrep An issue related to modularizing ripgrep into libraries.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants