The premise on which this CLI is based is that python's
from pathlib import Path
Path("my/path/to/dir").rglob("**/*.ext")Is very practical, but that it is even more so when you pair it with the usual string transformations python is good at.
You have a set of commands whose aim is just to glob, that is to provide a list of items.
The most "natural" (i.e.) close to original is rglob r, with the caveat that you have to subsitute
the symbol # for * so that a glob of **/*.json becomes rglob r ##/#.json.
The others are quite straightforward:
- The command
rglob lis the equivalent ofrglob('*') - The command
rglob lsis the full power ofrglob('**/*')
with extra filtering as an option in both cases, using the flag --filter or -f
What is intersting about python is to perform batch operations on your strings.
That is what rglob tf is here for. It gets piped into and modifies each line of the input.
For example:
rglob ls | rglob tf split "-"Will return a square array of elements, where each line is split into subcomponents along the character -
You can join the resulting stream:
rglob ls | rglob tf split "-" | rglob tf join "_" | rglob tf join "^"You can chain the commands up until the point you would like to evaluate the result.
This is where the rglob eval command comes in. It will evaluate the stream for each line and return the result.
This supposes you have transformed the stream into a list of shell compatible commands.
For example:
rglob r #.py | rglob tf replace ".py" ".csv" | rglob tf fmt "echo '{}' >> toto" | rglob tf evalThis will create a file toto with the list of all the .py files in the current directory and subdirectories,
with the extension .csv instead of .py. You could replace echo with touch to create empty files. Or even with a call to a script you have in your path. It's up to you.
We can also use python expressions to evaluate the stream. This is fairly risky, but can be useful.
For example:
rglob r #.py | rglob tf map "lambda x: x.upper()"You can find the rest of the documentation by following this link