SquircleSpace / shcl

SHell in Common Lisp
Apache License 2.0
318 stars 17 forks source link

Export builtins for use with tools like find #19

Open SquircleSpace opened 6 years ago

SquircleSpace commented 6 years ago

This is a completely crazy idea that almost no one actually wants, but...

Tools like find and xargs take in a command to run. Normally, you have to name a command backed by a binary. You can’t really tell xargs to run a shell function you defined earlier in your script.

Or can you?

Imagine there was an executable on disk that represented the builtin command, and running that executable magically got SHCL to run the appropriate builtin in the original shell process. You could just point xargs at that binary and suddenly it would be effectively calling a shell builtin. SHCL could create these files on demand and clean them up when xargs exits.

With FUSE, you could do some even whackier stuff along these lines.

phmarek commented 6 years ago

I guess the way to do that is to export some environment variable pointing to a unix socket to the builtin subprocess, which that one uses to provide a "mirrored" shell by just relaying all commands to the original process. (Similar to "SSH_AUTH_SOCK" and swank communication.)

That way a single value is enough to identify a whole shell environment.

The same idea could be used to have one process in the background, but have multiple shells with TTYs share the same process environment (the same functions, the same variables, etc.) - think about all shells in tmux windows being "the same shell" in the background.

phmarek commented 6 years ago

So, basically have a swank-like communication channel that just transports the parsed representation of what the user types, and STDIN/STDOUT/STDERR for interactive behaviour.

Alternatively, let the parent process do all the parsing as well, and just create a small builtin binary that uses a multiplexed channel to relay the available FDs to the parent process.

SquircleSpace commented 6 years ago

Yeah! Now that you mention it, I remember thinking similar things a long time back. I was thinking of it as being analogous to emacs and emacsclient.