Back to Shell Autocompletion
Notes from discussion:
grep myfile.c doesn't result in a syntax error, but it's not a good completion IMOesc for completion and ? to display options.
grep, which is incorrect
grep isn't a filels | grep and ls | wc -l make sense because the second commands read from stdin, but ls | ls doesn't. But none of bash/zsh/fish understand that.I think it can be as simple as an API to throw exceptions for command errors, e.g. consider:
grep --no-filename
grep --max-count
grep --max-count=
These all result in syntax errors, and some of them are different. Right now most commands aren't consistent about how they report errors.
But the "carrot" is if they are consistent and use an Oil API, then they will completion for free, and it will be correct.
Of course you also need to display completions when there are no syntax errors, like
grep pattern file1.c <TAB>
should complete another file, even though the prefix is a valid command
only the command knows
So the syntax error can include a completion type, like
raise SyntaxError('FILE', 'file expected')
raise SyntaxError('HOST', 'host expected')
raise SyntaxError('arg expected') # a command arg, not flag arg
You could implement such a parser/API in any language but I would start with Oil. I guess you could do it in sh with global variables since it doesn't have rich return values/exceptions.
That is another instance of the problem where the sh language isn't expressive enough to express basic things about its problem domain.
def Parse(argv):
# maybe raise syntax error
return opts, CompletionHint('FILE') # success, but could be more args
And I mentioned there also another approach that's more like information retrieval -- parse all the successful commands from history, and complete based on that. That eliminates some of the "boiling the ocean" problem, and can also be used for ranking.
i.e. bash on Ubuntu will complete something 500 commands by default from an empty state (and it's slow). but obviously it would be better if it ranks it by the commands you actually use.
I think that's pretty powerful but I haven't explored it yet
I think if you were to really evaluate it from an HCI perspective, it would basically force you to do ranking, because it would be such a big win
bash does no ranking / priority but I think fish does some. zsh doesn't appear to either