【问题标题】:Avoid adding zsh command to history避免将 zsh 命令添加到历史记录
【发布时间】:2016-03-07 19:15:59
【问题描述】:

我使用以下绑定允许我按 Control-Z 来恢复我以前后台运行的程序。我设置了histoptignorespace 并在fg 前面放置了一个空格,这样该命令就不会保留在我的历史记录中。

但是,当我按向上箭头时,它仍然出现。有什么方法可以删除它吗?我想按向上箭头忽略 fg 曾经输入过的事实。

# Allow Ctrl-z to toggle between suspend and resume                             
function Resume {                                                               
  zle push-input                                                                   
  BUFFER=" fg"                                                                     
  zle accept-line                                                                  
}                                                                                  
zle -N Resume                                                                                                                                                  
bindkey "^Z" Resume

【问题讨论】:

  • 我不认为这是可能的,唉。 “向上历史”实际上只是重播您输入的内容。
  • @ChrisKitching 我认为你基本上是对的,尽管事实证明直接运行fg 然后接受一个空行可以解决我的问题:)

标签: zsh zsh-zle


【解决方案1】:

以下内容对我有用。它实际上只是直接运行fg。剩下的就是返回提示所必需的。

# Allow Ctrl-z to toggle between suspend and resume
function Resume {
  fg
  zle push-input
  BUFFER=""
  zle accept-line
}
zle -N Resume
bindkey "^Z" Resume

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-12
    • 2012-12-11
    • 2016-05-07
    • 2015-07-26
    • 2011-02-18
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    相关资源
    最近更新 更多