Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/34j/jinja2-shell
Jinja2 Extension for running shell commands.
https://github.com/34j/jinja2-shell
hacktoberfest jinja2 jinja2-extension python subprocess
Last synced: about 2 months ago
JSON representation
Jinja2 Extension for running shell commands.
- Host: GitHub
- URL: https://github.com/34j/jinja2-shell
- Owner: 34j
- License: cc0-1.0
- Created: 2023-02-21T05:32:15.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-23T17:25:35.000Z (2 months ago)
- Last Synced: 2024-10-25T05:32:50.033Z (about 2 months ago)
- Topics: hacktoberfest, jinja2, jinja2-extension, python, subprocess
- Language: Python
- Homepage:
- Size: 128 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# jinja2-shell
Jinja2 Extension for running shell commands. Makes use of `subprocess.run(shell=False)`.
## Installation
Install this via pip (or your favourite package manager):
```shell
pip install jinja2-shell
```## Usage
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:
```jinja2
{% shell "echo Hello World" %}
{% shell "echo Hello World", False %}
{% shell "echo 'Hello World', False %}
{% shell "echo \"Hello World\"", False %}
``````text
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:
```jinja2
{{ "echo Hello World" | shell }}
{{ "echo Hello World" | shell(False) }}
{{ "echo 'Hello World'" | shell(False) }}
{{ "echo \"Hello World\"" | shell(False) }
``````text
Hello World
Hello World (Ubuntu), Hello World\n (Windows)
Hello World (Ubuntu), Hello World\n (Windows)
Hello World (Ubuntu), Hello World\n (Windows)
```## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!