7 ms·
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 pr
by stinos 3y ago
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 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
- pknopf 3y agoThanks for this!
- majkinetor 3y agoNot 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 ?
- stinos 3y agoshift-up/down
- nickjj 3y ago> How do you scroll the preview window with keyboard ? alias pf="fzf --preview='less {}' --bind shift-up:preview-page-up,shift-down:preview-page-down" That will let you run `pf` to preview files in less and lets you use shift + arrow keys to scroll the preview window. No dependencies are needed except for fzf. If you want to use ripgrep with fzf you can set FZF_DEFAULT_COMMAND to run rg such as `export FZF_DEFAULT_COMMAND="rg ..."` where ... are your preferred rg flags. This full setup is in my dotfiles at https://github.com/nickjj/dotfiles https://github.com/nickjj/dotfiles. I've made a video and blog post about it here: https://nickjanetakis.com/blog/customize-fzf-ctrl-t-binding-to-preview-files https://nickjanetakis.com/blog/customize-fzf-ctrl-t-binding-... I also made https://nickjanetakis.com/blog/using-fzf-to-preview-text-files-on-the-command-line-and-within-vim 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.
- wanderingmind 3y agoInfact 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 https://github.com/phiresky/ripgrep-all/wiki/fzf-Integration
- fsiefken 3y agoThat'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.
- cb321 3y agoEven longer ago, there was `glimpse`: https://www.linuxjournal.com/article/1164 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.html https://manpages.ubuntu.com/manpages/focal/man1/glimpse.1.ht...
- tambourine_man 3y agoVim is almost broken for me without fzf+rg. Feels like I’m manually grinding coffee instead of using electricity.
- stirfish 3y agoThis 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.
- orangepurple 3y agoAeropress is a direct upgrade from french press and uses way less coffee
- stirfish 3y agoI hadn't heard of this before. Thanks!
- orangepurple 3y agoAdd 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.
- iknowstuff 3y agoThis thread took a turn
- bch 3y agoI love that a ripgrep article has such a deeply nerdy coffee thread… > Add one or a few drops of water to your roasted coffee beans 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-changed-the-game-benefits-and-reasons-why-people-spray-their-coffee-beans https://thebasicbarista.com/en-us/blogs/topics/how-rdt-broke...
- shoover 3y agoOh. 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.
- fhlu 3y agoYou can also add a small script to your WSL under `/usr/local/bin/git`: GIT_WINDOWS="/mnt/c/Program Files/Git/bin/git.exe" GIT_LINUX="/usr/bin/git" case "$(pwd -P)" in /mnt/?/*) case "$@" in # Needed to fix prompt, but it breaks things like paging, colours, etc rev-parse*) # running linux git for rev-parse seems faster, even without translating paths exec "$GIT_LINUX" "$@" ;; *) exec "$GIT_WINDOWS" -c color.ui=always "$@" ;; esac ;; *) exec "$GIT_LINUX" "$@" ;; esac 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 :)
- stinos 3y agoThis 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.
- imakira 3y agoI wrote a bash version of this: function frg { result=`rg --ignore-case --color=always --line-number --no-heading "$@" | 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'` file="${result%%:*}" linenumber=`echo "${result}" | cut -d: -f2` if [ ! -z "$file" ]; then $EDITOR +"${linenumber}" "$file" fi }
- zero_k 3y agoWow, nice, thanks! :heart:
- seanw444 3y agoI'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.
- bbkane 3y agoMaybe if the "popular" shells, but http://www.nushell.sh/ http://www.nushell.sh/ is looking better and better
- evntdrvn 3y agonu acknowledged powershell as one of its inspirations, yeah!!
- steveklabnik 3y agoI use it near exclusively. Love nu.
- Natfan 3y agoA 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!
- bloopernova 3y agoWith fzf you can add lots of files to git while skipping some if you want: fza = "!git ls-files -m -o --exclude-standard | fzf -m --print0 | xargs -0 git add" 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/0ffcb98aa262c585c49d4b3f3ae24019 https://gist.github.com/aclarknexient/0ffcb98aa262c585c49d4b...
- stinos 3y agoAdd the preview to see what you're actually stashing: git ls-files -m -o --exclude-standard | fzf -m --print0 --preview "git diff {1}" | .... 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.
- bloopernova 3y agoNice. I'll have to try that out!
- kstrauser 3y agoThat blew my mind. I've used fzf a couple time here and there, but now I Get It. Thanks!
- w0m 3y agoThis is a gem; thank you.
- taude 3y agoThis 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....
- shmerl 3y agoI use it neovim with fzf search.