Skip to content

Instantly share code, notes, and snippets.

@robinknowles
Created November 17, 2023 14:26
Show Gist options
  • Save robinknowles/ab5e5b0c841cc7ce7c805eb39cac90bc to your computer and use it in GitHub Desktop.
Save robinknowles/ab5e5b0c841cc7ce7c805eb39cac90bc to your computer and use it in GitHub Desktop.
Using fzf to fuzzy-find OpenFOAM features

Fuzzy finding 'FOAM features

Accompanies OnCFD Newsletter #173

A couple of code snippets that use fzf to mine your install & extract the answers to everyday OpenFOAM questions, like...

  • How do I use a particular feature?
  • What does so-and-so dictionary look like?
  • Does this need a semi-colon? πŸ€¦β€β™‚οΈ

It looks like this...

oncfd-173-fzf-OpenFOAM

Here are the code snippets...

fzf + grep + less version

grep \
--line-buffered --line-number --color=never \
--recursive --binary-files=without-match '' $FOAM_TUTORIALS |
fzf \
--delimiter : \
--preview 'less {1}' \
--preview-window 'up,75%,border,+{2}/3'

fzf + ripgrep + bat version

rg \
--color=always --line-number --no-heading \
--smart-case '' $FOAM_TUTORIALS |
fzf --ansi \
--color 'hl:-1:underline,hl+:-1:underline:reverse' \
--delimiter : \
--preview 'bat -lcpp --color=always {1} --highlight-line {2}' \
--preview-window 'up,75%,border,+{2}+3/3,~3'

That should save you some typing, but make sure you check out the original article for more info πŸ‘‹

@robinknowles
Copy link
Author

Hi @otaolafranc - I'm glad you're getting some use out of it.

Unfortunately, when I try your command on my machine I get the expected behaviour i.e. it pulls up a bunch of phaseProperties files in twoPhaseEulerFoam etc πŸ€”

That's with rg = 14.1.0 , fzf = 0.44.1 & bat = 0.24.0 in an Ubuntu Docker container.

Not sure if it's a version thing or an operating system thing.

fzf has options to tweak how it matches, but they aren't something I've played with.

Hope you can get it working how you need 🀞

@otaolafranc
Copy link

I have the 'good' matches but also when i go up even more on the list i beging getting some matches such as the one showed there...
for the corresponding versions I am rg=14.1.0 fzf=0.57.0 and bat=0.24.0. strange... will have a look at the link, but as it is a pipe of so many things I am a little bit lost lol.
thanks in any case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment