Solvedripgrep Option for outputting absolute paths

It would be great if ripgrep had an option that would change the output file paths to be absolute instead of relative.

9 Answers

✔️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

$ rg 'fn is_empty' | cat
globset/src/    pub fn is_empty(&self) -> bool {
grep-matcher/src/    pub fn is_empty(&self) -> bool {
grep-matcher/src/    fn is_empty(&self) -> bool {
termcolor/src/    pub fn is_empty(&self) -> bool {
ignore/src/    pub fn is_empty(&self) -> bool {
ignore/src/    pub fn is_empty(&self) -> bool {
ignore/src/    pub fn is_empty(&self) -> bool {

$ rg 'fn is_empty' $(pwd) | cat
/home/andrew/rust/ripgrep/globset/src/    pub fn is_empty(&self) -> bool {
/home/andrew/rust/ripgrep/grep-matcher/src/    pub fn is_empty(&self) -> bool {
/home/andrew/rust/ripgrep/grep-matcher/src/    fn is_empty(&self) -> bool {
/home/andrew/rust/ripgrep/termcolor/src/    pub fn is_empty(&self) -> bool {
/home/andrew/rust/ripgrep/ignore/src/    pub fn is_empty(&self) -> bool {
/home/andrew/rust/ripgrep/ignore/src/    pub fn is_empty(&self) -> bool {
/home/andrew/rust/ripgrep/ignore/src/    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
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]\\\/')`


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!

Related Issues:

ripgrep Add support for replace in files
This is more easily accomplished using sed than I think people realize sed is quite a beast and is n...
ripgrep hidden files to be searched by default
The following is @okdana's solution but with the .git folder remaining ignored: ...
ripgrep ripgrep no way to exclude directory e.g. Tests and search for all *.c files
@sumonto you're correct $ rg -w str1 -tc -g '!tests/*' would do what you want So is that not working...
ripgrep Option for outputting absolute paths
I don't see how that's a niche problem judging from others mentioning here they have the with the sa...
ripgrep windows doesn't detect stdin automatically
This is the golden ticket for posterity: Namely running rg pat < file will recursively search the cu...
ripgrep fulltext search
I'm a little late to this issue but I'll share this in case it helps @BurntSushi with any ideas ...
svgo no such file or directory .svgo.yml
I noticed this problem with Yarn after someone had run yarn clean Deleting the .yarnclean file delet...
ohmyzsh compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew
Per #9602 (comment) brew cleanup fixed it for me I am using Apple M1 When I added this line: export ...
angular cli Issue: Cannot read property 'thisCompilation' of undefined
Here is the answer from issues #9793 : npm remove webpack npm install webpack@3.11.0 ...
sdk dotnet build error - the project 'Web' must provide a value for Configuration
I had this infuriating issue when migrating a .NET Core 2.2 app to core 3.0 Steps to reproduce I run...
ionic cli cordova build android error spawn EACCES when I update Android Studio 3.0(Gradle 4.1)
After a long and really frustrating night I got mine woking Description: cordova build android ANDRO...
tqdm Jupyterlab and tqdm_notebook
I confirm this problem on my environment but it is upstream so IMHO nothing can be done on tqdm Plea...
angular cli Error | Could not find plugin "proposal-numeric-separator" | Generating ES5 bundles for differential loading
Try to install @babel/compat-data: ~7.8.0 to devDependencies This is the only workaround which helpe...
angular cli Using invalid environment causes error in build (was "ERROR in Cannot read property 'length' of undefined")
Probably not the same cause but we had the same error (Cannot read property 'length' of undefined) w...
angular cli ng serve method ip not open in another machines
The solution is simple Just bind to the correct interface address via ng serve --host= ...
angular cli Incorrect JS paths when ng build -prod is deployed in a subfolder
When you're deploying to non-root path within a domain you'll need to manually update the <base href...
nativescript cli TNS doctor doesn't recognize Xcode (High Sierra)
HI @philipfeldmann Can yhou please run xcodebuild -version and paste the output? May be Xcode is ins...
angular cli Installation error: permission denied for node-sas
sudo npm install -g --unsafe-perm --verbose @angular/cli Installation error (node-sass) with: node v...
angular cli ng build -prod Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
Instead of use ng build --prod use ng build --env=prod UPDATE As many of us (thx) have mention this ...
psysh Not working after upgrading to PHP 7.3
May I know how do you open this file and drop in the code you mentioned? Thanks ...
expo cli Expo fails to start the project: error Invalid regular expression: /(.*\\__fixtures__
Got this issue today on windows but don't need to downgrade node Description I just initialize a new...
angular cli Property 'controls' does not exist on type 'AbstractControl'.
Got it! Looked at the docs - FormArray The FormArray class contains the controls property ...
angular cli [Bug] cli needs to be reloaded when a lazy loaded module is added in routes (FIXED)
I recomended change { path: 'user-panel' loadChildren: './user-panel/user-panel.module#UserPanelModu...
angular cli AOT build fails
I noticed same problem and after npm i enhanced-resolve@3.3.0 I can build with AOT ...
angular cli Cannot find name 'require'. using relative paths...
Ahhh here we go try adding declare var require: any; To src/typings.d.ts I am using a config with re...
expo cli XDLError: ValidationError: "scheme" is not allowed
can you try removing the .expo directory? rm -rf .expo in your project Description I'm having this e...
ionic cli Error: Cannot find module '@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/utils'
Try npm i @ionic/angular-toolkit@latest This worked in my project. Description: I was trying to star...
angular cli "No NgModule metadata found for 'AppModule'" after Upgrade to Angular 5.1.0 and AngularCli 1.6.0
I got the same error The issue is fixed only when i manually re installed angular/cli The webpack sh...
cli pod install failure with glog
what helped me: sudo xcode-select --switch /Applications/ Ask your Question I have been try...
angular cli ng serve doesn't listen other than localhost
Works with command ng serve --host OS? Windows 7 8 or 10 Linux (which distribution) Mac OSX ...
streamlink urllib3 (1.25.1) or chardet (3.0.4) doesn't match a supported version
Hello there I received this warning on Elementary OS 0.4.1 (based on Ubuntu 16.04.2) after installin...
terragrunt Upgrading to Terraform 0.12: separate configuration file for Terragrunt?
Hi all Hi! I'm one of the engineers at HashiCorp who works on Terraform Core As you might be aware ...
expo cli Could not load expo Network response timed out
The Network response timed out error means your phone can not connect to the Expo CLI running on you...
angular cli ng: command not found
Removing NODE and using NVM instead fixed a lot of issues After installing angular-cli with the help...
angular cli ng build fails with error Cannot find module 'webpack/lib/node/NodeTemplatePlugin' after updating to v1.3.0
I faced this issue many times recently and always the fix worked for me is : Bug Report or Feature R...
angular cli -bash: ng: command not found
This was a pain to figure out Please provide us with the following information: OS? Mac OSX (Seirra)...
angular cli Uncaught TypeError: Cannot read property 'apply' of undefined on new install
Downgraded to zone.js@0.8.5 and the problem disappeared. Bug Report or Feature Request (mark with an...
angular cli I am on Angular 5 and CLI 1.5 and I get an error
I faced this error after updating a non-CLI project to Angular 5 and @ngtools/webpack 1.8.0 ...
amplify cli Many-To-Many
You can implement many to many yourself using two 1-M @connections and a joining @model ...
cli How to skip one stage from multi-stage docker build
Docker 18.06 has been released Description We have Multistage docker build that creates rpm in each ...
angular cli Error in multi styles
Paths in angular-cli.json are relative to the project root (src/ normally) For instance you have the...
angular cli Error loading npm linked custom library with aot
It seems like this is a issue caused by Typescript and not by Angular CLI Typescript has problems re...
sdk dotnet new console, publish, makes a dll not an exe
Can we reduce the confusion somehow? I work on .NET Core and I was confused <OutputType>Exe</OutputT...
expo cli expo build fails inside xdl with "Cannot read property 'forEach' of undefined"
Try changing assetBundlePatterns: [**/*] to assetBundlePatterns: [assets/*] in app.json ...
nest cli Error: Cannot find module '@nestjs/schematics/package.json'
try yarn global add @nestjs/schematics I'm submitting a.. Current behavior I already global add nest...
ohmyzsh how to enable username and hostname in the default theme?
In fact I finally found the solution for the problem I do want to stick with the default theme but I...
angular cli Cannot find module '@angular/compiler-cli' when running ng serve
Remove angular-cli from your package.json and replace it with @angular/cli $ npm uninstall angular-c...
ionic cli Ionic build android, Error: spawn EACCES
@alexharvey assuming you're on mac (or linux): What version of the CLI are you using? Output of ioni...
angular cli is not a function
I have same issue Finally It looks like caused by a scheme changing The item assets now is an array ...