17

Zsh 自动完成功能很棒,但我无法正确配置一件事:我希望 zsh 为我提供历史命令列表。

我知道我可以用Ctrl+搜索历史R,但我想要一些不同的东西。当我输入:

shelajev@elephant ~ » kill 1 TAB
1642 shelajev gnome-keyring-d
1718 shelajev gnome-session
1807 shelajev ssh-agent
1810 shelajev dbus-launch
1811 shelajev dbus-daemon
1822 shelajev gnome-settings-
1884 shelajev gvfsd
18daemofs-fuse-

Zsh 为我提供了要杀死的进程列表。我想要这样的东西:

shelajev@elephant ~ » 杀Ctrl+ X Ctrl+X
杀 -9 12093
杀 -15 4123

列表中的这些项目取自我的历史记录。

存在一个 ZLE hist-complete 的东西,但我不知道如何正确配置它。

我有以下内容.zshrc

zle -C hist-complete complete-word _generic
zstyle ':completion:hist-complete:*' completer _history
bindkey "^X^X" hist-complete

但这只是完成个别单词,这并没有给我太多。有没有办法结合历史搜索历史中的并显示其列表?

4

4 回答 4

17

zsh 中有一个东西叫做history-beginning-search-menu. 如果你把:

autoload -Uz history-beginning-search-menu
zle -N history-beginning-search-menu
bindkey '^X^X' history-beginning-search-menu

在您的 .zshrc 文件中。然后例如:

kent$  sudo systemctl[here I type C-X twice]
Enter digits:
01 sudo systemctl acpid.service                      11 sudo systemctl enable netfs
02 sudo systemctl enable acpid                       12 sudo systemctl enable networkmanager
03 sudo systemctl enable alsa                        13 sudo systemctl enable NetworkManager
04 sudo systemctl enable alsa-restore                14 sudo systemctl enable NetworkManager-wait-online
05 sudo systemctl enable alsa-store                  15 sudo systemctl enable ntpd
06 sudo systemctl enable cronie                      16 sudo systemctl enable sshd
07 sudo systemctl enable cups                        17 sudo systemctl enable syslog-ng
08 sudo systemctl enable dbus                        18 sudo systemctl enable tpfand
09 sudo systemctl enable gdm                         19 sudo systemctl reload gdm.service
10 sudo systemctl enable hal                         20 sudo systemctl restart gdm.service

那么你需要给出索引号来触发历史中的命令。

当然可以对此进行一些优化。但我认为这会让你开始。

希望能帮助到你。

于 2012-11-28T21:33:39.387 回答
5

我的插件zsh-autocomplete现在包括一个适当的历史菜单,以及实时多行历史搜索。试试看,让我知道你的想法!

实时历史搜索

具有多选功能的历史菜单

于 2020-12-26T22:20:17.257 回答
0

几年过去了,现在有一个名为zsh-navigation-tools的插件。它并不完全符合您的要求,但也许您或其他人可能会发现它有帮助。但是,应该注意的是,它用全屏应用程序替换了默认的 bck-i-search ( CTRL+ R)。

感谢Mike将我指向这个插件。

于 2018-11-01T14:34:00.367 回答
0

如果您只想在当前行中自动完成顶部匹配(如鱼壳),请尝试zsh-autosuggestions。当您键入类似于历史命令的命令时,它会建议以浅灰色文本完成。您可以按 → 接受完成。

zsh-自动建议

于 2022-02-16T22:19:28.183 回答