A command line tool written in Python to find files and file contents matching (Python) regex patterns.
Print the usage help:
filesearch
Find all files ending with .py
:
filesearch ".*.py\b"
Find all files ending with .py
but exclude files in the folder .git
:
filesearch ".*.py\b" ".git"
In all files ending with .py
but excluding files in the folder .git
, find lines containing def
:
filesearch ".*.py\b" ".git" "def"
In the previous example, also print the 3 lines before and after the matching line
filesearch ".*.py\b" ".git" "def" 3
If you want to be able to run filesearch
from anywhere in the terminal, you can use the following two commands.
First, create a source distribution with
python setup.py sdist
Second, use pipx to install and be able to run the application in an isolated environment:
python -m pipx install .
This requires pipx
to be installed (e.g., via python -m pip install pipx
).
If you only want to use main.py, no packages need to be installed. Navigate to filesearch/ and use
python main.py --help
to get instructions on how to use the tool.