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.

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

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

02:28:39 $ ls -1 | prs "o = 'touch ' + ' '.join(i)"
touch LICENSE prs README.md setup.cfg setup.py

Completely ignore all input:

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

Uploaded Source

Built Distribution

prs-0.0.4-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for prs-0.0.4.tar.gz
Algorithm Hash digest
SHA256 7bf76619c8348d4f917915af8c1eab87bdf3e0e303d65532a551f95ccb20d7b5
MD5 cca926f615dbb4365d43a7d26321bd12
BLAKE2b-256 ba0e545834524e3dc003fc487dd7f72b7325f60c641b8d81da1f3c00c0e0ee89

See more details on using hashes here.

File details

Details for the file prs-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for prs-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 76533cce9e6e03b94620121d67ac366174d9580467a0ea1fb2749ac9a856c7e1
MD5 e0be4c055963089eafc876c80d503a2f
BLAKE2b-256 254a2b0376edbe0c32181eff2c3b37759fa361d5c8e74161e43d5c8a859dbab1

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