Virtual Python Shell (pvsh, ā€˜pā€™)


The Python Virtual Shell (pvsh or 'p' on the command line) lets you mix zsh / bash / etc. built-in shell scripting with slightly modified Python scripting. It's kind of like Brython for the Linux / Unix / Mac command line.

curl > p && chmod +x p && sudo cp p /usr/local/bin && hash -r

An example

christos@inner-sanctum ~ $ p
Welcome to p (or vpsh), the Python Virtual Shell. Please visit!
Hit '?' for help.

christos @ - Mon Sep  4 09:01:29 2023
p>      for x in range(3):
->              print('Python: ' + str(x))
-> echo Shell: %(x)d
Python: 0
Shell: 0
Python: 1
Shell: 1
Python: 2
Shell: 2

christos @ - Mon Sep  4 09:02:09 2023

The core concept is that all Python code is indented with tabs, with an extra tab at the beginning to mark Python code, and all shell commands (including some shell builtins) have zero tabs of indentation. They can be mixed line-by-line offering an opportunity to use built-in zsh, bash, etc. scripting or Python scripting as desired. The Python is an incomplete implementation; it doesn't support breaking a line into multiple lines. Nonetheless, this offers a tool to fuse shell- and Python-based interactions from the Linux / Unix / Mac command line.

Try it!