9 ms·
Xonsh, a Python-ish, Bash-compatible shell language and command prompt
- digi_owl 12y agothe demo gif could use some delays before each clear...
- dmix 12y agoYup, transitions way too fast to know whats going on.
- blakehaven 12y agoI was able to read the gif as the information was displayed.
- eximius 12y agoRead it, yes. Appreciate it, no.
- scopatz42 12y agoI'd readily accept any new demo videos :) Just use a white background so it matches the website theme
- strunz 12y agoIs there a reason xonsh doesn't honor the PS1 variable from bash to keep your terminal prefix? Or is there a way to customize xonsh's? Example: 10:54:01 foo@bar:~/scripts/xonsh$ xonsh foo@bar ~/scripts/xonsh $ # no time prefix
- untothebreach 12y agoIf you go to [http://xonsh.org/tutorial.html#environment-variables http://xonsh.org/tutorial.html#environment-variables] and scroll down to the table, you can see how to change the prompt :)
- strunz 12y agoThanks, doesn't look like you can use anything that isn't in the supported keywords though (like date/time)
- roryokane 12y agoIt looks to me like you can. > PROMPT: The prompt text, may be str or function which returns a str. If you need non-built-in values in your prompt, just set PROMPT to a function, and call something like `date` within the function. Use `%` to format `date`’s output into a template string, and then pass that template string to `xonsh.environ.format_prompt` to get the final value to return from the function.
- giancarlostoro 12y agoForgive me for my lack of knowledge, but where would one use this vs. just using Python?
- eximius 12y agoYou can use it instead of Bash. It basically combines the two... it looks glorious.
- yeukhon 12y agoI think another question is when would one use Python over Bash and vice versa. Personally, I write bash (and shell, reminder bash script not always == shell script) if I need handy command lines. I could have run in subprocess, but would be simpler to just invoke commands directly in my bash script.
- osn 12y agoIs there oh-my-xonsh ready or should we wait for it?
- patrickshan 12y agohehe, you mean zsh ?
- osn 12y agoI mean xonsh. Oh'my exists for zsh, fish, git...
- agumonkey 12y agoKinda like it. Not too big a step up from Bash.
- bkeroack 12y agoThis is great. When dealing with bash stupid-isms I've always thought it would be awesome to have a shell with Python syntax. The tough part is figuring out how to combine Python with "normal" shell commands in a clean, intuitive manner but it looks like Xonsh has gone a long way towards solving that! Just installed on my personal Macbook. Will see how it goes.
- meddlepal 12y agoI agree, this is awesome. I hate dealing with bash but it's pretty common when you're DevOps.
- spystath 12y agoYou could already do some minimal shell-like scripting with ipython[1]. Just put your ipython-flavored script in a file with .ipy extension an call it with ipython, or just use #!/usr/bin/ipython as a shebang. #!/usr/bin/ipython files = !ls for f in files: print(f) That being said, it is a bit clunky to use since it's not a proper shell, so xonsh is definitely a very welcome improvement. [1]: http://ipython.org/ipython-doc/stable/interactive/shell.html http://ipython.org/ipython-doc/stable/interactive/shell.html
- AstroChimpHam 12y agoIs there a way to switch explicitly between Python and Bash mode? The "ls -l" example makes me pretty worried that this could mess up basic bash scripts that already work just by defining a variable like "ls" and forgetting about it, or forgetting where it's defined. It's a great idea, but there's a lot of room for stuff breaking that worries me.
- sciurus 12y agoYou can use an uncaptured subprocess to run a command explicitly in bash mode. I'm unsure how you think xonsh would break a bash script, though. When you run a script in xonsh it's still going to be interpreted by whatever is declared in the script's shebang. Just like you can run a perl script from bash, you can run a bash script from xonsh. E.G. $ ls='foo' $ cat test.sh #!/bin/bash ls ~ $ print(ls) foo $ ./test.sh bin C:\nppdf32Log\debuglog.txt foo initrd.img.old lost+found opt run sys var boot dev home lib media proc sbin tmp vmlinuz cdrom etc initrd.img lib64 mnt root srv usr vmlinuz.old
- ridiculous_fish 12y agoThe stuff that gets broken are bash scripts that are designed to be sourced directly: virtualenv, rbenv, various prompts, etc.
- bkeroack 12y agoPresumably the shebang at the start of your script would cause it to be executed by bash directly.
- ptx 12y agoI don't think you would replace /bin/bash with this, but rather switch to it as your interactive shell, using "chsh". On FreeBSD, for example, the default shell is /bin/tcsh but scripts are usually written for /bin/sh (with a shebang line). Even if this thing can execute unmodified bash scripts (can it?), it seems to me that would be missing the point, which is to avoid the horror of writing complex bash scripts. When I start writing something in bash, because of those few things it makes so easy (e.g. running subprocesses), I usually regret it as the script grows. If xonsh can make those things just as easy, every script can be written in the right language – which is of course Python :) – from the start.
- deleted 12y ago[deleted]
- doomrobo 12y agoI genuinely wish there was an alternative that could gain enough traction to reach critical mass and hopefully start shipping with operating systems. I've never bothered to learn bash because it was always so damned confusing, and I just couldn't get over the idiosyncrasies when playing around with it. I wouldn't mind putting in time to learn something new and actually user-friendly.
- fiatjaf 12y agoHave you looked at fish? It is in the package repositories everywhere, I think.
- doomrobo 12y agoEven so, the single most attractive trait of bash is that it ships with almost everything. If I have to write a script on a machine with no internet, then bash is the only option. This its strongest source of staying power.
- doomrobo 12y agoI actually gave fish a try after you recommended it. I can't use it in my workflow :(. Virtualenv has a bash script to initiate the environment and fish's incompatibility with bash scripts makes it impossible for me to work with it.
- 12y ago
- ridiculous_fish 12y agoI'm a lead dev on the fish shell (http://fishshell.com http://fishshell.com) xonsh looks very cool. Shell scripting languages are famously obtuse and underpowered, and we've thought about how to cleanly merge shell scripting with a real language. It's heartening to see an attempt at it. Ambiguous syntax is a sticking point. For example, say the user runs this: [ 1 ] is this constructing a Python list with the value 1, or is it invoking /bin/[ with two arguments? It's ambiguous! It looks like xonsh interprets it the first way. Any thoughts on this issue? A related issue is the relationship between bash functions and Python functions. I'd be very interested to see how xonsh approaches this. Also, here's some unsolicited advise, from one non-POSIX shell maintainer to another: The claim that xonsh is "bash-compatible" is delicate. Full bash compatibility requires your shell to be insane. E.g. echo foo | cd / cd / | echo foo In bash, only the second line will change your working directory. Or consider this command: * this finds the first (for some meaning of first) file in your directory and invokes it with all other files as arguments. I tried it: xonsh doesn't handle either of these "correctly," which is to say that xonsh isn't yet insane. That's good news! On the other hand, this means it's not really bash compatible. IME nobody really cares about full bash compatibility. What they want is for their existing bash stuff to just work. Bash shebang scripts will just run in real bash, but that leaves shell-integration scripts: virtualenv, rbenv, etc. Supporting that stuff is one of the most common requests that the fish shell gets, and one of the most commonly cited reasons for not using fish. Here's a piece of rbenv's bash integration: https://github.com/sstephenson/rbenv/blob/master/libexec/rbenv-hooks https://github.com/sstephenson/rbenv/blob/master/libexec/rbe... . It's short but there's a lot of features being used: set, shopt, IFS, functions, etc. If you're aiming for bash compatibility, that's your target! In the meantime, I suggest changing the language to express that xonsh is bash-like, not bash-compatible. Otherwise users are going to be confused and disappointed.
- eddieplan9 12y ago> that leaves shell-integration scripts: virtualenv, rbenv, etc. Supporting that stuff is one of the most common requests that the fish shell gets, and one of the most commonly cited reasons for not using fish. shameless plug, but I made a utility to solve the problem: https://github.com/edc/bass https://github.com/edc/bass So you can write `bass source /usr/local/bin/virtualenvwrapper.sh ';' mkvirtualenv env1`, which of course can be shortened with a function.
- eximius 12y agoSo, for anyone like me who wanted to install it with pip, but has Python 2.7 as their default (and doesn't want to change for fear of breaking things), do the following (on a Debian based system): curl -O https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py https://raw.githubusercontent.com/pypa/pip/master/contrib/ge... sudo python3.4 get-pip.py sudo mv /usr/local/bin/pip /usr/local/bin/pip3 # optional, adjust line below if ommited sudo pip3 install xonsh ------ then: chsh -s /usr/local/bin/xonsh <yourusername> EDIT: Just realized I forgot a step. You have to edit /etc/shells to add /usr/local/bin/xonsh to change your shell to it using chsh.
- ivh 12y agoFor Debian/jessie it worked nicely for me to just install python3-ply and python3-pip with apt-get and then just do "pip3 install xonsh". Python3 seems to coexist just fine beside the default 2.7.
- eximius 12y agoSomehow, python3-pip escaped me. I feel silly.
- strunz 12y agoOn OSX I just installed it in a virtualenv with python3: brew install python3 # will install python3 but not make it default mkdir xonsh && cd xonsh virtualenv -p /usr/local/bin/python3 venv source venv/bin/activate pip install xonsh xonsh
- morekozhambu 12y agoIs there a ruby-ish shell out there?
- vram22 12y agoThere was one called rush, by Adam Wiggins, co-founder of Heroku, IIRC. I had tried it out a bit after it first came out. Just now did a Google search for "ruby shell rush" - without the quotes, and it found it - first result, though the others about it look interesting too. Not sure if the project is active though.
- krick 12y agoPretty cool, but I feel unsure what output something will produce. Look: a = $(ls) a # '1\n2\n3\n4\n' b = `ls` b # [] <-- What?! Because of these little surprises I cannot really feel confident using it.
- bishc 12y agoI see a lot of discussion on the awkwardness and idiosyncrasies of shells like bash.... So this is a great time for a shameless plug! Last week I released a language called 'bish' (https://github.com/tdenniston/bish https://github.com/tdenniston/bish) which compiles to bash, but has none of the same syntactical weirdness. So the idea is: write and maintain your script in bish, but compile to bash and ship the bash version. Here (https://news.ycombinator.com/item?id=9166386 https://news.ycombinator.com/item?id=9166386) is the previous discussion from last week.
- fastviper 12y agoWow.. this only needs python. Which means.. it works on windows? Sadly no support for python 2.7 so I'm out of possibility to even test this.
- rufugee 12y agoIs && and || supposed to supported? When I try "command && someothercommand", which is a common bash idiom, xonsh seems to just freeze up until a ctrl+c. It also jumps up to around 100% CPU.
- rufugee 12y agoAdditionally, redirection of stderr with 2> doesn't seem to work. Can you describe (or point out in the docs) how to accomplish this? Thank you.
- vram22 12y agoInteresting thread. For some alternative ways of doing "pipe-like" stuff in Python (with more than one meaning of the term), see these links: Swapping pipe components at runtime with pipe_controller: http://jugad2.blogspot.in/2012/10/swapping-pipe-components-at-runtime.html http://jugad2.blogspot.in/2012/10/swapping-pipe-components-a... That above post was the last in a series that I wrote over a period. The series describes both a) a small experimental tool I wrote, with examples of a few ways of using it, and b) some other Python-shell tool alternatives that I came across. pipe_controller was inspired by reading about and trying out some of those other tools. The post above links recursively to all the other posts in the series, but for convenience, I'm pasting selected other links below: Using PipeController to run a pipe incrementally: http://jugad2.blogspot.in/2012/09/using-pipecontroller-to-run-pipe.html http://jugad2.blogspot.in/2012/09/using-pipecontroller-to-ru... Some ways of doing UNIX-style pipes in Python: http://jugad2.blogspot.in/2011/09/some-ways-of-doing-unix-style-pipes-in.html http://jugad2.blogspot.in/2011/09/some-ways-of-doing-unix-st... Plumbum, UNIX shell-like library and tool in Python: http://jugad2.blogspot.in/2012/08/plumbum-unix-shell-like-library-and.html http://jugad2.blogspot.in/2012/08/plumbum-unix-shell-like-li...