如何让zsh从历史记录中排除某些命令?
发布时间:2020-12-13 23:01:46 所属栏目:Linux 来源:网络整理
导读:比如那些包含“生产”这个词的那些? 解决方法 function zshaddhistory() { emulate -L zsh if [[ $1 != *"production"* ]] ; then print -sr -- "${1%%$'n'}" fc -p else return 1 fi} 将上面的内容放在交互式shell启动时将来源的文件中(到.zshrc或像我这
比如那些包含“生产”这个词的那些?
解决方法function zshaddhistory() { emulate -L zsh if [[ $1 != *"production"* ]] ; then print -sr -- "${1%%$'n'}" fc -p else return 1 fi } 将上面的内容放在交互式shell启动时将来源的文件中(到.zshrc或像我这样来自.zshrc的文件). 替代形式(隐含的历史补充): function zshaddhistory() { emulate -L zsh if [[ $1 = *"production"* ]] ; then return 1 fi } .注意: print -sr -- "${1%%$'n'}" 显式将项添加到历史记录中但是如果zshaddhistory以零退出代码返回,则zsh隐含地执行zsh,因此如果没有fc -p并且使用setopt nohistignoredups nohistignorealldups(这是默认状态),您将在历史记录中看到不需要的重复项. 模拟-L zsh是为了确保模拟设置不会介入并更改函数体的解释.我把这一行放在我在zsh配置中定义的每个函数的开头. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |