5 ms·
The -pre flag is rarely mentioned but was a revelation for me in for dealing with MS office files and pdf documents. I use it every single day. alias rgpre='rg
by SanchoPanda 8y ago
The -pre flag is rarely mentioned but was a revelation for me in for dealing with MS office files and pdf documents. I use it every single day.
alias rgpre='rg -i --max-columns=1500 --pre rgpre'
*edit
Adding my script here, and would be grateful for any improvements. Goal was to catch doc,docx,ppt,pptx,xls,xlsx, epub, mobi, and pdf and still work on termux with default packages there only.
https://gist.github.com/ColonolBuendia/314826e37ec35c616d70506c38dc65aa https://gist.github.com/ColonolBuendia/314826e37ec35c616d705...
- ronjouch 8y agoThat's indeed a lovely script. It makes for seamless searching my trove of PDFs and ebooks. Thanks for sharing it, and thanks BurntSushi for considering including it to rg's README :) !
- burntsushi 8y agoThat's a lovely script. And yeah, I should try to publicize --pre a bit more, since it is pretty handy. I don't use it a ton myself, but when it works, I'm really thankful for it. (That might sound weird since it's in my tool, but I was initially kind of opposed to adding it.) One bummer is that it can slow ripgrep down quite a bit: one process per file is not good. As a tip, if you add --pre-glob '*.{pdf,xlsx,docx,doc,pptx,...}' and whatever else you need, then ripgrep will only invoke an extra process for those files specifically, which can significantly speed up ripgrep if you're searching a mixed directory (or just want to have `--pre` on by default).
- SanchoPanda 8y agoThat addition was an incredible time savings in my average search, I'm very grateful. A more prominent mention, and a sample script, would be very useful imho. Just googling for a way to do this for even just one of these file types yields inferior commercial solutions at best, often just nothing. And while I'm not sure how to make it much faster from a search perspective, I was able to find a 40% improvement in invocation by switching from rgpre to rgg as my alais. I ended here: alias rgg='rg -i --pre-glob '*.{pdf,xlsx,xls,docx,doc,pptx,ppt,html,epub,mobi}' --pre rgpre'
- burntsushi 8y agoHah nice! I'll noodle on this and figure out how to publicize it more. Your script would be very helpful as an example. Do you mind if I use it in the docs somewhere?
- SanchoPanda 8y agoPlease feel free. Even a cursory mention of the ability at the end of the readme would likely help many. With a verbatim script and verbatim command using it helping many more. I only stumbled upon this feature with enough context to really get it in the Ubuntu man pages and I don't know if I ever would have gotten to the pre-glob feature to be honest. I do believe that technically oriented non-programmers would be the biggest winners from more exposure around it.
- burntsushi 8y agoGreat! I filed an issue for it: https://github.com/BurntSushi/ripgrep/issues/1252 https://github.com/BurntSushi/ripgrep/issues/1252