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 option to customize the separator character betwen paths, lines, columns and matches #1842

Closed
noib3 opened this issue Apr 3, 2021 · 6 comments
Labels
enhancement An enhancement to the functionality of the software. help wanted Others are encouraged to work on this issue. rollup A PR that has been merged with many others in a rollup.

Comments

@noib3
Copy link

noib3 commented Apr 3, 2021

As of version 12.1.1, if the --no-heading option is used then a : will be used to separate paths, lines, columns (if the --column option is used) and matches. Is it possible to customize those characters individually?

For example I'd like to use a @ between paths and lines, the default : between lines and columns and a space between columns and matches.

I'm new to ripgrep, I've read the manual but I haven't found anything about it so I assume this behaviour is not currently supported?

@BurntSushi
Copy link
Owner

There is no way to customize it. But the underlying library does support customizing it:

ripgrep/crates/core/args.rs

Lines 789 to 790 in 7923d25

.separator_field_match(b":".to_vec())
.separator_field_context(b"-".to_vec())

I think I would be OK with a PR that adds two flags, one each for customizing the match and context separators for fields emitted in each case.

As a hint, you'll want to use cli::unescape_os to extract out the separator from the CLI argument.

@BurntSushi BurntSushi added enhancement An enhancement to the functionality of the software. help wanted Others are encouraged to work on this issue. labels Apr 3, 2021
@samwho
Copy link

samwho commented Apr 9, 2021

I'm also keen to have this feature, and my use-case is to make sure that the file path and line number are presented in the terminal in a way that can be ctrl+left clicked such that they will open to that line in VSCode.

I use the following settings:

--max-columns=150
--max-columns-preview
--smart-case
--search-zip
--color=auto
--no-heading
--no-messages
--trim

And the output looks like this:

$ rg use
src/entries.rs:186:use super::*;
src/entries.rs:187:use std::io::Cursor;
src/entries.rs:188:use test_case::test_case;

Sometimes, the fact that there is no space after the 2nd colon on each line makes it such that VSCode won't open the file at that line, instead it will initiate a search that yields nothing. Having a space there makes this work 100% of the time.

Removing --trim isn't a solution.

@samwho
Copy link

samwho commented Apr 9, 2021

I've forked the repo and started taking a preliminary look. If I manually change line 789 of ripgrep/crates/core/args.rs to be a space instead of a colon, it doesn't quite do what I'd like. I'd like to be able to keep the colon between the path and the line number, but have a space between the line number and the match.

Would you be open to accepting a PR that changes the printer crate to allow this?

@BurntSushi
Copy link
Owner

@samwho Possibly. It depends on if there are any performance problems created by accepting multiple bytes vs one byte. It's been a while since I've touched that code, but my instinct is that there shouldn't be.

@BurntSushi BurntSushi added the rollup A PR that has been merged with many others in a rollup. label May 31, 2021
BurntSushi pushed a commit that referenced this issue May 31, 2021
These flags permit configuring the bytes used to delimit fields in match
or context lines, where "fields" are things like the file path, line
number, column number and the match/context itself.

Fixes #1842, Closes #1871
BurntSushi pushed a commit that referenced this issue Jun 1, 2021
These flags permit configuring the bytes used to delimit fields in match
or context lines, where "fields" are things like the file path, line
number, column number and the match/context itself.

Fixes #1842, Closes #1871
@fallaciousreasoning
Copy link

@samwho did you come up with a solution? I have the same problem with VSCode link detection, and --field-match-separator " " doesn't quite do what I want, as I lose the line number when clicking a link.

@samwho
Copy link

samwho commented Jul 19, 2022

I'm afraid I didn't.

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. help wanted Others are encouraged to work on this issue. rollup A PR that has been merged with many others in a rollup.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants