ZSH历史完成菜单

时间:2012-11-28 20:20:36

标签: shell autocomplete zsh

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
   1891年shelajev gvfs-fuse-daemo

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

  

shelajev @ elephant~»kill 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

但这只能完成个别单词,这对我没什么用。有没有办法在历史记录中结合历史搜索并显示其列表?

2 个答案:

答案 0 :(得分:14)

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

然后您需要提供索引号以在历史记录中触发命令。

当然可能会有一些优化。但我想这会让你开始。

希望它有所帮助。

答案 1 :(得分:1)

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

Mike致谢,以将我指向该插件。

相关问题