Skip to content

Instantly share code, notes, and snippets.

@robinknowles
Created November 17, 2023 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 👋

@cloner0110
Copy link

It's not working, at least for me, on macOS.

@robinknowles
Copy link
Author

I'll check 'em out again on my Mac - any error messages?

@cloner0110
Copy link

Thanks for response, I just alias this :

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'

to something, for example command, then when i execute command, I see lots of permission denied messages, you can see some in the following image.
Screenshot 2024-01-17 at 00 08 29

@robinknowles
Copy link
Author

rg seems to be looking in some odd places - perhaps you don't have the $FOAM_TUTORIALS environment variable set

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