prs is a utility that allows you to use Python list comprehensions in shell commands.
Project description
prs
===
prs is a small utility that lets you pipe things to Python and process them in a list comprehension.
If you've ever wished you could manipulate items in your shell with a Python list comprehension, prs is for you.
Installation
------------
Just `pip install prs`.
Usage
-----
prs is simple. You pipe stuff into it from the shell, it exposes whatever is piped as a list called `i` (without final
newlines) to a script, and expects the script to return either a string or an iterable to a variable called `o`. That
variable is then printed to stdout, so you can pipe it to `sh` for execution.
```bash
$ ls -1
LICENSE
prs/
README.md
setup.cfg
setup.py
$ ls -1 | prs "o = [l.lower() for l in i]"
license
prs
readme.md
setup.cfg
setup.py
```
Multiple lines can be separated by a semicolon.
Various libraries are already imported (but feel free to import your own):
* os
* sys
* pathlib.Path
Examples
--------
Append `.bak` to all files in the current directory:
```bash
$ ls -1 | prs "o = ['mv {} {}.bak'.format(l, l) for l in i if Path(l).is_file()]"
mv LICENSE LICENSE.bak
mv README.md README.md.bak
mv setup.cfg setup.cfg.bak
mv setup.py setup.py.bak
```
Concatenate all entries into one:
```bash
02:28:39 $ ls -1 | prs "o = 'touch ' + ' '.join(i)"
touch LICENSE prs README.md setup.cfg setup.py
```
Completely ignore all input:
```bash
02:29:35 $ ls -1 | prs "o = 'hi'"
hi
```
===
prs is a small utility that lets you pipe things to Python and process them in a list comprehension.
If you've ever wished you could manipulate items in your shell with a Python list comprehension, prs is for you.
Installation
------------
Just `pip install prs`.
Usage
-----
prs is simple. You pipe stuff into it from the shell, it exposes whatever is piped as a list called `i` (without final
newlines) to a script, and expects the script to return either a string or an iterable to a variable called `o`. That
variable is then printed to stdout, so you can pipe it to `sh` for execution.
```bash
$ ls -1
LICENSE
prs/
README.md
setup.cfg
setup.py
$ ls -1 | prs "o = [l.lower() for l in i]"
license
prs
readme.md
setup.cfg
setup.py
```
Multiple lines can be separated by a semicolon.
Various libraries are already imported (but feel free to import your own):
* os
* sys
* pathlib.Path
Examples
--------
Append `.bak` to all files in the current directory:
```bash
$ ls -1 | prs "o = ['mv {} {}.bak'.format(l, l) for l in i if Path(l).is_file()]"
mv LICENSE LICENSE.bak
mv README.md README.md.bak
mv setup.cfg setup.cfg.bak
mv setup.py setup.py.bak
```
Concatenate all entries into one:
```bash
02:28:39 $ ls -1 | prs "o = 'touch ' + ' '.join(i)"
touch LICENSE prs README.md setup.cfg setup.py
```
Completely ignore all input:
```bash
02:29:35 $ ls -1 | prs "o = 'hi'"
hi
```
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
prs-0.0.1.tar.gz
(2.6 kB
view details)
Built Distribution
prs-0.0.1-py2-none-any.whl
(4.7 kB
view details)
File details
Details for the file prs-0.0.1.tar.gz
.
File metadata
- Download URL: prs-0.0.1.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e4b0c01c446ea2e994bd8f31c428d64235bc7de8aa86922b0ca6eb4d1589cc3 |
|
MD5 | 8197574048fe0b96e91a69dcd55ca72a |
|
BLAKE2b-256 | f619fe4215f5289ffd591c9562dd15515db1afcee9026abc2c5a0a338ac463f7 |
File details
Details for the file prs-0.0.1-py2-none-any.whl
.
File metadata
- Download URL: prs-0.0.1-py2-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78e3ec9852df8e74e046db55717b028b990e0266695eb565e2a4f83c6601cb4a |
|
MD5 | 2f071abc38c7fb6f79c14890cc51362c |
|
BLAKE2b-256 | 9829878a8aec081e7ea779a036d8950c2e5dce77b86756d88bc8f6817d3487b8 |