6 ms·
Show HN: Clamshell- an experimental Python based shell
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.
- kwertyops 4y ago~/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']) ?
- totetsu 4y agoon purpose to stop unwary copy pasting?
- benrutter 4y agoHaha, 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)
- pard68 4y agoTiny nit, the logo is an oyster, not a clam.
- Operyl 4y agoProbably because there isn't a clam emoji, just an oyster one. That's surprising to me.
- teddyh 4y agoBut there is a “shell” emoji: https://emojipedia.org/spiral-shell/ https://emojipedia.org/spiral-shell/
- benrutter 4y agoTrue! but the shell was very similar to xonsh's shell, so I figured an oyster was the least confusing choice
- benrutter 4y agoThis was the exact reason! I should have named it something train themed, then the emoji choice would have been a lot better
- traverseda 4y agoI 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.
- benrutter 4y agoThanks! 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!
- elesiuta 4y agoI 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 https://github.com/elesiuta/pyxargs
- upbeat_general 4y agoSlightly 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.
- benrutter 4y agoThere'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
- jmuhlich 4y agoI like pdbpp. Make sure to install from source as there hasn’t been a release in a while. https://github.com/pdbpp/pdbpp https://github.com/pdbpp/pdbpp
- w-m 4y agoIf you’re an iPython user, you may enjoy ipdb: https://pypi.org/project/ipdb/ https://pypi.org/project/ipdb/
- thenipper 4y agoThis 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.
- randomluck040 4y agoCan you elaborate on the „running RPG games in python“ please?
- thenipper 4y agoSure.. 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.
- randomluck040 4y agoThanks for elaborating. Sounds pretty cool actually. Do you have it on GitHub or something?
- thenipper 4y agoNot 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.
- slig 4y agoSlightly 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.
- 0x6c6f6c 4y agoSomething for Python akin to zx for JavaScript? https://github.com/google/zx https://github.com/google/zx
- alxprc 4y agoMaybe Plumbum: https://plumbum.readthedocs.io/en/latest/ https://plumbum.readthedocs.io/en/latest/
- goffi 4y ago`sh` is great for that: https://amoffat.github.io/sh/ https://amoffat.github.io/sh/
- woolion 4y agoNowadays 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.