Michael Mior
Michael Mior

Reputation: 28752

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

Upvotes: 1

Views: 528

Answers (1)

Michael Mior
Michael Mior

Reputation: 28752

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

Upvotes: 1

Related Questions