Xonsh – A Python-powered shell
xon.sh
xon.sh
Xonsh: Python-powered, cross-platform, Unix-gazing shell - https://news.ycombinator.com/item?id=39368586 - Feb 2024 (102 comments)
Ask HN: Does anyone use xonsh shell? - https://news.ycombinator.com/item?id=34449879 - Jan 2023 (3 comments)
Xonsh: I don't remember how to write a for loop in Bash [video] - https://news.ycombinator.com/item?id=33044772 - Oct 2022 (130 comments)
Xonsh is a Python-powered shell - https://news.ycombinator.com/item?id=30457791 - Feb 2022 (3 comments)
Xonsh is a Python-powered shell - https://news.ycombinator.com/item?id=30442016 - Feb 2022 (1 comment)
The Xonsh Python Shell - https://news.ycombinator.com/item?id=24744653 - Oct 2020 (41 comments)
Xonsh: Python-powered, cross-platform, Unix-gazing shell - https://news.ycombinator.com/item?id=17989710 - Sept 2018 (93 comments)
Xonsh: a Python-ish, BASHwards-looking shell language and command prompt - https://news.ycombinator.com/item?id=11836893 - June 2016 (2 comments)
The xonsh shell - https://news.ycombinator.com/item?id=11672023 - May 2016 (53 comments)
Xonsh, a Python-ish, Bash-compatible shell language and command prompt - https://news.ycombinator.com/item?id=9207738 - March 2015 (61 comments)
Broadly speaking I’ve found that most of the reported compatibility and usability concerns in their GitHub issues have boiled down to user error, rather than any kind of a defect with the shell itself. That’s not to say there aren’t any issues, but they’re few and far between, and it’s more than solid enough for regular use. It isn’t bash, and you shouldn’t expect to execute a bash script with xonsh or use bash idioms (even though some compatibility layers exist for e.g. translating your ~/.bashrc and sourcing envvars from bash scripts).
It's very easy to switch if you're willing to spend 30 minutes to go through this talk about its design by the author: https://www.youtube.com/watch?v=uaje5I22kgE
After this short intro you will know how Python and shell interact within xonsh and you'll avoid surprises.
I wish it started faster, but it's a really small price to pay for having Python 3.13 open literally at all times.
(Homepage) https://takoshell.org/index.html
(Differences from Xonsh) https://takoshell.org/xonsh.html
Specifically, there are a number of imports from collections which appear to no longer work, and I had to install a fairly old version of collections to get Set and MutableSequence (which `tako/takoshell/tools.py` subclasses).
`hz.mit.edu` is not a git forge, so I don't think I can submit a PR without e-mailing the author.
It looks unmaintained. Last release 5 years ago, documentation is sporadic.
Reminds me of some of the angry forks of Black that get like 100 downloads a year.
I've used xonsh as my primary shell for many years now. The Bash compatibility was poor initially, but they fixed most/all the issues, and source-bash just works.
I use Gentoo, and don't actually use sudo, so I can't comment on that (I just su into root).
>>> os.getcwd()
'C:\\Users\\Admin\\Downloads'
>>> os.system("cd Video")
0
>>> os.getcwd()
'C:\\Users\\Admin\\Downloads'
>>> import os
def sh(x):
return os.popen(x).read().split("\n")It's just like Bash scripting, except in Python. You can mix and match Python statements with regular shell commands.
sh.ls("-l", "/tmp", color="never")
Oh dear - no. A lot less ergonomic than "ls -l /tmp".If all you want is a convenient way to call commands from Python scripts, sh makes sense. The benefit of xonsh, though, is that it is a shell :-)
So, for example, if you want to have a fancy prompt, you can use Python functions to construct your fancy prompt. If you want to manipulate your $PATH as a list (or any similar environment variable), you just treat it like a Python list and do whatever you want with it.
I often write simple conditionals/for loops right on the prompt (not via a shell script). I use the Python syntax, but call whatever command I want and manipulate it.
And it's really handy that the shell prompt is a Python prompt - you can import any Python library and play with it. I never run "python" to get to a Python prompt. I have it available at all times. I want to look at a docstring for a standard Python function? I just do it at the command line.
There are a lot of new shells, but despite the overwhelming positivity of each thread here they've each been super incomplete/half baked. FWIW I'm looking for a non-posix de-crufted (no oil shell, no zsh) and lightweight/minimal (no fish) shell.
I haven't tried all of these out significantly (really diving in takes hours if not days) but considering my use cases and thoroughly reading the documentation/field reports:
Elvish seemed really cool but has no async/background task support. Furthermore AFAICT you can't iterate over the output of a process _while_ it's running. There are bugs (can't import edit module), there's TODO all over the docs despite supposedly being mature and stable, etc.
Nushell also has no async/background task support (pueue doesn't count, running in separate process trees has countless implications).
Ion shell sounds great on paper, but it's missing the entire first 2-3 chapters of its documentation. It doesn't seem to have any significant background job control, and seems more like a paper-overing of shellisms than a reinvention.
So xonsh seems like the best remaining competitor. It supports background processes with `Popen`, but I can't find an example for async iterating lines. I see lots of examples that are like, `for x in !(ls)` or `for x in $(whatever).splitlines()` but both of those require the command to finish before executing the loop.
Then I keep seeing reports of Ctrl+C breaking with loops, all the python module and environment dependency management madness (plus cross contamination), excessive slowness when mixing python and commands, etc etc.
I'd like to hear a critical rebuttal of these but I think these new shells are more intellectual curiosity than an actual step up. I'm probably going to give up and go with zsh, which while not an improvement at least it will do what I need I don't have to learn anything new.
One thing I've learned though is that although amazing testimony, being someone's main driver isn't a good enough review. Heck, bash has been my main driver for 15 years and it's _awful_. You learn the pain points and then subconsciously avoid doing anything with it near those points.
I remember seeing some simple CLI program that you could pipe your task into, and it would notify you when the task completed. the names escapes me at the moment.
Not to put you off investigating alternative shells (I've spent time with rc shell, xonsh (and tako), and even turned gauche scheme & tcl into a commandline shell), but isn't your bash problem solved by using $PS1 to launch your own functions to do whatever?
At least, you can use $PS1 for the "after command" bit. For pre-command, just use a simple 1 letter wrapped script which does whatever, and then exec's the remaining arguments (aka "Bernstein chaining")
(unless I've gotten the wrong end of the stick, and am missing what you meant)
Perhaps you could start a timer in a preexec, and stop it in precmd. If the elapsed time is greater than some value, notify-send yourself a message that a long-running command has finished.
Incorrect. This can be achieved because I've done it ;)
It relies on trap DEBUG (preexec) and PROMPT_COMMAND (precmd), but to make this much easier for me I've ported zsh preexec and precmd callback support to bash:
https://github.com/lloeki/dotfiles/blob/master/bash/ext
Then with those callbacks now available it is quite easy to e.g compute time between command start and command end:
https://github.com/lloeki/dotfiles/blob/master/bash/rc
(The time thing is commented out because I don't need it right now, I used it to display command exec time on the prompt. Note that bash EPOCHREALTIME has second-level precision)
And from there notifying completion of commands that run longer than X is absolutely trivial.
Other things I've "backported":
- chpwd callback
- the %\n thing on lack of newline in command output
- PROMPT and RPROMPT
- zprompt colors
Naively I’d expect Fish to seem more minimal than something like xonsh (which embeds the entirety of Python).
this was a complete python non-starter for me as soon as I encountered it a couple of times, and it mystifies me how others tolerate this crap
and you have python added on
This page gives a bit of a preview, plus there are some links at the bottom to additional features. Still under development tho!
Once you were reading code, it made sense for the most part. But when I had to write a new multiline command or a script, I had to look things up in documentation constantly. For my brain "similar but different" was torture, not an advantage.
With Xonsh you get real Python and this solves all my problems. As soon as you learn what $VAR, $(CMD), and @EXPR do, you're good to go!
[1] https://amterp.github.io/rad/guide/args/#arg-declarations
[2] https://amterp.github.io/rad/guide/rad-blocks/#basic-example
Sold. Let me start using this immediately