Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
URL: http://github.com/mvdan/sh/discussions/1074
ylesheet" href="https://github.githubassets.com/assets/github-6e7c458caf1e80bb.css" />
Uh oh!
There was an error while loading. Please reload this page.
-
As I mentioned in a recent PR, I'm writing a terminal/shell app and using this package as the shell interpreter. Right now to do "tab completion" I do some rudimentary searching on the existing input to try to find the last word, and then add a "*" and call expand.Fields.
Basically I'm wondering if there's some way to instrument the parser so that even for incomplete input, it tells me the last word or partial word it read, and ideally its type.
For example, "i" expects a command, or function name, or a keyword that begins an expression, all starting with "i" (like "if"), whereas "foo=${bar" is expecting an environment variable that begins with "bar".
Part of the problem is that if I search backwards for a space, for example, well, it could be escaped with a backslash, so it's really part of the previous word. But that backslash could itself be escaped, so it's actually not part of the previous word. So there's no obvious way I can see to deal with quoting correctly except to parse the whole command so far and try to get "the last word", as I said.
Any thoughts?
Beta Was this translation helpful? Give feedback.
All reactions