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.
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.
If you though Shellshock/Bashdoor was bad (Score:2)
Re: (Score:2)
I was going to post "no, thank you" and you give another good reason why.
Re:If you though Shellshock/Bashdoor was bad (Score:5, Funny)
pip install what_can_possibly_go_wrong
HORRIFYING (Score:5, Insightful)
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.
Re: (Score:3)
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!
Re: (Score:2)
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.
How does this differ ... (Score:3)
Re:How does this differ ... (Score:4, Insightful)
They didn't invent it, therefore it is bad. Much like ifconfig vs ip, traceroute vs tracepath, nslookup vs host, etc etc.
Re: (Score:2)
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
Re: How does this differ ... (Score:3)
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.
Re: (Score:3)
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 "
Re: How does this differ ... (Score:2)
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?
schism (Score:2)
Re:schism (Score:5, Insightful)
Flame war for what? Who would use tabs?
Re: (Score:2)
vi l0zers who can't handle emacs, obviously.
For a language I would call bash++ (Score:1)
This is a totally expected outcome.
Re: (Score:2)
sorry, no suggestions here, just curiosity: bc is specifically designed for "arithmetic at the prompt" so ... why not bc? what else do you need?
Re: (Score:2)
laziness and impatience is what you have mindfulness, zen, tiktok, drugs and lots of other crazy shit for. when it comes to sw design there is only one commandment: "give it one function and one function only, then release it and let it interoperate for the greater glory of zero!"
Re:Was excited... (Score:4, Informative)
Why not just implement a shell function that will feed the command line arguments as an expression to a python invocation? Add it to the init script for whatever shell you are using.
doit() {
python -c "print($*)"
}
Then:
% doit 99.3/7
14.185714285714285
Re: (Score:2)
Here is mine. I don't pretend to know it's secure, but it's resilient against accidentally pasting in some undesirable function calls, plus you can use keywords in the math module.
math () {
python3 -c 'import sys; import re; import math;
allowed = ["log","ln","sqrt","sin","cos","tan","asin","acos","atan","radians","degrees","atan2","pi"]
def filter(match):
return "math."+match.group() if match.group() in allowed else ""
print(eval(re.sub(r"[{};`a-zA-Z_]+"
Re: (Score:2)
zsh has floating point math. If you must be able to do floating point from your shell without an external program, it's probably your answer. But why not use bc? It does the job.
Re: (Score:2)
These people are demented (Score:4, Insightful)
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.
Re: (Score:2)
Eh, there's elitism and then there's practicality. I'm always going to fall back on the better tool for the job, and typically that will be the one less tedious.
Re: (Score:2)
Sure. But if you code with any reasonable level of skill, you _already_ have the indentation in place that Python requires or something very close to it. So where exactly does "tedious" come in?
Re: (Score:2)
Implementing that shit in a shell. Using VIM to write Python with auto indentation is trivial, but if I'm doing that I don't need a special shell.
Re: (Score:2)
I agree. I think Python is mostly unsuitable for that type of scripting anyways.
Re: (Score:2)
I would go with the lack of support for arrays as being the fundamental flaw of Python.
Previous Python Shells: (Score:5, Informative)
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:
Re: (Score:1)
It continues to amaze me that people that think they are smart cannot deal with a minor detail like indentation as syntax-relevant. Seriously, how dysfunctional and inflexible can you get? This is not a problem. This is not even a major characteristic of the language.
Re: There's a pattern I've noticed in life (Score:2)
If you dont understand why non visible characters should not be synthetically relevant then you're clearly too clueless to bother explaining it to.
Re: There's a pattern I've noticed in life (Score:2)
That should read syntactically. Fucking auto correct.
Re: (Score:1)
Hahah, you wish. And since when has whitespace followed by characters on the same line been "non visible"? Empty lines _are_ syntactically irrelevant in Python. Indentation only applies to non-empty lines.
Well, if that is your level of insight, I can understand that very minor details scare you to death...
Re: (Score:2)
". And since when has whitespace followed by characters on the same line been "non visible"?"
So you can tell the difference between spaces and a tab and count how many tabs there are without checking your editros tabstop settings without looking can you?
Moron.
Do you have an AED handy? (Score:2)
1) No tab characters allowed in the source code file. (They are indeed evil invisible shape-shifters).
but then, with no problems:
2) Mandatory indentation (3 spaces exactly) as code scoping.
Re: There's a pattern I've noticed in life (Score:2)
If it amazes you how a seemingly minor thing like the distinction between different kinds of whitespace, or the allocation of meaning to whitespace in general, can introduce all sorts of added costs in terms of workflow complexity, the introduction of subtle bugs, and the increased difficulty in debugging or adding functionality to complex codebases where the whole code doesn't fit on one screen, then you obviously haven't encountered real software in the real world. I would guess you're pretty good at writ
Re: (Score:1)
Soooo, you advocate doing large software projects without a strict policy on tabs? Seriously? That is just dysfunctional.
That said, have you any references for large Python projects that are in trouble because of the indentation? Anything at all? Because there are certainly lots of large Python projects, but whitespace seems to be a complete non-issue.
BTW, your attempts to talk down to me accomplish nothing because you are so far off the mark that they are just hilarious to me.
Re: There's a pattern I've noticed in life (Score:2, Troll)
The usual answer I get to my question is "refactor so that every class or function *does* fit in one screen; this enforces good readability!"
And the reason I don't bother engaging is because I've seen the same answer misapplied in another language where the language (lack of) features forces the same strategy of breaking everything into tiny subclasses which all fit on one screen: Java.
And when you take this "solution" in java, you pay two penalties: the one up-front is that you end up writing a shit ton of
The end of TABs in scrips, ha! (Score:3)
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?
Re: (Score:2)
You can already inline python in shells (Score:3)
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.
Re: (Score:3)
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.
One thing the comments so far have taught me... (Score:3)
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.
Re: (Score:2)
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
Re: (Score:2)
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.
How is this different than ipython? (Score:1)
Who asked for this? (Score:1)
We should call it powerpython (Score:2)
Did they wait with suggesting to clone powershell until some patent of MS ran out?