The Xonsh Python Shell(xon.sh)
xon.sh
The Xonsh Python Shell
http://xon.sh
11 comments
Sounds like it should actually be "χonch," then, with a Greek letter chi instead of an 'x'.
This pattern is also present in e.g. LaTeX
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/.
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/.
More taglines are always welcome!
Haven't seen you in meat space for a few years - good to see you're still alive and well in cyberspace!
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!
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!
Okay, but I read it as "zonsh", or maybe "Exxon Shell".
It's pronounced "Konsh". Origin story - name relates to conch ("konk") shells.
Source: my 1st cousin, one of its co-creators and core maintainers.
Source: my 1st cousin, one of its co-creators and core maintainers.
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!
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!
Hi Mike, a lot of us hangout on gitter: https://gitter.im/xonsh/xonsh
Awesome! Thanks for the tip!
What issues? The latest few versions do have a Windows problem, but only for some users - it still hasn't been root caused.
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).
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).
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.
I've written simple small scripts with it for my last two jobs.
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.
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).Thanks!
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.
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.
> 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.
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.
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?
HN Moderators will sometimes "rescue" a submission if they think it will do better at another time and might be interesting to the community.
Original discussion: https://news.ycombinator.com/item?id=9207738
(I reposted because I found out about it recently)
(I reposted because I found out about it recently)
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:
- 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").
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").
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.
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?
If a xonsh user does want to do strict separation, how does that work? Syntactically, how do you separate shell code from Python code?
"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.
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.
You may not be aware, but PowerShell can now be run on Linux, macOS, and Windows.
https://github.com/powershell/powershell
https://github.com/powershell/powershell
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 :)
So help out!
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
judging by the nickname and github url it's yours https://github.com/geophile/marcel
Yes, that’s it. The link is included on the website.
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!
If the initial “X” isn’t alienating enough, stay for the “nsh” consonant cluster at the end!
"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)
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.
It's simply initially off-putting.
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.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.
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.
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.
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.
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.
Ref: See "TAGLINES" def in https://xon.sh/_modules/xonsh/xonfig.html