Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Clamshell- an experimental Python based shell (github.com/benrutter)
51 points by benrutter on Jan 28, 2023 | hide | past | favorite | 25 comments
About a month ago I started a suprisingly-not-that tricky project to build an experimental python repl that I could use instead of bash as a daily shell in windows, mac or linux. It"s more hack-for-exploration than a production ready shell, but here it is! Hope somebody finds it anywhere near as interesting to check out as I found making it.

Disclaimer: I know about xonsh and love it (if you haven't heard of it, google it). This project is more pure python and less python and bash interacting - see the readme for more details.



  ~/me $_ x = files('Music')
  ~/me $_ for item in x:
        >     if 'Rick Astley' not in x['name']:
        >         delete(x['path'])
Shouldn’t that be:

  ~/me $_ x = files('Music')
  ~/me $_ for item in x:
        >     if 'Rick Astley' not in item['name']:
        >         delete(item['path'])

?


on purpose to stop unwary copy pasting?


Haha, thanks! That's such an immensely charitable interpretation of my messy typo- I'll update the readme so people can copy paste there music collection into non-existence if they feel like it. (Luckily it'll just go to the recycle bin so those Bananarama mp3s are still recoverable)


I wish that xonsh took some inspiration from this, allowing "super commands" that return python objects, which can then be piped to normal commands. I want to be able to do things like

    for file in ls:
         if file.is_mount():
             try: fusermount -u @(file)
             except: print(f"Couldn't unmount {file}")

Or more complicated stuff involving piping actual live python objects around. Xonsh is great, but the lack of what you're calling "super commands" does limit things a fair bit.

Right now I can do similar stuff, but I often end up doing horrible things like

    for file in $(ls).split("\n"):
        file=Path(file)
which is not nearly as elegant, especially for more complicated stuff. Lots of places for issues to sneak in, like I'm pretty sure that splitting the output of ls like I did there gives me an extra null directory at the end of the output, not an issue here but it is one more spot for bugs to sneak in.

Of course the other problem with these "super commands" is that they all have to exist in your master shell process. I wonder if you could use something like RPyC to have live python objects that are fully interactable but which live in other processes.


Thanks! Glad you enjoyed looking over it- that's exactly how I feel about xonsh. Having python in the shell feels great, but I'm always left feeling like I have a marriage of something I like with something I like less (not to hate on bash too much) rather than just the shell I want in the first place.

Really cool idea about separate processes- I guess since the shell is its own thing, there's no reason you couldn't write an interpreter in a non-GIL language (like rust or c++) even if the commands where Python. That'd free you up to spawn subprocesses and shells to your heart's content!


I made a somewhat related program called pyxargs[1] which may help with what you're looking for. The command for your example would be

  pyxargs --py "print('{}') if os.path.ismount('{}') else ''" | pyxargs -m stdin fusermount -u {}
[1] https://github.com/elesiuta/pyxargs


This is really neat! I’ve been working on a “shell” that I use for running RPG games in python. I might have to see if I can piggyback off of this.


Can you elaborate on the „running RPG games in python“ please?


Sure.. basically i've been fiddling with creating a 'shell' that lets me at the simplest level do something like this:

  roll 1d20
  You rolled an 18
  roll goblin.attacks.shortsword
  You rolled an 4 on 1d6.
  apply roll goblin.attacks.shortsword to character.hp
The other part will be that it'll let me connect into a foundry instance and have the chat/rolls show up on my terminal.


Thanks for elaborating. Sounds pretty cool actually. Do you have it on GitHub or something?


Not yet. I should sometime soon but life/family/work keeps coming up.

If you want you can drop an email to Sam at phin.tech and I can email you if/when it comes out.


Slightly off-topic: Does anyone have a recommendation for a pdb alternative?

I’ve found most of the alternatives have a high (for my use case) learning curve. For real debugging I use VSCode but it’s nice to be able to quickly throw breakpoints around.


There's some interesting projects like pubd, but I'd massively recommend ipdb. Its basically what I wish pdb was- i.e syntax highlighting, multilinear editing, completion hints etc


If you’re an iPython user, you may enjoy ipdb: https://pypi.org/project/ipdb/


I like pdbpp. Make sure to install from source as there hasn’t been a release in a while.

https://github.com/pdbpp/pdbpp


Slightly off-topic: can anyone recommend a nice framework / library to replace "bash scripts" with Python? For instance, I don't want to deal with subprocess manually.


`sh` is great for that: https://amoffat.github.io/sh/


Nowadays I just use bash because alternative shells often won't be available in dev environments, CI, etc, so bash cannot be avoided anyway. But in the past I've used Python to generate bash script to avoid having to do tricky processing in bash. By piping that into vim you can check the resulting commands before execution in a simple command.

It's a really dumb solution and can work in any language/environment, so I like it.


Something for Python akin to zx for JavaScript?

https://github.com/google/zx



Tiny nit, the logo is an oyster, not a clam.


Probably because there isn't a clam emoji, just an oyster one. That's surprising to me.


This was the exact reason! I should have named it something train themed, then the emoji choice would have been a lot better


But there is a “shell” emoji: https://emojipedia.org/spiral-shell/


True! but the shell was very similar to xonsh's shell, so I figured an oyster was the least confusing choice




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: