[英]How to complete rustup/cargo commands?
I have rustup+rust+cargo installed using the official installation script .我使用官方安装脚本安装了 rustup+rust+cargo 。
How do I enable shell completions, to be able to type cargo <TAB>
in the terminal and see the possible commands such as cargo check
?如何启用 shell 完成,以便能够在终端中键入
cargo <TAB>
并查看可能的命令,例如cargo check
?
You can run rustup completions
and follow the instructions.您可以运行
rustup completions
并按照说明进行操作。 For example, for bash
you can run例如,对于
bash
,您可以运行
rustup completions bash >> ~/.local/share/bash-completion/completions/rustup
rustup completions bash cargo >> ~/.local/share/bash-completion/completions/cargo
to generate completions for rustup
and cargo
respectively.分别为
rustup
和cargo
生成完成。 Consult rustup completions
for further details, eg for configuring zsh
and fish
completions.有关详细信息,请
rustup completions
,例如配置zsh
和fish
补全。
@AnonymousDuck's answer is a good way to do it in principle. @AnonymousDuck 的回答原则上是一个很好的方法。 A downside to "expanding" the completions is that one should remember to regenerate the expanded forms after updates, so they're kept up to date with the respective tools.
“扩展”完成的一个缺点是,应该记住在更新后重新生成扩展的 forms,以便它们与相应的工具保持同步。
A way to make that happen on demand (sacrificing a few milliseconds on first invocation) is for example:一种按需实现这一点的方法(在第一次调用时牺牲几毫秒)例如:
printf '. <(rustup completions bash)\n' >~/.local/share/bash-completion/completions/rustup
printf '. <(rustup completions bash cargo)\n' >~/.local/share/bash-completion/completions/cargo
A slight caveat that is rarely an issue is that the use of <(...)
requires the shell to not be in POSIX mode.一个很少出现问题的小警告是
<(...)
的使用要求 shell不处于 POSIX 模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.