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

[FR] Extend --replace #1591

Closed
NightMachinery opened this issue May 21, 2020 · 3 comments
Closed

[FR] Extend --replace #1591

NightMachinery opened this issue May 21, 2020 · 3 comments
Labels
doc An issue with or an improvement to documentation.

Comments

@NightMachinery
Copy link

I want to both print a highlighted version of the text a la rg --passthru ... and further process matches. Currently this needs two calls of rg. If --replace supported something like $1:$LINE, I could just run a cut -d: -f1 and cut -d: -f2-1 to get the data, with just one rg call. This should perform better if there are lots of non-matching lines? ... Anyways I think it's a good feature to have.

Perhaps a better option is to add --exec that execs a command? Sth in the spirit of --exec 'cp $1 ~/tmp'.

@NightMachinery NightMachinery changed the title [FR] Extend --replace to allow using the entire line as a variable [FR] Extend --replace May 21, 2020
@okdana
Copy link
Contributor

okdana commented May 21, 2020

I don't know about the --exec thing (doubt he'll go for that), but for the $LINE thing, you're just asking for this, aren't you?

% rg -r '$1:$0' '(foo) .+' <<< 'foo bar'
foo:foo bar

@BurntSushi
Copy link
Owner

I'm not sure I understand the problem here. @NightMachinary Could you please provide a more detailed example with inputs and outputs?

(But yeah, I am unlikely to add an --exec flag or enrich the --replace language.)

@BurntSushi BurntSushi added the question An issue that is lacking clarity on one or more points. label May 21, 2020
@NightMachinery
Copy link
Author

@okdana That $0 should be added to the manpage.
@BurntSushi The --replace functionality I wanted is this $0 which is already there. :)
The --exec flag would be something just like --replace, but instead of printing the output you call $SHELL -c $OUTPUT_HERE. It's actually pretty easy to implement since you have the --replace part down already.

@BurntSushi BurntSushi added doc An issue with or an improvement to documentation. and removed question An issue that is lacking clarity on one or more points. labels May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc An issue with or an improvement to documentation.
Projects
None yet
Development

No branches or pull requests

3 participants