Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Python Linux

Experimental Project Attempts a Python Virtual Shell for Linux (cjshayward.com) 62

Long-time Slashdot reader CJSHayward shares "an attempt at Python virtual shell."

The home-brewed project "mixes your native shell with Python with the goal of letting you use your regular shell but also use Python as effectively a shell scripting language, as an alternative to your shell's built-in scripting language... I invite you to explore and improve it!"

From the web site: 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 [a Python implementation for client-side web programming], but for the Linux / Unix / Mac command line...

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.

This discussion has been archived. No new comments can be posted.

Experimental Project Attempts a Python Virtual Shell for Linux

Comments Filter:
  • Just wait for the exploits with this gee-wiz shell.
  • HORRIFYING (Score:5, Insightful)

    by Xardion ( 215668 ) on Sunday October 29, 2023 @12:45PM (#63963690)

    Security issues aside... who thought this was a good idea? Using whitespace to denote an entirely different language mixed in the shell script? What if someone sets their tab stops to 2 or 4 spaces and it becomes indistinguishable from their regular spacing? Even if they don't, it can get very ambiguous.

    • by znrt ( 2424692 )

      What if someone sets their tab stops to 2 or 4 spaces

      now we know why the youngster geeks have banned tabs and demand spaces all the way down.

      it was a conspiracy all along, to poison our shells!

    • by jma05 ( 897351 )

      Why is this a hypothetical?
      Python has been around since 1991, and is currently the most popular language. It has been widely used for Linux scripting.
      People are doing just fine with indentation as syntax for decades.
      Anyone scripting has enough sophistication to show tabs in their editor.

  • by PPH ( 736903 ) on Sunday October 29, 2023 @12:45PM (#63963692)

    ... from the 'python -c command' invocation? Put I/O in pipes and string python, shell builtins and other utilities together and you're good to go.

    • by ArchieBunker ( 132337 ) on Sunday October 29, 2023 @01:44PM (#63963780)

      They didn't invent it, therefore it is bad. Much like ifconfig vs ip, traceroute vs tracepath, nslookup vs host, etc etc.

      • They didn't invent it, therefore it is bad. Much like ifconfig vs ip, traceroute vs tracepath, nslookup vs host, etc etc.

        By that logic all underwear and other clothing should be the same color everywhere. Or, you only need ONE highway/street not multiple between LA and LB.

        Having some diversity, some choice is a good thing, even if it is redundant.

        Even /. has redundant 'ArchieBunker' types - but they go by different names. /sarcasm

        • Stupid analogy. The whole point of fashion and other consumer items is personal choice. The point of utilities is functionality, consistency and familiarity. You dont need a piss poor 2nd option when the first already does the job fine.

          • Stupid analogy. The whole point of fashion and other consumer items is personal choice. The point of utilities is functionality, consistency and familiarity. You dont need a piss poor 2nd option when the first already does the job fine.

            Actually many seemingly redundant commands/applications exist solely because the developers of the initial design either missed something or created an "interface from he11" design.

            As my exemplar I submit the Linux commands "ifconfig" and "ip". Both commands ostensibly do the same thing: configure network interfaces and display information about those interfaces.

            If I want data for network interface 'eno3' I easily can type "ifconfig eno3" at the command-line and it displays instantly. If I want to use the "

          • The whole point of fashion and other consumer items is personal choice. The point of utilities is functionality, consistency and familiarity. You don't need a piss poor 2nd option when the first already does the job fine.

            You're talking about Linux software, as if UX research, market testing and well engineered designs are the norm and the users don't all pick tools based on how they feel and the tools aren't developed that same way. That's hilarious, I mean what-if, right?

  • Oh noes - not tabs, spaces. This will only start another flame war
  • This is a totally expected outcome.

  • by Arnonyrnous Covvard ( 7286638 ) on Sunday October 29, 2023 @01:50PM (#63963802)

    Indentation for syntactic structure is the fundamental flaw of Python, and now they want that in an environment that respects whitespace so little that some very frequently used commands resort to offering the zero byte as delimiter instead of whitespace. It's an environment where the one-liner is a common concept, because multi-line shell commands are brittle. These people are nuts.

    • by jabuzz ( 182671 )

      I would go with the lack of support for arrays as being the fundamental flaw of Python.

  • by Misagon ( 1135 ) on Sunday October 29, 2023 @02:07PM (#63963836)

    A few previous shells based on Python:

    Apparently, Tako is a fork of Xonsh, but apart from that each has a different approach to embed Python in a shell. In pysh, commands become functions; in Marcel, Python is in parentheses, and in Xonsh, everything that is not valid python is interpreted as a command.

    IMHO, I think that shells and Python have too different syntax, that it would be better to define a single syntax model and stick to it for everything instead of mixing. A shell is too powerful and crude: if you want to improve a shell, you should make it safer, not more ambiguous.
    (Not that any of these don't have any good ideas, because they do.)

    For an example of horror, see this Xonsh:

    >>> ls = 44
    >>> l = 2
    >>> ls -l
    42
    >>> del ls
    >>> ls -l
    total 0

  • by 4wdloop ( 1031398 ) on Sunday October 29, 2023 @02:34PM (#63963874)

    All python is marked with a TAB at the line beginning, eh?
    I suppose that only work on the prompts - so no hope of mixing sh and py in the scripts then (or forget the TABs)?

    I also do not see integration - at the best it's a lame coexistence in isolation?

    • by kmoser ( 1469707 )
      I can foresee a situation where a developer spends an hour trying to debug such a script, only to realize that one of the Python lines starts with a space, not a tab.
  • 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.

    This is a neato trick for people who haven't heard of the here document [wikipedia.org] but for the rest of us it's a bit underwhelming. Using that strategy doesn't require that you begin each line with a tab, either. What they've done is provide something inferior to the option you have already.

    • by gweihir ( 88907 )

      It is surprising how many people think they can improve systems have not even understood the basics and have never heard of basic features. Must be some variant of the Dunning-Kruger effect at work.

  • Pythonistas can turn nasty really quickly.

    Come on, this is the essence of the old Slashdot - someone trying out an idea just because they could. Getting some disparaging comments is understandable... but it's disappointing to see pretty much every one of them be that way.

    • Oh I assure you its not the pythonistas. Most python users got bored of the "tabs vs spaces" argument and the far dafter "significant whitespace bad!" argument 20 years ago.

      That said, as a python user, while this is an interesting conept, the implementation is poorly. One would expect a good python shell implementation to use an abstract syntax tree approach, because its both the standard for language implementation and extremely performant and flexible.

      Unfortunately this seems to be just a big nested loop

      • But as an experiment, sure, its interesting to look at, but dont expect it to yield much of reliable use.

        To be fair, that can be said about many of the entries in this family of posts to Slashdot.

  • ipython has shell and Python syntax.
  • Yeah I really want a shell thats going to perform so badly it's like im using a terminal over a 300baud modem.
  • Did they wait with suggesting to clone powershell until some patent of MS ran out?

Real programmers don't comment their code. It was hard to write, it should be hard to understand.

Working...