[HN Gopher] Xonsh - A Python-powered shell
       ___________________________________________________________________
        
       Xonsh - A Python-powered shell
        
       Author : GTP
       Score  : 85 points
       Date   : 2025-02-21 23:48 UTC (3 days ago)
        
 (HTM) web link (xon.sh)
 (TXT) w3m dump (xon.sh)
        
       | brumar wrote:
       | I would not advise to replace your interactive shell with it as
       | it's a pain when you stumble upon uncompatible commands, but
       | writing shell scripts with xonsh is a wonderful experience.
        
         | Qem wrote:
         | What are some examples of incompatible commands?
        
           | brumar wrote:
           | I don't remember exactly why and how some shell scripts
           | refused to run, but on top of my head I think 'alias' was not
           | working and 'sudo !!' too.
        
             | BeetleB wrote:
             | I hope you're not trying to source regular Bash scripts
             | without using _source-bash_.
             | 
             | 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).
        
               | brumar wrote:
               | Interesting! I think I never tried to update xonsh in 7
               | years or so.
        
         | poincaredisk wrote:
         | I use fish, so it's not a problem for me. When I tried it 4
         | years ago it's was a bit unstable, which made me switch back to
         | fish. Also fish is much more polished and user friendly out of
         | the box.
        
         | scottydelta wrote:
         | Can you talk about how is it different than writing python
         | scripts? Or writing test code in the python console?
        
           | Neywiny wrote:
           | Feels like the only benefit is not having to write
           | os.system(). Though maybe including shell scripts (like build
           | environment setup stuff from other software) for more
           | complicated commands? I may give this a try for a bit to find
           | out
        
           | brumar wrote:
           | For me it shines when you need to write shell scripts but you
           | prefer do some parts in python. As another commenter wrote
           | os.system or calling the subprocess module works too, but I
           | find it less satisfying.
        
           | BeetleB wrote:
           | In a xonsh script, you can have regular statements like "cd",
           | "ls", and pretty much everything.
           | 
           | It's just like Bash scripting, except in Python. You can mix
           | and match Python statements with regular shell commands.
        
             | echoangle wrote:
             | I have never tried it but I would probably prefer to use sh
             | ( https://pypi.org/project/sh/ ) and have users install
             | that before having to use a totally separate shell. Python
             | is normally already there.
        
               | BeetleB wrote:
               | Cursory look at the docs:                   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.
        
       | dang wrote:
       | Related:
       | 
       |  _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)
        
       | BeetleB wrote:
       | I've used xonsh as my primary shell since around 2017. It's
       | awesome. Being able to write shell scripts in something very
       | similar to Python is awesome. Bash scripting is the epitome of
       | "not awesome".
        
       | foundry27 wrote:
       | I've been using xonsh as my daily driver for a few years now, and
       | it's a massive productivity booster!
       | 
       | 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).
        
       | aterp wrote:
       | Might be interesting to folks in this thread - I'm working on a
       | CLI tool/language which aims to let people write better scripts,
       | more easily. It integrates well with Bash if it's needed, but
       | lets you to avoid writing whole scripts in Bash and particularly
       | some of the more painful aspects like arg parsing.
       | 
       | This page gives a bit of a preview, plus there are some links at
       | the bottom to additional features. Still under development tho!
       | 
       | https://amterp.github.io/rad/guide/getting-started/
        
       | ambivalence wrote:
       | Xonsh is a fantastic shell. I literally think they are most
       | hindered by the name at this point, since it's one of those
       | clever names that are pronounced in a peculiar way and one that
       | doesn't really convey well that it's really Python + sh in a
       | beautifully consistent design.
       | 
       | 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.
        
       ___________________________________________________________________
       (page generated 2025-02-25 23:00 UTC)