Jinja2 Extension for running shell commands.
CC0-1.0 License
Jinja2 Extension for running shell commands. Makes use of subprocess.run(shell=False)
.
Install this via pip (or your favourite package manager):
pip install jinja2-shell
The extension class is jinja2_shell.ShellExtension
.
If the second argument is True
(default), the output is stripped of trailing whitespace and newlines. (a\n\b \n
-> a\nb
)
As a statement:
{% shell "echo Hello World" %}
{% shell "echo Hello World", False %}
{% shell "echo 'Hello World', False %}
{% shell "echo \"Hello World\"", False %}
Hello World
Hello World (Ubuntu), Hello World\n (Windows)
Hello World (Ubuntu), Hello World\n (Windows)
Hello World (Ubuntu), Hello World\n (Windows)
As a expression:
{{ "echo Hello World" | shell }}
{{ "echo Hello World" | shell(False) }}
{{ "echo 'Hello World'" | shell(False) }}
{{ "echo \"Hello World\"" | shell(False) }
Hello World
Hello World (Ubuntu), Hello World\n (Windows)
Hello World (Ubuntu), Hello World\n (Windows)
Hello World (Ubuntu), Hello World\n (Windows)
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!