Open tbodt opened 8 months ago
Thanks for the contribution, @tbodt! Could you provide a quick writeup on the overhaul? For example, an explanation of how the state file is used will be super helpful. Thanks!
The basic idea is: bash includes a lot of builtins that dump out shell state (variables, functions, completions) in the same syntax as is used to create them, so if you source a script that defines a lot of functions and then run the dump commands, you can run any of those functions again by restarting bash and feeding in the whole script again.
Storing the state in a file is something i'm not entirely happy with since it's so easy to forget to delete it. I originally was going to store it in memory, but passing it between the three processes involved was a real pain and needed to create temporary files anyway because the fish psub function apparently blocks until the input command completes which means the output had better fit in a pipe buffer or you're going to need a file, and even though i got it to work it was a major performance problem because pushing around half a kilobyte in a shell variable and then sending it into the script file in the form of fish \xHH escapes was not fast. There's unexplored design space here but i just wanted to get it working finally so i made a file. Ultimately fish (and bash) support for non-named pipes is pretty disappointing.
Possible new issue: from the point of view of the script, the bash pid will change between function invocations, and this will break some script out there as a consequence of hyrum's law. I don't have any ideas for fixing this short of another overhaul to write basically an RPC server in bash. Well that could be pretty fun actually now that i think about it...
Major overhaul to support functions. With a bit more work it can probably do completions. Also should fix all the quoting issues.
Not very well field tested yet, but passes all the tests in the repo.
Needs a pass for python 2 compat. I can't really do this easily since my Linux distro has deleted python 2 entirely.