Comments (10)
$ echo 'fig
^mango'
fig
!!:s^mango
lolwut
from ripgrep.
Yeah, odd indeed. Here's mine:
$ printf '%b' "$s" | rg --trace -UF 'fig
^mango'
DEBUG|rg::flags::config|crates/core/flags/config.rs:41: /home/andrew/.ripgreprc: arguments loaded from config file: ["--max-columns-preview", "--colors=match:bg:0xff,0x7f,0x00", "--colors=match:fg:white", "--colors=line:none", "--colors=line:fg:magenta", "--colors=path:fg:green", "--type-add=got:*_test.go"]
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1099: using heuristics to determine whether to read from stdin or search ./ (is_readable_stdin=true, stdin_consumed=false, mode=Search(Standard))
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1112: heuristic chose to search stdin
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1260: found hostname for hyperlink configuration: duff
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1270: hyperlink format: ""
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:174: using 1 thread(s)
DEBUG|grep_regex::config|crates/regex/src/config.rs:175: assembling HIR from 1 fixed string literals
TRACE|grep_regex::matcher|crates/regex/src/matcher.rs:66: final regex: "(?:fig\n\\^mango)"
TRACE|grep_regex::literal|crates/regex/src/literal.rs:59: skipping inner literal extraction, no line terminator is set
DEBUG|globset|crates/globset/src/lib.rs:453: built glob set; 0 literals, 0 basenames, 12 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
TRACE|rg::search|crates/core/search.rs:254: <stdin>: binary detection: BinaryDetection(Convert(0))
TRACE|grep_searcher::searcher|crates/searcher/src/searcher/mod.rs:728: generic reader: reading everything to heap for multiline
TRACE|grep_searcher::searcher|crates/searcher/src/searcher/mod.rs:732: generic reader: searching via multiline strategy
apple fig
^mango banana
Where the regex is "(?:fig\n\\^mango)"
is what I'd expect.
You seem to be having some kind of extra !!:s
being inserted between the \n
and the \^
. I dunno where that is coming from. Can you try a different shell?
Okay, that made me try a different shell. I use zsh by default. So I dropped into bash:
[andrew@duff ripgrep] printf '%b' "$s" | rg --trace -UF 'fig
^mango'
DEBUG|rg::flags::config|crates/core/flags/config.rs:41: /home/andrew/.ripgreprc: arguments loaded from config file: ["--max-columns-preview", "--colors=match:bg:0xff,0x7f,0x00", "--colors=match:fg:white", "--colors=line:none", "--colors=line:fg:magenta", "--colors=path:fg:green", "--type-add=got:*_test.go"]
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1099: using heuristics to determine whether to read from stdin or search ./ (is_readable_stdin=true, stdin_consumed=false, mode=Search(Standard))
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1112: heuristic chose to search stdin
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1260: found hostname for hyperlink configuration: duff
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1270: hyperlink format: ""
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:174: using 1 thread(s)
DEBUG|grep_regex::config|crates/regex/src/config.rs:175: assembling HIR from 1 fixed string literals
TRACE|grep_regex::matcher|crates/regex/src/matcher.rs:66: final regex: "(?:fig\n!!:s\\^mango)"
TRACE|grep_regex::literal|crates/regex/src/literal.rs:59: skipping inner literal extraction, no line terminator is set
DEBUG|globset|crates/globset/src/lib.rs:453: built glob set; 0 literals, 0 basenames, 12 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
TRACE|rg::search|crates/core/search.rs:254: <stdin>: binary detection: BinaryDetection(Convert(0))
TRACE|grep_searcher::searcher|crates/searcher/src/searcher/mod.rs:728: generic reader: reading everything to heap for multiline
TRACE|grep_searcher::searcher|crates/searcher/src/searcher/mod.rs:732: generic reader: searching via multiline strategy
This sadly therefore looks like something bash is doing. I haven't the faintest clue what it is. And I'm surprised by it, given that single quotes are being used here.
from ripgrep.
Oh! Didn't expect that! I'll try to check the bash
bug list tomorrow. It feels like a regression, since this was working for me 3 years ago.
from ripgrep.
Interestingly, I cannot reproduce this:
$ s='apple fig\n^mango banana\n123 456\ndragon$\nunicorn\n'
$ printf '%b' "$s" | rg -UF 'banana
123'
^mango banana
123 456
$ printf '%b' "$s" | rg -UF 'fig
^mango'
apple fig
^mango banana
Can you re-run with --trace
? That might show some information.
I can't make heads or tails of this. The search shouldn't care about ^
.
from ripgrep.
Oh. I did wonder if there's something wrong/different on my machine. Here's the --trace
output:
$ printf '%b' "$s" | rg -UF --trace 'fig
^mango'
DEBUG|rg::flags::parse|crates/core/flags/parse.rs:97: no extra arguments found from configuration file
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1099: using heuristics to determine whether to read from stdin or search ./ (is_readable_stdin=true, stdin_consumed=false, mode=Search(Standard))
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1112: heuristic chose to search stdin
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1260: found hostname for hyperlink configuration: abcd
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1270: hyperlink format: ""
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:174: using 1 thread(s)
DEBUG|grep_regex::config|crates/regex/src/config.rs:175: assembling HIR from 1 fixed string literals
TRACE|grep_regex::matcher|crates/regex/src/matcher.rs:66: final regex: "(?:fig\n!!:s\\^mango)"
TRACE|grep_regex::literal|crates/regex/src/literal.rs:59: skipping inner literal extraction, no line terminator is set
DEBUG|globset|crates/globset/src/lib.rs:453: built glob set; 0 literals, 0 basenames, 12 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
TRACE|rg::search|crates/core/search.rs:254: <stdin>: binary detection: BinaryDetection(Convert(0))
TRACE|grep_searcher::searcher|crates/searcher/src/searcher/mod.rs:728: generic reader: reading everything to heap for multiline
TRACE|grep_searcher::searcher|crates/searcher/src/searcher/mod.rs:732: generic reader: searching via multiline strategy
Final regex (?:fig\n!!:s\\^mango)
seems very odd, compared to (?:banana\n123)
and (?:fig\n\\^mango)
(when I use $'fig\n^mango'
).
from ripgrep.
I posted about this on twitter, and it looks like some kind interaction substitution based on history. But the fact that it's happening inside a single quoted string suggests this might be a bash bug.
from ripgrep.
Discussion in the bug-bash group: https://lists.gnu.org/archive/html/bug-bash/2023-12/msg00064.html
from ripgrep.
Thanks for the follow-up! I read through that thread and I can't even tell whether they consider the behavior a bug or not. It sounds like they are just going to fix the docs?
from ripgrep.
I think they are going to fix it for single quotes (along with documentation update):
The quick substitution feature didn't pay attention to the quoting state,
however, and just translated the line into a standard history expansion,
which was then skipped. The fix is to have it inhibit quick substitution
the same way as other history expansions.
from ripgrep.
Yeah I saw that. But the other part of their message was "This is a standard form of history expansion, described in the man page." That confused me hah. Either way, quite interesting!
from ripgrep.
Related Issues (20)
- cursor disappearing HOT 1
- failing test: f2361_sort_nested_files
- The same `LineTerminator` is being used for searching and printing
- `--pre` doesn't work on Windows (CMD, MSYS2 bash, Powershell) HOT 16
- ARMv8 release binary for RPI 5 HOT 2
- ripgrep 14.1.0 exit silently when stdin is not connected (GNU parallel without --tty) HOT 8
- Feature Request: search for binary data by supplying a hex string HOT 9
- Is it possible to add a search for just a set of directories as a type? HOT 1
- Allow following symlinks to files HOT 2
- WalkDir ignores files that are in .gitignore outside of current git repository HOT 2
- Multiple quirks in ignore behavior HOT 1
- BUG: exit code on windows not stable (wrong on first run, then stable), seems to leak HOT 9
- pcre2 reset match \K drops submatches HOT 1
- ripgrep is slower than LTREP matching `[A-Z][A-Z]+` HOT 3
- --files is listing files that won't be searched into HOT 4
- ripgrep ignore files inside `.github` folder HOT 5
- Potentially incorrect or undocumented .gitignore files handling
- `--text` flag only works if it's late in the command HOT 1
- Ripgrep parsing files in gitignore HOT 1
- Searching disk images for a text regex causes rg to be SIGKILL'd HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ripgrep.