News for hackers. Stuff that matters.
Re:The Xonsh Python Shell by emptybits on Monday October 12, 2020 @03:32PM (#24758469)
Some of the docs suggest "xonsh" is pronounced "conch". i.e. a shell that's a shell. Snailed it. :-P

Ref: See "TAGLINES" def in https://xon.sh/_modules/xonsh/xonfig.html

Re:The Xonsh Python Shell by chrisweekly on Monday October 12, 2020 @06:40PM (#24760280)
It's pronounced "Konsh". Origin story - name relates to conch ("konk") shells.

Source: my 1st cousin, one of its co-creators and core maintainers.

Re:The Xonsh Python Shell by gridlockd on Monday October 12, 2020 @03:35PM (#24758511)
Okay, but I read it as "zonsh", or maybe "Exxon Shell".
Re:The Xonsh Python Shell by pmiller2 on Monday October 12, 2020 @08:59PM (#24761254)
Sounds like it should actually be "χonch," then, with a Greek letter chi instead of an 'x'.
Re:The Xonsh Python Shell by kwk1 on Tuesday October 13, 2020 @12:26AM (#24762259)
This pattern is also present in e.g. LaTeX
Re:The Xonsh Python Shell by samatman on Tuesday October 13, 2020 @02:16AM (#24762781)
TeX being from τέχνη make sense, I do enjoy startling people by pronouncing it thus (as Knuth recommends).

xonsh being pronounced /kɑnʃ/ and not /eks.ɑnʃ/ or /xɑnʃ/, or even /zɑnʃ/, is just one of those things I have to remember.

pronouncing TeX /tɛk/ is better than /tɛks/, but really it's /tɛx/, the way Bach is /bax/.

Re:The Xonsh Python Shell by scopatz on Monday October 12, 2020 @06:43PM (#24760324)
More taglines are always welcome!
Re:The Xonsh Python Shell by antongribok on Monday October 12, 2020 @07:31PM (#24760713)
I just want to say thank you for Xonsh!

I've been using it as my default shell for the past 2 years, and now I pretty much can't work without it.

Thank you, thank you, thank you!

Re:The Xonsh Python Shell by rwcarlsen on Monday October 12, 2020 @09:55PM (#24761522)
Haven't seen you in meat space for a few years - good to see you're still alive and well in cyberspace!
Re:The Xonsh Python Shell by traverseda on Monday October 12, 2020 @03:40PM (#24758577)
Put this in my `~./xonshrc` a while ago

    from pathlib import Path
    from xonsh.events import events
    class CwdPath(type(Path())):
        def __iter__(self):
            return self.iterdir()

    $cwd = CwdPath.cwd()

    @events.on_chdir
    def set_cwd(olddir, newdir, **kw):
        $cwd = CwdPath(newdir)
It's really nice being to do

    for f in $cwd:
        echo @(f.name)
or equivalent, especially with python's glob syntax

    for f in $cwd.glob("**/*.png"):
        #Do a thing
Overall I've been really enjoying xonsh, now that I've got the hand of it.
Re:The Xonsh Python Shell by mrweasel on Monday October 12, 2020 @04:18PM (#24758993)
I had been wondering about using Python as my shell, but always rejected it, because regular shell operations would be to complicated, compared to the relative fewer times having Python directly available would be helpful.

Mostly I'm just sticking with bash, not because it's best, but because it's available everywhere. I don't really feel setting up something like Xonsh, zsh or ksh on every server I ssh into, to much work. The time is honestly better invested in getting better at bash, if you spend your day on multiple different systems. It's a little sad actually.

Re:The Xonsh Python Shell by animal_spirits on Monday October 12, 2020 @04:36PM (#24759157)
I originally thought the same, I've tried using Python as my shell because I really love programming in Python, but it never felt smooth. I stopped and since then I've been getting better and better at bash and it is becoming more apparent to me that bash is the best tool for the job of a command line. Being able to glide between programs and pipe output without having a python API just makes things faster.
Re:The Xonsh Python Shell by AcerbicZero on Monday October 12, 2020 @04:30PM (#24759109)
I use this https://github.com/Bash-it/bash-it on my "main" system, because you're right, no one has time to setup their shell every time they ssh into a new server, but it is nice to have a "pretty" bash setup for where most of the work gets done.
Re:The Xonsh Python Shell by geophile on Monday October 12, 2020 @02:54PM (#24758014)
Another pythonic shell: https://marceltheshell.org. Unlike Xonsh, marcel provides a strict separation between shell syntax and Python syntax. Specifically, some shell commands take Python functions as arguments. E.g., in the current directory, find all the .c and .h files, and count lines:

    ls -fr \
    | select (f: f.suffix in ('.c', '.h')) \
    | map (f: f.read().count('\n')) \
    | red +
- List only files (-f) recursively (-r).

- Select those whose suffix is .c or .h.

- Map qualifying files to the count of \n in the file.

- Reduce those counts to a total using +.

The parentheses delimit Python functions (marcel permits omission of "lambda").

Re:The Xonsh Python Shell by galkk on Monday October 12, 2020 @04:05PM (#24758850)
It's a good tone to show an affiliation to the project, when you introduce it.

judging by the nickname and github url it's yours https://github.com/geophile/marcel

Re:The Xonsh Python Shell by geophile on Monday October 12, 2020 @04:17PM (#24758981)
Yes, that’s it. The link is included on the website.
Re:The Xonsh Python Shell by gridlockd on Monday October 12, 2020 @03:37PM (#24758536)
"Marcel has been built and tested on Linux. It seems to mostly work on Mac, except for the ps operator. Haven't tried Windows at all."

That's unfortunate, because as awful as bash may be, a shell that works natively on all three systems would be far more valuable. Python has all that platform abstraction already built-in.

Re:The Xonsh Python Shell by cpascal on Monday October 12, 2020 @04:13PM (#24758938)
You may not be aware, but PowerShell can now be run on Linux, macOS, and Windows.

https://github.com/powershell/powershell

Re:The Xonsh Python Shell by globuous on Monday October 12, 2020 @04:48PM (#24759282)
I've only tried Emacs' eshell on Linux and MacOS, it works great, and I'm sure it works great on Windows as well. Maybe has been the one true shell all this time :)
Re:The Xonsh Python Shell by geophile on Monday October 12, 2020 @03:48PM (#24758671)
So help out!
Re:The Xonsh Python Shell by scopatz on Monday October 12, 2020 @06:42PM (#24760311)
FWIW (as the original author of xonsh), xonsh does have a strict separation of Python and subprocess syntax. Users can always choose to write in fully formal xonsh, it is just that most users choose to use the default convenience mechanisms that xonsh provides.
Re:The Xonsh Python Shell by geophile on Monday October 12, 2020 @08:37PM (#24761149)
Thanks for the clarification. I read an interview with you, and there was some discussion of the difficulties in parsing things like "ls -lR", and whether to interpret that as an ls command with flags, or a subtraction. (If I'm remembering correctly.)

If a xonsh user does want to do strict separation, how does that work? Syntactically, how do you separate shell code from Python code?

Re:The Xonsh Python Shell by MikeTheGreat on Monday October 12, 2020 @04:02PM (#24758817)
Is there a place to find a community of xonsh users?

I'd love to use this on Windows but have been running into issues. I'm like 99% sure it's because of my own dumb (unrelated) config issues, but I still can't use xonsh because of it.

Having people to ask questions of would be awesome!

Re:The Xonsh Python Shell by scopatz on Monday October 12, 2020 @08:17PM (#24761019)
Hi Mike, a lot of us hangout on gitter: https://gitter.im/xonsh/xonsh
Re:The Xonsh Python Shell by MikeTheGreat on Tuesday October 13, 2020 @12:05AM (#24762169)
Awesome! Thanks for the tip!
Re:The Xonsh Python Shell by BeetleB on Tuesday October 13, 2020 @02:09AM (#24762744)
What issues? The latest few versions do have a Windows problem, but only for some users - it still hasn't been root caused.
Re:The Xonsh Python Shell by phillco on Monday October 12, 2020 @04:30PM (#24759112)
I'm curious if there's an equivalent of this for shell scripts, or people use Xonsh itself for this.

Simple bash scripts can easily grow into tangled behemoths and there's not an easy, incremental rewrite step (like JS → TS) that would add a lot of structure. Jumping straight to Python is usually painful because of all the subprocess calls.

It seems that xonsh could bridge that gap, but I'm not sure how many people use it for that purpose, or if people use something else (e.g. Oil shell).

Re:The Xonsh Python Shell by geophile on Monday October 12, 2020 @05:09PM (#24759469)
Marcel (referenced elsewhere in this discussion) addresses this point exactly. I didn't want to invent another scripting language. Python is great for that purpose, except that, as you point out, shelling out is painful. So marcel includes a module, marcel.api, which gives you access to marcel shell capabilities inside of Python. The example I gave elsewhere explores a directory recursively, finds .c and .h files, and counts the lines in them. The shell command was this:

    ls -fr \
    | select (f: f.suffix in ('.c', '.h')) \
    | map (f: f.read().count('\n')) \
    | red +
In Python, it would be:

    from marcel.api import *

    print(first(ls(file=True, recursive=True) |
                select(lambda f: f.suffix in ('.c', '.h')) |
                map(lambda f: f.read().count('\n')) |
                red('+')))
You can see that the ls, select, map, and red commands are called directory from the Python code, without having to call Popen, os.system(), etc. Each version of the code (shell, script) runs in one Python process, (not one process per command).
Re:The Xonsh Python Shell by phillco on Monday October 12, 2020 @06:51PM (#24760402)
Thanks!
Re:The Xonsh Python Shell by BeetleB on Tuesday October 13, 2020 @02:12AM (#24762760)
Not sure what you mean. Are you asking if people can do some kind of shell scripting in Xonsh? The answer is "yes". It's mostly Python, but with extra features so you don't have to do stuff like subprocess, shutil, etc.

I've written simple small scripts with it for my last two jobs.

Re:The Xonsh Python Shell by kortex on Monday October 12, 2020 @11:15PM (#24761899)
I've started using it to replace bash for automated testing. It's easy to add since I'm already installing pytest et al in the container/env. Makes it easy to test situations where I have some python program interacting with other programs thru pipes and such.
Re:The Xonsh Python Shell by dheera on Monday October 12, 2020 @08:27PM (#24761098)
Wow! This is amazing, especially the ability to just type calculations into the terminal, e.g. "5*25.4" or "import math" and then "math.asin(1)".

And you can use matplotlib, numpy, and cv2 directly from the terminal. Freaking awesome.

The only major issue I'm encountering is that if the prompt is wider than the terminal (due to your path + git branch name being too long) it goes bezerk.

Re:The Xonsh Python Shell by BeetleB on Tuesday October 13, 2020 @02:08AM (#24762740)
> The only major issue I'm encountering is that if the prompt is wider than the terminal (due to your path + git branch name being too long) it goes bezerk.

You're likely using prompttoolkit for the prompt. If this is a problem for you, you can set it to use readline, and it will behave the way most shells do.

Re:The Xonsh Python Shell by aviraldg on Monday October 12, 2020 @01:33PM (#24756946)
Meta: There's something weird about the timestamp on this submission. When I look at it from news.ycombinator.com/submitted?id=aviraldg it says it was submitted a day ago, but on news.ycombinator.com/item?id=24744653 it says it was submitted an hour ago. Is this perhaps the result of someone else submitting the link again after I submitted the original?
Re:The Xonsh Python Shell by nemothekid on Monday October 12, 2020 @01:36PM (#24757009)
HN Moderators will sometimes "rescue" a submission if they think it will do better at another time and might be interesting to the community.
Re:The Xonsh Python Shell by AcerbicZero on Monday October 12, 2020 @04:29PM (#24759100)
I've found python to be somewhat inflexible and inconsistent; two qualities which make me think using it as a shell replacement might be a bad idea. Also, who wants to spend hours googling solutions to problems that only affect your shell? I see enough of that with Fish and Zsh.
Re:The Xonsh Python Shell by aviraldg on Monday October 12, 2020 @01:36PM (#24757010)
Original discussion: https://news.ycombinator.com/item?id=9207738

(I reposted because I found out about it recently)

Re:The Xonsh Python Shell by jasonmp85 on Monday October 12, 2020 @03:22PM (#24758355)
Why in god’s name would you ever pick the word “Xonsh” for a project?

If the initial “X” isn’t alienating enough, stay for the “nsh” consonant cluster at the end!

Re:The Xonsh Python Shell by tomjakubowski on Monday October 12, 2020 @03:28PM (#24758428)
"nsh" isn't too bad. English speakers already use that in words like "ensure", and "nch" (which is pretty close) is also common (tranche, enchant)
Re:The Xonsh Python Shell by MikeTheGreat on Monday October 12, 2020 @04:01PM (#24758802)
Re:The Xonsh Python Shell by bruxis on Monday October 12, 2020 @04:16PM (#24758967)
I'm not sure why the downvotes (or at least I don't think they're warranted). I love the project, but the name is ridiculous and honestly makes it a tough sell to bring in new members to the community.

It's simply initially off-putting.