Skip to content

Instantly share code, notes, and snippets.

@abzrg
Last active February 17, 2025 18:28
Show Gist options
  • Save abzrg/358e4718b842500577351609d0fcaf5c to your computer and use it in GitHub Desktop.
Save abzrg/358e4718b842500577351609d0fcaf5c to your computer and use it in GitHub Desktop.
Look up anything in OpenFOAM tutorials
#!/bin/sh -e
# This is the modified version of gtfo from https://www.cfdengine.com/newsletter/173/
main() {
argparse "$@"
if [ -z "$WM_PROJECT_DIR" ]
then
die "OpenFOAM environment is not loaded."
fi
if [ -n "$filename" ]; then
find_nameOpt="-iname"
fi
find $FOAM_TUTORIALS $find_nameOpt "$filename" -type f \
-not \( \
-path "*polyMesh*" -prune \
-o -path '*triSurface*' -prune \
-o -path '*geometry*' -prune \
-o -path "*dataset*" -prune \
-o -path '*validation*' -prune \
-o -path "*All*" \
-o -path '*.sh' \
-o -path "*.py" \
-o -path '*README*' \
-o -path '*.m4*' \
-o -path "*plot*" \
-o -path "*list-worlds*" \
-o -path "*.schema" \
-o -path "*.csv" \
-o -path '*otape17*' \
-o -path "*Test*" \
\) \
-exec grep \
--ignore-case \
--recursive \
--line-buffered \
--binary-files=without-match \
--line-number \
"$query" "{}" + 2>/dev/null \
| fzf --ansi --delimiter ':' --nth=3 --preview ' \
test -n {} && zless {1} \
| nl -ba \
| perl -pe "s/"{2}"/>/g if "{2}" .. "{2}' \
--preview-window 'up:70%:+{2}-/3'
}
usage() {
echo "Usage: gtfo [-f,--filename filename] [-q,--query query] [-h,--help] [filename] [query]"
}
die() {
echo "$1"
exit 1
}
argparse() {
# Parse -* args first
for arg in "$@"
do
shift
case "$arg" in
-q|--query)
query="$1"
continue
;;
-f|--filename)
filename="$1"
continue
;;
-h|--help)
usage
die 1
;;
-*)
usage
die "Error: Uknown option '$arg'."
;;
esac
set -- "$@" "$arg"
done
# Then parse non -* args
test -z "$filename" && filename="$1"
test -z "$query" && query="$2"
}
main "$@"

GTFO

Look up anything in OpenFOAM tutorials:

# 1
gtfo

# 2
gtfo topoSetDict
gtfo toposetdict

# 3
gtfo topoSetDict 'ToFace;'

# 4
gtfo -f topoSetDict -q 'ToFace;'
gtfo --filename topoSetDict --query 'ToFace;'

To install, download the script and place it somewhere in PATH.

curl -O <link>

# e.g., copy in one of the following places
cp gtfo ~/.local/bin/
cp gtfo ~/bin/
sudo cp gtfo /usr/local/bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment