大型/.ssh/config文件使用zsh的自动完成速度较慢 [英] Autocomplete slow using zsh for large /.ssh/config file
问题描述
我目前有一个/.ssh/config文件,其中包含大约7000行.
I currently have a /.ssh/config file the has about 7000 lines in it.
我正在尝试查看是否有一种方法可以为此加快zsh中的自动完成功能.
I am trying to see if there is a way to speed up the autocomplete feature in zsh for this.
当我开始键入要ssh进入的服务器,然后按TAB
时,它大约需要10秒钟,才能向我显示我可以选择的主机.
When I start typing which server I want to ssh into and then press TAB
it takes about 10 seconds for it to show me the possible Hosts I can choose from.
推荐答案
问题是_ssh
的完成每次尝试尝试完成Host
指令时都会逐行读取整个配置文件,以查找Host
指令.主机.
The problem is that the completion for _ssh
reads your entire config file line-by-line looking for Host
directives each time you try to complete a host.
一种解决方案是重写相关功能(_ssh_hosts
),以更快地执行某些操作(例如在内存中缓存主机名以用于后续完成).
One solution would be to override the relevant function (_ssh_hosts
) to do something faster (like cache host names in memory for subsequent completions).
另一种方法是通过将实际配置移动到单独的文件中来使配置文件更小,而将配置文件保留为Host
/Include
对的列表.例如,打开
Another would be to make your config file smaller by moving the actual configuration into separate files, leaving your config file as nothing but a list of Host
/Include
pairs. For example, turn
Host foo
User bob
IdentityFile ~/.ssh/bob_ident
Host bar
User alice
IdentityFile ~/.ssh/alice_ident
进入
Host foo
Include foo_config
Host bar
Include bar_config
其中~/.ssh/foo_config
和~/.ssh/bar_config
将包含每个主机的相关详细信息.
where ~/.ssh/foo_config
and ~/.ssh/bar_config
would contain the relevant details for each host.
大概,Host
指令仅占7000 + l行的一小部分,因此这应该大大提高_ssh_host
的速度.
Presumably, Host
directives only make up a small fraction of your 7000+l lines, so this should speed up _ssh_host
considerably.
这篇关于大型/.ssh/config文件使用zsh的自动完成速度较慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!