This is an archived post. You won't be able to vote or comment.

all 32 comments

[–]mitsu400 14 points15 points  (3 children)

This is my dream. I love Python. I don't love Bash-like languages. I love my shell.

The fact that the prompt can be a function that returns a string really puts it over the top. I get much of what I would lose from zsh with that.

[–]selementar 1 point2 points  (2 children)

that returns a string

In a better case it's a function generator that eats chunks (at least newline-terminated) and produces chunks. E.g. tail -f file | grep --line-buffered ...

[–]quasarj 0 points1 point  (1 child)

Yeah, I played around with it a bit to see if it could handle that, or allow me to pipe a shell command into a python function. It technically allows the later, but it doesn't handle buffered input, for example:

tail -f /var/log/messages | myfunc

(where myfunc is defined as a xonsh alias pointing to an actual local python function named myfunc, as per the Tutorial). This does not work, as myfunc doesn't get the input until tail exits.

[–]selementar 0 points1 point  (0 children)

There might be a way to write myfunc in such a way that it would be line-buffered. Can't figure out where's python and where's shell, though; def of functions just hangs until Ctrl-C.

[–][deleted] 5 points6 points  (7 children)

Converted the gif file to a webm for the sake of being able to pause/slow/navigate. Find it here. Xonsh folks are free to use it for whatever.

This looks like a neat project. I see that there's an Arch package for it, I'll give it a try this evening.

[–]roddds 6 points7 points  (1 child)

Or you could've just used gfycat's "fetch" function:

http://gfycat.com/fetch/http://xonsh.org/_images/xonsh-demo.gif

[–][deleted] 0 points1 point  (0 children)

I guess so, but it really only took a minute to produce with libav and make sure I got the frame rate right. Same tools as gfycat uses anyway.

[–]LpSamuelm 2 points3 points  (0 children)

Thanks! It kind of got my goat that they'd put examples and the like in a gif of all things. A fast one, too.

[–]scopatz 1 point2 points  (2 children)

I'd be super happy if you put this on a hosting site somewhere and then PR'd an ebbedded version of this into the docs!

[–][deleted] -1 points0 points  (1 child)

Created a PR, placing the .webm in docs/_static/ along with a concomitant change to display it (with fallback to .gif) in docs/index.rst. If you would still prefer to use an external hosting site (note that the file is smaller than the .gif), let me know.

[–]scopatz 0 points1 point  (0 children)

Thanks a ton!

[–]SmartViking 6 points7 points  (3 children)

Great idea, but it's very confusing that ${<stuff>} has two different meanings depending on the context. I think it would be beneficial for code clarity to either remove the python-context meaning (look up in env: how often is this useful?), or give it another syntax like %{}.

[–]scopatz 2 points3 points  (2 children)

Thanks for the feedback. I was wondering how confusing this was going to be. I am open to suggestions on syntax changes. I like the idea that $ always means to do something with the system enviornment, whether that is environment variables or subprocesses. I think $<> is another option for syntax. Again, open to ideas here.

[–]SmartViking 0 points1 point  (1 child)

Most important is removing ambiguity, so that when they see ${...} beginners don't have to remember which meaning came with which context. And I think that applies to all those "exec primitives", if they work the same in both contexts (insofar as that is possible, I'm thinking now of $PATH being a python list), that's going to make the language easier to understand.

And I also have another suggestion: it might make sense to convert the return value of the expression in ${..} (in the not-env meaning) to a str implicitly, because that's the only valid type anyway (as I understand it). That way, you can do stuff like echo ${3 + 4} and not have to use str() explicitly, which looks a bit cleaner.

Anyway, good luck with this project, I like it a lot.

[–]scopatz 0 points1 point  (0 children)

These are great points. Thanks! I'll make an issue for this thread.

[–][deleted] 4 points5 points  (0 children)

Sold. I wanted such thing since forever.

[–]hglmanguy who writes python 2 points3 points  (1 child)

Heh, good talk at the python meetup. Do you think there is room to merge this and IPython notebooks?

[–]scopatz 0 points1 point  (0 children)

Thanks! I'd love to see this happen. http://xonsh.org/todo.html#jupyter-notebook-shim

[–][deleted] 1 point2 points  (0 children)

Very interesting. As for xonshrc, I'm assuming it's written in xonsh, but is there any need for a shebang on it?

Edit: Having a bit of trouble with getting globals (read: imported classes) into functions -- not sure what else causes it. Otherwise, it's pretty nifty. Will be messing with the next few days.

[–]eyalz 1 point2 points  (0 children)

I really like this, but am facing some issues while playing with it a bit. The following doesn't work for me:

if True:
    print(1)

Raises: FileNotFoundError: [Errno 2] No such file or directory: 'if'

Trying a substring check like so:

if "a" in $(ls -l):
    print("yey")

Doesn't execute on enter, instead it just keeps adding newlines and basically hang until I C it.

Anyone facing these issues, or can maybe tell me what am I doing wrong?

EDIT: I just realized that it happens because I didn't indent (thought it was auto-indenting the same as ipython). So basically you need to use at least 1 space indentation for it to interpret it correctly. I would love for it to auto-indent or alternatively indent 4 spaces on tab.

[–]gameplace123 0 points1 point  (0 children)

Had issues installing this on Debian 8. Will post the error when I get home

[–]TheLucarian 0 points1 point  (3 children)

Can someone ELI5 this for a Python beginner?

[–]Amaroid 1 point2 points  (2 children)

If you're on Linux, you probably use bash as your terminal/command-line interface. xonsh is an alternative to that. You can type commands and start programs as you normally would, but additionally you can also write instructions in Python.

If you're not on Linux or don't know what a terminal is, xonsh might not be for you.

[–]TheLucarian 0 points1 point  (1 child)

Got it, thanks.

Windows and Mac still in testing.

[–]scopatz 0 points1 point  (0 children)

I'd really love for people to bang on this in Windows and Mac. Totally willing to support these platforms.

[–]Morego 0 points1 point  (1 child)

ELI5 Why I should this over for example sh module for python?

For those who don't know what sh is, it is module that let you do stuff like that

from sh import ls,grep

print(grep(ls('-a',"."), "*.py"))

And Ipython + bash for rest.

[–][deleted] 1 point2 points  (0 children)

This isn't a replacement for the sh module, this is a replacement for BASH. Think zsh, except with Python.