Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HISTIGNORE not working in zsh

I have added

export HISTIGNORE="ls:cd:pwd:exit:cd .."

to my .zshrc file.

Deleted .zsh_history and restarted terminal but it still wont ignore those commands.

enter image description here

like image 590
tgreen Avatar asked Jul 24 '16 06:07

tgreen


1 Answers

The zsh shell doesn't use the HISTIGNORE environment variable. Instead, it has a HISTORY_IGNORE environment variable.

From the zshparam manual:

HISTORY_IGNORE

If set, is treated as a pattern at the time history files are written. Any potential history entry that matches the pattern is skipped. For example, if the value is fc * then commands that invoke the interactive history editor are never written to the history file.

Note that HISTORY_IGNORE defines a single pattern: to specify alternatives use the (first|second|...) syntax.

So in your case, you would want to do

HISTORY_IGNORE="(ls|cd|pwd|exit|cd ..)"

or something similar.

Notice that this affects only history written to the history file, not the history in the currently active shell session, as far as I can see.

like image 142
Kusalananda Avatar answered Dec 22 '22 09:12

Kusalananda