Solvedripgrep Option for outputting absolute paths
✔️Accepted Answer
I don't see how that's a niche problem, judging from others mentioning here they have the with the same issue.
I guess I need to stop using the word "niche" because you aren't the first to see it as an invitation to pick at my use of it. The problem is that the word "niche" bundles up quite a bit, and re-litigating this every single time I say "no" to something is seriously tiring. To elaborate, what I'm saying here is that "this feature, in balance doesn't carry its weight." Namely, that the number of folks clamoring for it, in the context of the problems it solves and in the context of available work arounds, in my opinion, do not sufficiently counter balance the work required to implement it, maintain it and the time required to respond to future feature requests and bug reports related to this feature. This is an inherently subjective assessment on my part as the maintainer, since the only data I have is my ability to guess based on responses in the issue tracker. Moreover, I find it very difficult to, on occasion, trust the perspective of end users implicitly because they often have tunnel vision and unfairly weight their pet features above all other costs that are, frankly, invisible to them but highly visible to me.
The end result is a delicate balance. As such, I have frequently reversed course on features I was previously opposed to as my calculus changes due to updated data. That could happen for this feature too, but three people asking for it to service use cases that I find down right strange ain't gunna do it. Sorry.
For example:
I want to be able to open the file in sublime text (subl) or in fact any editor
This just doesn't make any sense to me. I do things like this all the time:
$ vim $(rg -l pattern)
and it just works.
If, for some reason, your particular editor is incapable of dealing with relative file paths (which seems crazy to me, but hey, maybe it's a thing), then I really don't see why the onus should be on ripgrep to solve that problem. Moreover, ripgrep can already emit absolute file paths because the file paths it does emit are based directly on the file path you give it in the first place. Compare:
$ pwd
/home/andrew/rust/ripgrep
$ rg 'fn is_empty' | cat
globset/src/lib.rs: pub fn is_empty(&self) -> bool {
grep-matcher/src/lib.rs: pub fn is_empty(&self) -> bool {
grep-matcher/src/lib.rs: fn is_empty(&self) -> bool {
termcolor/src/lib.rs: pub fn is_empty(&self) -> bool {
ignore/src/gitignore.rs: pub fn is_empty(&self) -> bool {
ignore/src/types.rs: pub fn is_empty(&self) -> bool {
ignore/src/overrides.rs: pub fn is_empty(&self) -> bool {
$ rg 'fn is_empty' $(pwd) | cat
/home/andrew/rust/ripgrep/globset/src/lib.rs: pub fn is_empty(&self) -> bool {
/home/andrew/rust/ripgrep/grep-matcher/src/lib.rs: pub fn is_empty(&self) -> bool {
/home/andrew/rust/ripgrep/grep-matcher/src/lib.rs: fn is_empty(&self) -> bool {
/home/andrew/rust/ripgrep/termcolor/src/lib.rs: pub fn is_empty(&self) -> bool {
/home/andrew/rust/ripgrep/ignore/src/gitignore.rs: pub fn is_empty(&self) -> bool {
/home/andrew/rust/ripgrep/ignore/src/types.rs: pub fn is_empty(&self) -> bool {
/home/andrew/rust/ripgrep/ignore/src/overrides.rs: pub fn is_empty(&self) -> bool {
eg when using rg through a command that cd's to another directory first (so pwd is not the correct thing)
Sorry, but I don't understand this. If you run rg foo
without an explicit path, then that's equivalent to rg foo ./
which is in turn equivalent to rg foo $(pwd)
in terms of the directory that is searched.
or when (as in my example above), no file name is shown at all
This is entirely expected and matches the standard behavior of grep
. If ripgrep only searches one file given by explicit arguments (in this case, your glob must have matched exactly one file), then it does not print the file name by default. You can force the issue with the --with-filename
flag. Case in point:
$ rg 'fn is_empty' ignore/src/git*.rs
165: pub fn is_empty(&self) -> bool {
$ rg 'fn is_empty' ignore/src/git*.rs --with-filename
ignore/src/gitignore.rs
165: pub fn is_empty(&self) -> bool {
Describing this behavior as "unusable" is seriously unproductive.
Other Answers:
Thank you for making it clear that ripgrep already can emit absolute file paths. It is a bit embarrassing that I did not realize this myself..
I changed my alias from
alias rg `%@if[%TREE_ROOT==none,%DEFAULT_TREE_ROOT%,%TREE_ROOT%]\base-00\exe\rg ^
%$ -n --no-ignore-parent --color never --no-heading . ^
| b sed 's/^^/%@replace[\,\\\,%_CWD]\\\/')`
to
alias rg `%@if[%TREE_ROOT==none,%DEFAULT_TREE_ROOT%,%TREE_ROOT%]\base-00\exe\rg ^
%$ -n --no-ignore-parent --color never --no-heading %_CWD`
Now it works exacly like I want, and I have no need for the option that I initially asked for.
Thank you for making ripgrep, it is a great tool!
It would be great if ripgrep had an option that would change the output file paths to be absolute instead of relative.