Skip to main content

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
```

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.2.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

prs-0.0.2-py2-none-any.whl (4.7 kB view details)

Uploaded Python 2

File details

Details for the file prs-0.0.2.tar.gz.

File metadata

  • Download URL: prs-0.0.2.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for prs-0.0.2.tar.gz
Algorithm Hash digest
SHA256 094566575dfa33d42edd99d49f04a91b33c80664229d6e1937862d2435e0d883
MD5 22d8017888d97abccfaab64b2a2d9c34
BLAKE2b-256 bb8d6e48656c9a83f9f19b2890e15b1b9d27f92f65510134c1add854cd65441c

See more details on using hashes here.

File details

Details for the file prs-0.0.2-py2-none-any.whl.

File metadata

File hashes

Hashes for prs-0.0.2-py2-none-any.whl
Algorithm Hash digest
SHA256 ca5c8cd87bc685b0a2049f1153f5e798c9b242767f36f569f2476c48d873a2f3
MD5 6f262e104756383b50ac7befe4f15500
BLAKE2b-256 b4e4881e6d6e5c658b33a261d56906ebf9577adc7acb9ccc910ad1b4f989e235

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page