5 ms·
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 b
by traverseda 4y ago
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.
- 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