3 ms·
Author here. This blog post is the result of my puzzling over how auto-complete works in the shell, and subsequently whether shell completion scripts could be w
by JoshMcguigan 7y ago
Author here. This blog post is the result of my puzzling over how auto-complete works in the shell, and subsequently whether shell completion scripts could be written in Rust. It also introduces a new Rust crate, shell_completion[0], which is a library that exposes some low level primitives for writing shell completion scripts in Rust. shell_completion is certainly in its infancy, so I'd be happy to have contributors of any kind (both code and opinions are welcome).
[0]: https://github.com/joshmcguigan/shell_completion https://github.com/joshmcguigan/shell_completion
- sam0x17 7y agoThis is very cool -- thanks for your work! I wonder if the API for windows auto-completion is sophisticated enough that you could add cross-platform support for this.
- jbreiding 7y agoNo need to worry if you just use the same shell through WSL. The integration is with the shell not the os.
- sbr464 7y agoI’m curious about your approach, did you have any resources or projects that you found yourself going back to? (Regarding shell completions in general)
- JoshMcguigan 7y agoThese [0] two [1] sections of the GNU Bash man pages were very useful. I also found that this tutorial [2] provided a useful perspective. I spent a small amount of time looking through the bash-completion [3] project as well as the git bash completions [4]. Generally, my process for writing is google around until I have some base level of knowledge, then building one or more demo applications to ensure my understanding is correct. Then as I'm writing the blog post I'll be refining the demo applications into examples for the blog post and/or library code that I want to open source. [0]: https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion https://www.gnu.org/software/bash/manual/html_node/Programma... [1]: https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#Programmable-Completion-Builtins https://www.gnu.org/software/bash/manual/html_node/Programma... [2]: https://hackaday.com/2018/01/19/linux-fu-custom-bash-command-completion/ https://hackaday.com/2018/01/19/linux-fu-custom-bash-command... [3]: https://github.com/scop/bash-completion https://github.com/scop/bash-completion [4]: https://github.com/git/git/blob/master/contrib/completion/git-completion.bash https://github.com/git/git/blob/master/contrib/completion/gi...
- sbr464 7y agoThanks for sharing (and @snowe2010)
- snowe2010 7y agoI've actually written two separate articles on shell completion, explicitly for subcommands, because the resources regarding subcommands is so lacking. https://tylerthrailkill.com/2019-01-13/writing-zsh-completion-scripts/ https://tylerthrailkill.com/2019-01-13/writing-zsh-completio... https://tylerthrailkill.com/2019-01-19/writing-bash-completion-script-with-subcommands/ https://tylerthrailkill.com/2019-01-19/writing-bash-completi... I need to improve them and write a bit more information, I was writing a library to generate completion scripts for both bash and zsh, so I had to know the differences quite well.