You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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