Skip to content

Add special-case readline completion logic for first-position #202

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jpco
Copy link
Collaborator

@jpco jpco commented Apr 23, 2025

We can't complete %pathsearched binaries, but we can complete some things in "first position". So this adds:

  • A way to detect the start of commands when those happen in the middle of a line (like after a ; or & or | or {).
  • Completion for syntactic forms at first position -- local let for fn %closure match
  • Function completion at first position
  • Completion for executable files and directories at absolute paths, but not other files, in first position

Shortcomings:

  • Start-of-command detection doesn't handle newlines-inside-() properly; I believe doing that would require a novel (within es) method of retaining previous-line state.
  • Paths starting with ~/ or ~username/ don't have filtering for whether they're executable, because I didn't want to bother with tilde expansion.

Possible further improvements for builtin completion:

  • variable-assignment completion? (like path =)
  • control primitive completion better -- right now you'll get primitive-completion if you already typed $&, but it should actually happen at start-of-command position
  • A variable to manually store the list of completable commands?

Of course, programmable completion based on semi-parsed input and something like #178 would be the "real", long-term goal, but this is a useful stop-gap and helps inform how its design would need to work.

A funny outcome of this change: path-cache.es makes it so that running a binary once makes that binary name complete-able from then on.

This code is getting messy... Also, my attitude for readline integration (somewhat unlike my attitude for the rest of the shell) is that these kinds of "80%-working" solutions are okay. If other people want to vocally disagree with that, please do :)

@jpco jpco changed the title Add special-case completion logic for first-position Add special-case readline completion logic for first-position Apr 23, 2025
jpco added 2 commits May 17, 2025 09:13
Now we know we're in command position after `blah <=` and `blah |[2] `.
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.

1 participant