Skip to content

Shell in Python

Existing Python libraries

Python-based shells

  • https://github.com/geophile/marcelMarcel is a shell. The main idea is to rely on piping as the primary means of composition, as with any Unix or Linux shell. However, instead of passing strings from one command to the next, marcel passes Python values: builtin types such as lists, tuples, strings, and numbers; but also objects representing files and processes.”
  • https://xon.sh/ “Xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt. The language is a superset of Python 3.6+ with additional shell primitives that you are used to from Bash and IPython. It works on all major systems including Linux, OSX, and Windows. Xonsh is meant for the daily use of experts and novices.”

Docs / blogs posts

Shell -> Python converter / compiler

See also:

Type-safe shell scripting

Misc

References

Misc ideas for a new API

Goals:

  • Ease / naturalness of use
  • Type safety

Shell object: shell = Shell()

Run something: result = shell.ls()

With options: result = shell.ls(l=True) (== ls -l).

Errors recovery:

try:
    result = shell.ls()
except ShellException as e:
    print(e.status)

Strong typing: generate .pyi files for common commands ? By parsing man pages ?

Piping: shell.ls().pipe.grep('*.py') ? bof.

shell.pipe(shell.ls(), shell.grep('*.py') ? (Needs to parse AST inside the pip argument).

Page last modified: 2024-01-18 12:48:15