A small utility to create and run directory-specific macros.
lm <macro-name> <args...>lm looks for and runs executable scripts in the .local-macro directory, as well as .local-marco directories in parent directories.
Configuration is done via environment variables.
| Env var | Description | Default |
|---|---|---|
| LM_DIR_NAME | The name of the directory containing the macro scripts | .local-macro |
Assume we have a project with the following directory structure:
- project/
- frontend/
- .local-macro/
- run
- ...
- backend/
- .local-macro/
- run
- ...
- .local-macro/
- sync-schemas
- ...with a node frontend
$ cat frontend/.local-macro/run
#!/bin/zsh
npm run devand a python backend
$ cat backend/.local-macro/run
#!/bin/zsh
python manage.py runserverand a set of shared schemas that need to be synced between them
$ cat .local-macro/sync-schemas
#!/bin/zsh
cp frontend/schemas/schema.json backend/schemas/schema.jsonRunning the frontend and backend and syncing the schemas are all commands which need to be run often, but are only relevant to this project. lm makes it easy to define these macros only where they're relevant.
$ cd project/frontend
$ lm run # calls project/frontend/.local-macro/run$ cd project/backend
$ lm run # calls project/backend/.local-macro/run$ cd project/backend
$ lm sync-schemas # calls project/.local-macro/sync-schemasMacros are simple scripts that are called with the arguments passed to lm. They can be written in any language, as long as they are executable. lm will pass along all arguments after the macro name to the script.
Additionally, lm will pass several environment variables to the script:
| Env var | Description |
|---|---|
| LM_CALL_DIR | The path to the directory from which lm was called |
| LM_MACRO_DIR | The path to the parent of the resolved script's .local-macro directory |
| LM_MACRO | The name of the macro |
These can be used to customize the behavior of the macro.