Skip to content

Instantly share code, notes, and snippets.

@polyrand
Last active July 19, 2021 18:47
Show Gist options
  • Save polyrand/d59c42a0884992dd8e60a3a03045f8a4 to your computer and use it in GitHub Desktop.
Save polyrand/d59c42a0884992dd8e60a3a03045f8a4 to your computer and use it in GitHub Desktop.
ripgrep jupyter notebooks

Save nbread somewhere in your $PATH and give it permissions with chmod +x nbread

Add the following alias to your shell:

alias rgnb="rg --pre nbread --pre-glob '*.ipynb' --type-add 'ipynb:*.ipynb' -tipynb"

Now you can run rgnb sqlite to search for "sqlite" in all your *.ipynb files.

#!/usr/bin/env python3
import json
import sys
if __name__ == "__main__":
data = json.loads(sys.stdin.read())
filtered = [x for x in data["cells"] if x["cell_type"] == "code"]
filtered = ["".join(x["source"]) + "\n" for x in filtered]
print("\n".join(filtered))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment