如何让 zsh 从历史记录中排除某些命令?
比如,那些包含“生产”一词的内容?
Like, say, those that include the word "production"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
比如,那些包含“生产”一词的内容?
Like, say, those that include the word "production"?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
明确将项目添加到历史记录中。但是,如果 zshaddhistory 以零退出代码返回,那么 zsh 也会隐式执行相同的操作,因此无需使用 fc -p 并使用 setopt nohistignoredups nohistignorealldups (这是默认状态)您将在历史记录中看到不需要的重复项。
\n'}" fc -p else return 1 fi }emulate -L zsh
在这里是为了确保模拟设置不会介入并更改函数体的解释。我将此行放在我在 zsh 配置中定义的每个函数的开头。将上述内容放入交互式 shell 启动时将获取的文件中(放入
.zshrc
或像我一样从.zshrc
获取的文件)。替代形式(隐式添加到历史记录中):
.注意:
明确将项目添加到历史记录中。但是,如果 zshaddhistory 以零退出代码返回,那么 zsh 也会隐式执行相同的操作,因此无需使用 fc -p 并使用 setopt nohistignoredups nohistignorealldups (这是默认状态)您将在历史记录中看到不需要的重复项。
emulate -L zsh
在这里是为了确保模拟设置不会介入并更改函数体的解释。我将此行放在我在 zsh 配置中定义的每个函数的开头。explicitly adds item to history. But the same thing implicitly does zsh if
zshaddhistory
returns with zero exit code, so withoutfc -p
and withsetopt nohistignoredups nohistignorealldups
(which is the default state) you will see unneeded duplicates in history.
\n'}" fc -p else return 1 fi }emulate -L zsh
is here to make sure that emulation settings does not step in and change the interpretation of the function body. I put this line at the start of the every function I define in zsh configuration.Put the above to a file that will be sourced when interactive shell starts (to
.zshrc
or to a file that is sourced from.zshrc
like I do).Alternate form (implicit addition to history):
. Note:
explicitly adds item to history. But the same thing implicitly does zsh if
zshaddhistory
returns with zero exit code, so withoutfc -p
and withsetopt nohistignoredups nohistignorealldups
(which is the default state) you will see unneeded duplicates in history.emulate -L zsh
is here to make sure that emulation settings does not step in and change the interpretation of the function body. I put this line at the start of the every function I define in zsh configuration.