Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul #112

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Overhaul #112

wants to merge 2 commits into from

Conversation

tbodt
Copy link
Contributor

@tbodt tbodt commented Dec 15, 2023

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.

i
Change-Id: I42db512aa346cfcdb0d8b29f6044c2df90022189
Change-Id: I7114ffd9645920bbd294af54fc0453241d8777d4
@tbodt tbodt marked this pull request as draft December 15, 2023 17:41
@edc
Copy link
Owner

edc commented Dec 17, 2023

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!

@tbodt
Copy link
Contributor Author

tbodt commented Dec 17, 2023

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...

script_lines.append(comment(b'updating alias %s=%s -> %s' % (k, v1, v)))
else:
continue
script_lines.append(b'alias %s %s' % (k, v))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aliases probably need to be run through bass as well, don't they? At least, I'm currently encountering an alias that contains bash code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants