问题 ZSH历史完成菜单


Zsh自动完成是惊人的,但我无法正确配置一件事: 我希望zsh能够提供历史命令列表。

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

shelajev @ elephant~»杀死1标签
   1642年shelajev gnome-keyring-d
   1718年谢拉耶夫侏儒会议
   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~»杀 按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

但这只能完成单个单词,这对我没有多大帮助。有没有办法结合历史搜索 线 在历史上并展示了那个?


8631
2017-11-28 20:20


起源



答案:


在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

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

当然可以有一些优化。但我认为这会让你开始。

希望能帮助到你。


14
2017-11-28 21:33



谢谢,这完全按照你的说法工作。这是一个很好的起点!我只是想知道是否有办法用类似的东西来增强它 菜单选择。 - Oleg Šelajev
我也在寻找潜在的菜单选择+数字选择组合。 @OlegŠelajev你找到了吗? - Mikko Ohtamaa
没找到任何东西,但我没有深入研究。 - Oleg Šelajev


答案:


在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

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

当然可以有一些优化。但我认为这会让你开始。

希望能帮助到你。


14
2017-11-28 21:33



谢谢,这完全按照你的说法工作。这是一个很好的起点!我只是想知道是否有办法用类似的东西来增强它 菜单选择。 - Oleg Šelajev
我也在寻找潜在的菜单选择+数字选择组合。 @OlegŠelajev你找到了吗? - Mikko Ohtamaa
没找到任何东西,但我没有深入研究。 - Oleg Šelajev