Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用模式历史搜索,但在较旧的zsh版本中,可以优雅地降级为非模式历史搜索_Zsh - Fatal编程技术网

使用模式历史搜索,但在较旧的zsh版本中,可以优雅地降级为非模式历史搜索

使用模式历史搜索,但在较旧的zsh版本中,可以优雅地降级为非模式历史搜索,zsh,Zsh,我将我的一些点文件保存在版本控制中,这样我就可以在我们工作的众多服务器上改进我的环境。当然,这包括我的.zshrc 我刚刚了解到如何将ctrl-R绑定到Histry incremental pattern search backward,以便在历史记录中进行模式搜索,它非常有用,所以我将它放在了.zshrc中,并一直在高兴地将其部署到任何地方 问题是我们的一些服务器安装了zsh版本4.2.6,但它没有此功能;在这些服务器上,ctrl-R现在只是一种非常有效的方式,可以打印而不需要这样的小部件“历

我将我的一些点文件保存在版本控制中,这样我就可以在我们工作的众多服务器上改进我的环境。当然,这包括我的.zshrc

我刚刚了解到如何将ctrl-R绑定到
Histry incremental pattern search backward
,以便在历史记录中进行模式搜索,它非常有用,所以我将它放在了.zshrc中,并一直在高兴地将其部署到任何地方

问题是我们的一些服务器安装了zsh版本4.2.6,但它没有此功能;在这些服务器上,ctrl-R现在只是一种非常有效的方式,可以打印
而不需要这样的小部件“历史增量模式向后搜索”

因此,我需要在.zshrc中提供一些东西,以便在可用的地方进行模式历史搜索,而在不可用的地方只进行历史搜索;要么只是有条件地重新绑定密钥,要么将其绑定到任何一种方式都有效的对象

我可以使用
is至少
来测试zsh版本,如果我可以确定支持
历史增量模式向后搜索的最早版本,但如果可能的话,我宁愿更直接地测试(类似于功能检测背后的逻辑,而不是Javascript中的浏览器/版本检测)

我发现
zle-l
给了我一个定义的小部件列表,但显然只有用户定义的小部件。我还没有找到任何其他方法来测试小部件是否被定义


如果您有任何建议(或明确知道唯一的方法是版本号测试),我们将不胜感激。

您非常接近正确答案,但您忘记了RTFM;-)手册中描述zle的章节说明:

-l [ -L | -a ]
      List all existing user-defined widgets.  If the -L option is
      used, list in the form of zle commands to create the widgets.

      When combined with the -a option, all widget names are listed,
      including the builtin ones. In this case the -L option is
      ignored.
果然:

$ zle -al | grep history-incremental-pattern-search-backward 
.history-incremental-pattern-search-backward
history-incremental-pattern-search-backward
因此,您正在寻找的测试是:

zle -al | grep -q history-incremental-pattern-search-backward

Drat,我不确定我是怎么错过的,因为这正是我最初找到
zle
命令的原因。:)