Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

Awesome Lists containing this project

README

        

# jinja2-shell



CI Status


Documentation Status


Test coverage percentage




Poetry


black


pre-commit




PyPI Version

Supported Python versions
License

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)):



34j
34j

💻 🤔 📖

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!