-
-
Notifications
You must be signed in to change notification settings - Fork 164
Shell Autocompletion
andychu edited this page Oct 28, 2018
·
40 revisions
-
Survey: What shell completion scripts do you use? (September 2018) -- started by Andy, 36 comments on lobste.rs
-
Subthread on Hacker News -- people brought up argcomplete for Python, rs-clap for Rust, Language Server Protocol
-
Running Bash Completion Scripts with OSH
-
lobste.rs comments -- Xiao (author of Elvish) and I discussed the possibility of shared completions. Discussed the
git
use case. Continued into e-mail thread (will summarize on Zulip) -
Reddit comments -- zsh developer and author Oliver Kiddle (okapi-a) discussed the possibility of shared completions. Continued into e-mail thread (will summarize on Zulip). Goal: Get upstream authors to maintain completion scripts?
- Bash auto-completion in Clang -- Oliver brought this up as an example of something limiting. Doesn't take advantage of zsh features?
-
lobste.rs comments -- Xiao (author of Elvish) and I discussed the possibility of shared completions. Discussed the
-
Release of OSH 0.6.pre5 -- A long list of the things I had to do to emulate bash! Not done yet.
- Proposals
- Design Notes
Here is a draft of an Oil blog post:
- bash and zsh "boiled the ocean" in parallel, i.e. developed completions for common and not-so-common Unix commands.
- zsh maintains many completions in-tree. Bash is at least two different projects.
- although there is also the zsh-completions and oh-my-zsh projects.
- bash does not use its own parser to figure out what the completion context is.
- readline parses the line with COMP_WORDBREAKS.
- Not only that, but bash-completion disregards that, and reparses COMP_LINE. bash is parsed in bash.
- bash dynamically greps the output of 'ls' and other commands for flag completion.
- git is the biggest completion by a factor of 2 in both bash and zsh.
- Some commands partially handle their own completion logic.
- npm
- clang
git --listcmds
- Ryan Prior used https://github.com/davetron5000/gli (a Ruby command line parser) for Conjur tools and got completion info from GLI data structures.
- Some libraries handle their own completion.
- Python argparse
- Rust rs-clap
- google gflags ?
- Grammars / pure-declarative approaches are probably good enough for 90% of completions, but not the (IMO) most important use cases like
git
. - Grammar-based approaches have been tried in the past
- zsh has a nicer completion UI.
- It gives you help for flags.
- It doesn't constantly redraw the line like readline! (argh)
- Thomas Ballinger (contributor to the BPython shell) has a great blog about Terminals.
- It's easier to draw stuff below the prompt than above the prompt.
-
Should we "boil the ocean" 0, 1, or N times?
- 0: emulate bash
- 1: share autocompletion among shells
- N: everybody develops their own
-
What would a shared completion API / protocol / grammar / data format look like?
- Visit https://oilshell.zulipchat.com/ and sign in with GIthub!
_ Advantages:
- Write async messages like e-mail, or chat synchronously in real-time.
- Organize the conversation into threads (the git use case, grammars, Elvish design, etc.)
- Markdown support for code examples
- Notify via e-mail with @, but don't spam people's inbox with every message.
- Public, so new people can view the history (unlike e-mail / IRC)
- Easy login with Github.
- Power
- Is the DSL Turing complete? Does it need to be?
- Latency
- Something in-process has better latency.
- Version skew of completion definitions:
- Querying a binary directly eliminates version skew. The upstream author adds a flag via
argparse
orgolang/flags
, and everything should work. - Otherwise there is an extra step of generating a grammar, and this can get out of date.
- (There are many different ways to distribute binaries now. Package managers are only one. For example, the Rust toolchain is updated with a
curl | sh
-style shell script.)
- (There are many different ways to distribute binaries now. Package managers are only one. For example, the Rust toolchain is updated with a
- Querying a binary directly eliminates version skew. The upstream author adds a flag via
- Version skew of the DSL itself.
- Is it statically linked into every library?
- Killer app: Could you implement the completion server protocol in VimScript? Yes, as long as it can
invoke an arbitrary process.
- You probably cannot implement a DSL in VimScript, or it would be very awkward.