It's fast indeed. And I can't help keeping promoting the combination with fzf :) For those who want to try it out, this is a Powershell function but the same principle applies in any shell. Does ripgrep then puts fuzzy searching in the resulting files+text on top while showing context in bat:
function frg {
$result = rg --ignore-case --color=always --line-number --no-heading @Args |
fzf --ansi `
--color 'hl:-1:underline,hl+:-1:underline:reverse' `
--delimiter ':' `
--preview "bat --color=always {1} --theme='Solarized (light)' --highlight-line {2}" `
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3'
if ($result) {
& ($env:EDITOR).Trim("`"'") $result.Split(': ')[0]
}
}
There are other ways to approach this, but for me this is a very fast way of nailing down 'I now something exists in this multi-repo project but don't know where exactly nor the exact name'edit this comes out of https://github.com/junegunn/fzf/blob/master/ADVANCED.md and even though you might not want to use most of what is in there, it's still worth glancing over it to get ideas of what you could do with it
I wrote a bash version of this:
I've never really seen PowerShell beyond minimal commands, but after seeing the parent, I definitely think it has the superior syntax of the shells. Especially for scripts.
I expected to like Powershell when I began working somewhere with a lot of Windows (after decades of mostly Linux). I figured on paper this sounds like it has learned many important lessons that Unix shells could learn but (at least the popular ones) didn't, it's been given a blank canvas, the principles it's working to make sense, it has good people behind it. So I even undertook to write a modest new piece of glue code in Power Shell, after all if it had been on Linux I'd definitely consider the Bourne shell as well as Python for the work...
Then I tried it and I strongly dislike it. The syntax is clunky, it's really no better than popular Unix shells at being a "real" programming language, and yet it's not as good as they are at being just a shell either.
It also just doesn't feel like a quality product. On my work Windows laptop, Powershell will sometimes not quite bother flushing after it starts, so I get the banner text and then... I have to hit "enter" to get it to finish up and write a prompt. In JSON parsing the provided JSON parser has some arbitrary limits... which vary from one version to another. So code which worked fine on machine #1 just silently doesn't work on machine #2 since the JSON parsers were changed and nobody apparently thought that was worth calling out. If you told me this was the beta of Microsoft's new product I'd be excited but feel I needed to provide lots of feedback. Knowing this is the finished product I am underwhelmed.
I find the built-in commands rough. "curl https://jrock.us" to see if my website is up used to involve opening Internet Explorer to accept some sort of agreement. Now it just flashes the terminal, moves the cursor to the far right hand side of the screen, and blinks for a while. I like the Linux version of curl better...
Ironically, windows 10+ comes with real curl installed, to use it type curl.exe instead
I had no idea!
As it turns out, the reason that "curl ..." doesn't work is because it pops up a window below all of my other windows saying that certificate revocation information is unavailable, and would I like to proceed. After that it does download my web page!
That’s independent of the shell, and is I believe a bug in the terminal emulator. There is an open source Windows Terminal you can separately install and that is so much better.
Nope, windows terminal definitely does this too. Just last week I was trying to install WSL, and thought it had frozen at 20% and was trying to figure out what went wrong ... turns out it had already booted but powershell had stopped flushing output.
YMMV (and obviously does). I think that powershell is night and day better than bash (etc) as a programming language.
Maybe if the "popular" shells, but http://www.nushell.sh/ is looking better and better
I use it near exclusively. Love nu.
nu acknowledged powershell as one of its inspirations, yeah!!
Unlike most Microsoft things it was not constrained by back compatibility.
I generally don't like MS software, but their commitment to back compatibility is worth calling out.
PowerShell is the worst of all worlds. Its a terrible shell compared to bash/zsh/whateversh, and for anything complex enough to need a long script you’re far better off in Python.
A lot of people sleep on PowerShell, possibly because some of the syntax is a little clunky (and quite slow compared to some other shells, I will freely admit). That being said, I'd argue object oriented programming is a massive improvement over text oriented programming. I never want to touch awk again!
The only thing making it less than a total win is its handling of piped errors and `set -e`. The programming model itself is far superior to 'stringly-typed' sh.
1. Thanks for this, instantly added to my dotfiles
2. You nerd-sniped me into getting rid of the unnecessary `cut` process :)
Thanks! I have tried using bash substitution to solve it but failed (I just learned the difference between "#" and "##").
FYI, these substitutions are POSIX:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...
Also a couple mnemonic hints:
% vs #. On US keyboards, # is shift-3 and is to the left of % which is shift-5. So # matches on the start (left) and % matches on the end (right).
# vs ## (or % vs %%). Doubling the character makes the match greedy. It's twice a wide so it needs to eat more.
Bash also supports ${parameter/pattern/string} and ${parameter//pattern/string} (and a bunch others besides) which are not POSIX:
https://www.gnu.org/software/bash/manual/html_node/Shell-Par...
Thanks for the great information!
Jesus, bash really is an abomination
I wrote a zsh version of this:
Awesome. Thanks. Saved me some time. I haven't used the fzf integration like this.
I wrote a fish version, and simplified it:
Still not a fan of the string-based injections based on the colon and newline characters, but all versions suffer from it. (also: nice that fzf does the right thing and prevents space and quote injection by default).I love this, thank you! If anyone else wants to open the file in VScode, the command is
Wow, nice, thanks! :heart:
great stuff
Vim is almost broken for me without fzf+rg. Feels like I’m manually grinding coffee instead of using electricity.
This comment got me to get out my French press and manually grind some beans. It wasn't a meditative and calming as I remember, and the coffee tastes a little...dusty. I guess it's time for me to update my vimrc.
Aeropress is a direct upgrade from french press and uses way less coffee
I hadn't heard of this before. Thanks!
Add one or a few drops of water to your roasted coffee beans with your hand and shake well after weighing it out to stop the grinds from sticking to the walls of your grinder from static.
This thread took a turn
I love that a ripgrep article has such a deeply nerdy coffee thread…
Ah, RDT (Ross Droplet Technique)[0].
A little atomizer (“spritz” bottle) of plain water serves well here. NB: this is for single-dose grinding - e.g. measuring a small amount of beans loaded into a grinder to grind immediately. If you have a grinder with a “big” hopper on top that has (e.g.) the weeks worth of coffee (even though you grind on-demand for ea. espresso/french press/aeropress/pourover/drip/…) this isn’t for you.
[0] https://thebasicbarista.com/en-us/blogs/topics/how-rdt-broke...
I use my Aeropress every day but I wouldn't say it's "better" than French press, it's just different. Using less coffee but finer ground changes the characteristics of the brew quite a bit (probably some technical reason about extraction level or something).
I’m glad my analogy sprouted another branch in this conversation :)
Which integration for ripgrep do you use with Vim?
Can't speak for OP, but I use telescope for neovim and I don't think I could use (neo)vim without it.
Telescope is cool, but last I checked it was neovim only or recommended and I’m a regular-Vim holdout.
I modified some functions from: https://github.com/junegunn/fzf.vim
And added my keyboard shortcuts.
Oh. Thanks for the tip. This might make me finally embrace powershell. I’ve been using WSL+zsh+fzf as a Windows CLI for continuity with day job Mac tools, but git CLI performance is only usable inside the WSL file system.
You can also add a small script to your WSL under `/usr/local/bin/git`:
This allows you to use `git` in your WSL shell but it'll pick whichever executable is suitable for the filesystem that the repo is in :)Thank you. I will use this.
The code as written above only works if you haven't changed the mountpoint for your windows partition (i.e. from /mnt), consider that
This might make me finally embrace powershell
Yeah, I have a bit of a love-hate relationship with it. But I actually have that with all shells out there. I don't know if it's just me or the shells, or (the most likely I think): a bit of both. But PS is available out of the box and using objects vs plain text is a major win in my book, and even though I still don't know half of the syntax by heart it feels less of an endless fight than other shells. And since I use the shell itself for rather basic things and for the rest only for tools (like shown here), we get along just fine.
With fzf you can add lots of files to git while skipping some if you want:
With that in the [alias] section of a gitconfig file, running git fza brings up a list of modified and not yet added files, space toggles each entry and moves to the next entry.That alias as well as fzf+fd really speed up some parts of my workflow.
Oh and shameless plug for my guide on what to include in your zsh setup on macOS: https://gist.github.com/aclarknexient/0ffcb98aa262c585c49d4b...
Add the preview to see what you're actually stashing:
And that's just the start: it could even be that by binding a key to the fzf reload command to then display the diff in it's finder, and in turn a key to stage the selected line, you could turn that into an interactive git staging tool.Nice. I'll have to try that out!
That blew my mind. I've used fzf a couple time here and there, but now I Get It. Thanks!
Infact I would recommend a step further to integrate rip-grep-all (rga) with fzf that can do a fuzzy search not just on text files but on all types of files including pdfs, zip files. More details here [1]
[1] https://github.com/phiresky/ripgrep-all/wiki/fzf-Integration
That's really nice, thanks. Long ago there was the Google Desktop Search where you could 'Google' your local documents. But the difference is that that worked with an index, so I imagine it's faster if you have thousands of pdfs en epubs.
Even longer ago, there was `glimpse`: https://www.linuxjournal.com/article/1164 which is still available. [1] glimpse's index-builds are like 10X slower than `qgrep` mentioned elsethread. `qgrep` also seems to have faster search (though I only tried a few patterns) and `qgrep` does not allow spelling errors like `glimpse`.
Neither `glimpse` nor `qgrep`, to my knowledge, directly supports pre-processing / document conversion (like `pdftotext`), though I imagine this would be easy to add to either replicating Desktop Search. (Indirectly, at some space cost, you could always dump conversions into a shadow file hierarchy, index that, and then translate path names.)
[1] https://manpages.ubuntu.com/manpages/focal/man1/glimpse.1.ht...
Not bad. For those who want to try it, install all prereqs with: choco install fzf bat ripgrep
How do you scroll the preview window with keyboard ?
shift-up/down
I've made a video and blog post about it here: https://nickjanetakis.com/blog/customize-fzf-ctrl-t-binding-...
I also made https://nickjanetakis.com/blog/using-fzf-to-preview-text-fil... which covers how to modify fzf's built in CTRL+t shortcut to allow for previews too. CTRL+t is a hotkey driven way to fuzzy match a list of files.
This is a gem; thank you.
This is pretty much my exact use of ripgrep, too. I use it as a starting point to zero in on files/projects in a several-hundred repo codebase, and then go from there....
I use it neovim with fzf search.
Thanks for this!