News for hackers. Stuff that matters.
Re:Shshsh is a bridge connects Python and shell by frou_dh on Saturday September 23, 2023 @11:05AM (#37623906)
I have bookmarked/tried so many Python/Shell mashups over the years.

IMHO the following is about the only one that's tasteful in terms of project scope and not going off the deep end: https://github.com/hauntsaninja/pyp

Re:Shshsh is a bridge connects Python and shell by geophile on Saturday September 23, 2023 @11:39AM (#37624248)
I'd be curious on your thoughts on my entry: https://marceltheshell.org. (This website has lots of examples, so you can get a sense of how it works without installing.)
Re:Shshsh is a bridge connects Python and shell by frou_dh on Saturday September 23, 2023 @12:32PM (#37624772)
Personally I wouldn't use a full-on replacement interactive shell because I have a stacked .bashrc that I've constructed over a long time, and things I install from my package manager all come with bash_completion support etc, and even scripts written in Python can have bash completion (https://pypi.org/project/argcomplete/).

I like that you support the scripting use case with vanilla Python syntax. That's something that made Xonsh a non-starter for me (I'm not going to write scripts when syntax highlighting and auto-formatting don't work because it's a superset of valid Python syntax).

Re:Shshsh is a bridge connects Python and shell by geophile on Saturday September 23, 2023 @01:05PM (#37625119)
Thanks.

Lately I've been finding it useful to write bash scripts with some marcel, e.g.

    #!/bin/bash
    echo ...
    pushd ...
    marcel <<EOF
    ...
    EOF
Re:Shshsh is a bridge connects Python and shell by grrandalf on Saturday September 23, 2023 @02:25PM (#37625922)
Thanks for posting. Interesting tool -- I'll take a look at this.

"Saving streams" is killer. I've been "meaning to build something to solve that" for a looong time. :) :) But you did. Thanks!!

https://www.marceltheshell.org/saving-and-recalling-streams

-----

One feature request to think about if it doesn't exist: defining multiline functions right at the prompt, which you later export to a .py file. So I think a decent inline editor with support for arrow keys might be useful. https://www.marceltheshell.org/functions-1

This is not a showstopper obviously. The current 'import' functionality should be enough for me for now.

Why inline vs. shelling out a dedicated editor: because replacing the screen will take me out of flow because I frequently refer to previous commands' output on the terminal when constructing/editing the next command.

Re:Shshsh is a bridge connects Python and shell by geophile on Sunday September 24, 2023 @05:40PM (#37637468)
Thank you! One change from the stream page: > and >> now redirect to files in the traditional Unix/Linux way. (That older behavior was just too ingrained and I imagine it is for lots of people.) Use >$ and >>$ to store in variables that don't survive your session. (The $ is meant to evoke an association with variables.)

Multiline functions can be defined right now:

    M 0.18.3 jao@loon ~$ f = (lambda: \
    M +$    lambda x, y: x + y \
    M +$    )
    M 0.18.3 jao@loon ~$ (f(3,4))
    7
So all that would be needed is a way to dump them into a file. That should be doable with another function.

One thing to note: You have choices beyond inline and imports for defining new functions. There is a startup file, typically in ~/.config/marcel/startup.py. You can define functions in there, or do imports. The REPL loop checks for modifications to that file, so if you change it, you pick up the changes for your next command.

For example, I just put this into my startup file:

    def hello(x):
        return f'Hello {x}'
and then without restarting marcel:

    M 0.18.3 jao@loon ~$ (hello('world'))
    Hello world
Re:Shshsh is a bridge connects Python and shell by zinodaur on Saturday September 23, 2023 @11:25AM (#37624110)
I was really in to this stuff as well - eventually I just settled for awk, it works pretty well
Re:Shshsh is a bridge connects Python and shell by elesiuta on Saturday September 23, 2023 @02:42PM (#37626110)
I have never heard of pyp before, looks neat!

I made something similar myself, pyxargs [1], which doesn't have all the magic of pyp, but although being geared towards more xargs like usage, it also functions somewhat similarly.

For example, although not as clean as the magic variables x, l or line, you can use '{}'

  ls | pyp 'x[:3]'  ==  ls | pyxargs --pyev "'{}'[:3]"
Overall the syntax of pyp looks much better, and the --explain feature is nice since pyp seems to do a little more for you under the hood (the closest pyxargs equivalent being --dry-run). I think I'll start using pyp myself when not running commands over multiple directories of files or in parallel.

[1] https://github.com/elesiuta/pyxargs

Re:Shshsh is a bridge connects Python and shell by throwaway290 on Saturday September 23, 2023 @06:39PM (#37628222)
I like your take on it compared to pyp at first glance because it uses a clearer model (xargs instead of just wildcard pipe) and a more appropriate name, even if it has fewer features.

But yeah I didn't know either existed and I wish I did, seems like it could be really useful in the shell

Re:Shshsh is a bridge connects Python and shell by elesiuta on Sunday September 24, 2023 @02:05AM (#37630535)
Thank you! My original use case was for running ffmpeg in directories with encodings that broke xargs, and later added the py/pyev flags which basically swapped subprocess.run() with exec()/print(eval()).

I didn't really highlight it in the documentation but it can also run commands in parallel as multiple windows in a multiplexer so it's easier to checkup on their progress or interact with them.