4

比如说,那些包含“生产”这个词的?

4

1 回答 1

6
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'}"

显式地将项目添加到历史记录。但是同样的事情隐式地执行 zsh ifzshaddhistory返回零退出代码,因此没有fc -p和使用setopt nohistignoredups nohistignorealldups(这是默认状态)您将在历史记录中看到不需要的重复项。

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

于 2011-08-04T04:44:59.127 回答