shell - ZSH历史完成菜单

标签 shell autocomplete zsh

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

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

shelajev@elephant ~ » kill 1TAB
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
kill -9 12093
kill -15 4123



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

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

我的 .zshrc 中有以下内容:
zle -C hist-complete complete-word _generic
zstyle ':completion:hist-complete:*' completer _history
bindkey "^X^X" hist-complete

但这只是完成了个别单词,并没有给我太多。有没有办法结合历史搜索线路 在历史记录中并显示一个列表?

最佳答案

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

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

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

希望能帮助到你。

关于shell - ZSH历史完成菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13613698/

相关文章:

elasticsearch - 查询 Elasticsearch 基于地址的索引

javascript - 如何为 jquery 自动完成框设置默认值?

rvm - nvm 必须在路径中的 rvm 之前吗?

linux - 时间源 somescript.sh : time not displayed

linux - zsh 替换:(P) 和::= 运算符交互

bash - 使用 grep (在 shell 脚本中)每次匹配仅显示一个文件

android - 如何在Intel App Framework上实现自动完成?

bash - 普罗米修斯:zsh:未找到匹配项:server.remoteWrite[0].url

shell - 如何在搜索中使用 awk 变量?

python - 在 Python 中通过 os.system 在命令行上执行 MySQL 查询