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
  • re
  • sys
  • pathlib.Path

Examples

Note: The examples here won't actually run the commands, they will just display them so you can see what will actually run. To run the commands for real, just append | sh to each example.

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

Change the extension of all files in all subdirectories:

$ prs 'o = ["mv %s %s" % (l, l.with_suffix(".2py")) for l in Path(".").glob("**/*.py")]'
mv setup.py setup.2py
mv build/lib/prs/cli.py build/lib/prs/cli.2py
mv build/lib/prs/__init__.py build/lib/prs/__init__.2py
mv prs/cli.py prs/cli.2py
mv prs/__init__.py prs/__init__.2py

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

Uploaded Source

Built Distribution

prs-0.0.7-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: prs-0.0.7.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.9.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.6

File hashes

Hashes for prs-0.0.7.tar.gz
Algorithm Hash digest
SHA256 93533805a87cb545b478148530513ed428f7e7402b90b4bf7f1f86ef50ceb795
MD5 04a6432db6f34c433b17c336d77af91c
BLAKE2b-256 9f4bc66421e6b8f9bf4762800e6a32a1def7661cd388b34797d4528d15b9d2a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: prs-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.9.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.6

File hashes

Hashes for prs-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1e723f8b40ca4e241c86b483cb8588b4de888afe5dc8a1a0e789f7043447db6b
MD5 980702b4dde5c16c65df2d80beb5c24d
BLAKE2b-256 be266c556b1723cb985ebb44498c16c8b427604a41c76ddf16b11714903ef142

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