zshzsh-zle

Avoid adding zsh command to history


I use the following binding to allow me to press Control-Z to resume a program I previously backgrounded. I set histoptignorespace and put a space in front of fg so the command doesn't persist in my history.

However, it still appears when I press the up arrow. Any way to remove this as well? I would like pressing the up arrow to ignore the fact that fg was ever entered.

# 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

Solution

  • The following worked for me. It really just runs fg directly. The rest is necessary to get back to the prompt.

    # 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