如何让 zsh 从历史记录中排除某些命令?

发布于 2024-11-27 13:25:33 字数 24 浏览 5 评论 0原文

比如,那些包含“生产”一词的内容?

Like, say, those that include the word "production"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唱一曲作罢 2024-12-04 13:25:33
function zshaddhistory() {
    emulate -L zsh
    if [[ $1 != *"production"* ]] ; then
        print -sr -- "${1%%

将上述内容放入交互式 shell 启动时将获取的文件中(放入 .zshrc 或像我一样从 .zshrc 获取的文件)。

替代形式(隐式添加到历史记录中):

function zshaddhistory() {
    emulate -L zsh
    if [[ $1 = *"production"* ]] ; then
        return 1
    fi
}

.注意:

print -sr -- "${1%%

明确将项目添加到历史记录中。但是,如果 zshaddhistory 以零退出代码返回,那么 zsh 也会隐式执行相同的操作,因此无需使用 fc -p 并使用 setopt nohistignoredups nohistignorealldups (这是默认状态)您将在历史记录中看到不需要的重复项。

emulate -L zsh 在这里是为了确保模拟设置不会介入并更改函数体的解释。我将此行放在我在 zsh 配置中定义的每个函数的开头。

\n'}" fc -p else return 1 fi }

将上述内容放入交互式 shell 启动时将获取的文件中(放入 .zshrc 或像我一样从 .zshrc 获取的文件)。

替代形式(隐式添加到历史记录中):


.注意:


明确将项目添加到历史记录中。但是,如果 zshaddhistory 以零退出代码返回,那么 zsh 也会隐式执行相同的操作,因此无需使用 fc -p 并使用 setopt nohistignoredups nohistignorealldups (这是默认状态)您将在历史记录中看到不需要的重复项。

emulate -L zsh 在这里是为了确保模拟设置不会介入并更改函数体的解释。我将此行放在我在 zsh 配置中定义的每个函数的开头。

\n'}"

明确将项目添加到历史记录中。但是,如果 zshaddhistory 以零退出代码返回,那么 zsh 也会隐式执行相同的操作,因此无需使用 fc -p 并使用 setopt nohistignoredups nohistignorealldups (这是默认状态)您将在历史记录中看到不需要的重复项。

emulate -L zsh 在这里是为了确保模拟设置不会介入并更改函数体的解释。我将此行放在我在 zsh 配置中定义的每个函数的开头。

\n'}" fc -p else return 1 fi }

将上述内容放入交互式 shell 启动时将获取的文件中(放入 .zshrc 或像我一样从 .zshrc 获取的文件)。

替代形式(隐式添加到历史记录中):

.注意:

明确将项目添加到历史记录中。但是,如果 zshaddhistory 以零退出代码返回,那么 zsh 也会隐式执行相同的操作,因此无需使用 fc -p 并使用 setopt nohistignoredups nohistignorealldups (这是默认状态)您将在历史记录中看到不需要的重复项。

emulate -L zsh 在这里是为了确保模拟设置不会介入并更改函数体的解释。我将此行放在我在 zsh 配置中定义的每个函数的开头。

function zshaddhistory() {
    emulate -L zsh
    if [[ $1 != *"production"* ]] ; then
        print -sr -- "${1%%

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):

function zshaddhistory() {
    emulate -L zsh
    if [[ $1 = *"production"* ]] ; then
        return 1
    fi
}

. Note:

print -sr -- "${1%%

explicitly adds item to history. But the same thing implicitly does zsh if zshaddhistory returns with zero exit code, so without fc -p and with setopt 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.

\n'}" fc -p else return 1 fi }

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 without fc -p and with setopt 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.

\n'}"

explicitly adds item to history. But the same thing implicitly does zsh if zshaddhistory returns with zero exit code, so without fc -p and with setopt 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.

\n'}" fc -p else return 1 fi }

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 without fc -p and with setopt 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文