Skip to content

Add option to customize the separator character betwen paths, lines, columns and matches #1842

Closed

Description

@noib3

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?

Activity

  1. BurntSushi commented on Apr 3, 2021

    @BurntSushi
    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.

  2. added
    enhancementAn enhancement to the functionality of the software.
    help wantedOthers are encouraged to work on this issue.
    on Apr 3, 2021
  3. samwho commented on Apr 9, 2021

    @samwho

    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.

  4. samwho commented on Apr 9, 2021

    @samwho

    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?

  5. BurntSushi commented on Apr 9, 2021

    @BurntSushi
    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.

  6. added
    rollupA PR that has been merged with many others in a rollup.
    on May 31, 2021
  7. added 2 commits that reference this issue on May 31, 2021
    9bbd163
    0adfb63
  8. fallaciousreasoning commented on Jul 18, 2022

    @fallaciousreasoning

    @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.

  9. samwho commented on Jul 19, 2022

    @samwho

    I'm afraid I didn't.

  10. added a commit that references this issue on Feb 13, 2024
    578e199
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAn enhancement to the functionality of the software.help wantedOthers are encouraged to work on this issue.rollupA PR that has been merged with many others in a rollup.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions