I have following answer for How to remove a single line from history?. When I do following, the line ( echo hello_world
) is not saved into history. Please note that I am using zsh
shell.
prompt$ echo hello_world
> # ^ extra space
$ history | tail -n1
1280 history | tail -n
$ echo hello_world
hello_world
$ history | tail -n1
1280 history | tail -n
But when I do run a command having a space at the beginning and right after do Ctrl+P, I can see it on the shell history, even though it is not save in history
. Is it possible to prevent it? With the bash
shell, this works when setting HISTCONTROL= ignorespace
.
$ echo hello_world
$ # Press `CTRL-p` => " echo hello_world" shows up again
Setup: I have following configuration for the
zsh
shell:
## Save only one command if 2 common are same and consistent
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_ALL_DUPS
Delete empty lines from history file
setopt HIST_REDUCE_BLANKS
Ignore a record starting with a space
setopt HIST_IGNORE_SPACE
Do not add history and fc commands to the history
setopt HIST_NO_STORE
Add timestamp for each entry
setopt EXTENDED_HISTORY
head -n1
? The last command should be the last line ofhistory
not the first line. – Raphael Ahrens Jul 16 '20 at 09:14fc -rl - 0
in order to reverse the output. For clarity I replacedhead -n1
withtail -n1
@RaphaelAhrens – alper Jul 16 '20 at 09:47$HISTCONTROL
variable? (referred to in the Accepted answer https://unix.stackexchange.com/a/49216/117549) – Jeff Schaller Jul 16 '20 at 13:37ignoredups:erasedups:ignorespace
I have also addedignoredups:erasedups
– alper Jul 16 '20 at 13:41HISTCONTROL=ignorespace
, I get the behavior I think you're looking for: entering a command prefixed with a space, then recalling the previous command skips that command. – Jeff Schaller Jul 16 '20 at 16:07zsh
! – Jeff Schaller Jul 16 '20 at 17:34bash
and it works but it does not onzsh
– alper Jul 16 '20 at 17:37bash
than right? @KGII – alper Aug 01 '20 at 10:04ohmyzsh/ohmyzsh
github page since I couldn't find github page forzsh
@KGIII – alper Aug 01 '20 at 19:28ohmyzsh
: (https://github.com/ohmyzsh/ohmyzsh/issues/9149) – alper Aug 01 '20 at 19:47