Disable Zsh history completely
Asked Answered
B

3

5

I would like to disable Zsh history (arrow up) and zle history search (namely esc+p) completely. How can I achieve this?

My current .zshrc:

unsetopt hist_append
unsetopt hist_expand
HISTFILE=
HISTSIZE=SAVEHIST=0

Currently I have history buffer of one, but I'd like to have history of zero.

21-10-2016 Update:

I've added

bindkey -r "^[p"
bindkey -r "^Xr"
bindkey -r "^Xs"
bindkey -r "^[[A"
bindkey -r "^[[B"
bindkey -r "^[n"

to get rid of history features that I use (esc+p is deeply hardwired to my backbone - so difficult to unlearn).

Brandenburg answered 20/10, 2016 at 16:44 Comment(7)
Unrelated, but I'm pretty sure this construct HISTSIZE=SAVEHIST=0 does not work.Brogan
I think it does, however HISTSIZE cannot be set to zero for some reason. % HISTSIZE=SAVEHIST=4 % echo $HISTSIZE $SAVEHIST 4 4 % HISTSIZE=0 % echo $HISTSIZE $SAVEHIST 1 4 % HISTSIZE=SAVEHIST=0 % echo $HISTSIZE $SAVEHIST 1 0Brandenburg
Hm. Today I learned.Brogan
Yeah me too! :)Brandenburg
I think chained assignment like this only works for parameters using an integer representation internally (i.e., typeset -i).Serpentine
I'm not sure what your point is: % HISTSIZE=0 % typeset -i|grep HISTSIZE HISTSIZE=1Brandenburg
His point is that for a normal shell variable, A=B=5 puts the value B=5 into the variable A. But if you mark the variable as specifically "integers only", than A=B=5 will put the value 5 into both variables A and B. This trick doesn't work for all variables, only for variables that are specifically "integer only". It's not an answer to your original question. It's continuing the discussion on chained variable assignment.Brogan
B
2

I don't see anything in the zsh man page that completely disables history. Even setting HISTSIZE=0 seems to reset the value of HISTSIZE to 1.

You'll probably have better luck changing the key bindings with bindkey so that history features never occur. For example, bindkey -r "^[[A" for my up-arrow key (note that I actually typed a caret and two brackets, not an escape key).

Brogan answered 20/10, 2016 at 17:0 Comment(0)
C
8

I use following entries in my .zshrc:

alias disablehistory="function zshaddhistory() {  return 1 }"

If function zshaddhistory is defined, it can control whether history line will be saved.

Therefore, alias disablehistory will just define function that always returns 1 (don't save).

alias disablehistory="function zshaddhistory() {  return 1 }"
alias enablehistory="unset -f zshaddhistory"

enablehistory just unsets function set by previous alias.

If you want to disable history completely, permanently define zshaddhistory in your .zshrc

Chkalov answered 6/8, 2021 at 9:24 Comment(0)
B
2

I don't see anything in the zsh man page that completely disables history. Even setting HISTSIZE=0 seems to reset the value of HISTSIZE to 1.

You'll probably have better luck changing the key bindings with bindkey so that history features never occur. For example, bindkey -r "^[[A" for my up-arrow key (note that I actually typed a caret and two brackets, not an escape key).

Brogan answered 20/10, 2016 at 17:0 Comment(0)
E
0

Try configuring your ZSH setup to run a postexec function that empties/deletes your .zhistory file. It's a hacky workaround but should probably work.

Enthusiastic answered 20/10, 2016 at 17:7 Comment(1)
Currently HISTFILE="" I've also tried HISTFILE="/dev/null" with no luck. No hacks around here!Brandenburg

© 2022 - 2024 — McMap. All rights reserved.