Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view default zsh settings (HISTSIZE, SAVEHIST, ...)

How do I see the current values for all the zsh settings?

e.g., I don't currently have HISTSIZE and SAVEHIST set, so env | grep HIST and set | grep HIST show nothing. So then how can I see what default values are being used?

like image 715
Rob Bednark Avatar asked Aug 11 '12 20:08

Rob Bednark


2 Answers

There is no option to get the default value for an undefined variable except parsing documentation or source code.

HISTSIZE and SAVEHIST are not settings, they are special variables. There is a way to list all variables, but I know of no way to list those that are special and are used as settings.

To help you list parameters implemented as variables, there is the zsh/parameter module (zmodload zsh/parameter to load it). It has an associative array $parameters where keys are variable names and values are variable type descriptions. Both HISTSIZE and SAVEHIST appear there as integer-special. HISTCHARS appears there as scalar-special. Note though that RANDOM appears here just as HISTSIZE: integer-special, so you can’t use this to get special variables used as options. But you can always use the PARAMETERS USED BY THE SHELL section of man zshparam.

I don't know of any option that will allow you to determine default values of those parameters, except parsing documentation or source code.

# setopt | grep hist
nobanghist
extendedhistory
histfcntllock
histignorealldups
histignorespace
histnostore
histreduceblanks
histsavenodups
histverify
incappendhistory

If you want to see non-default settings:

If no arguments are supplied, the names of all options currently set are printed. The form is chosen so as to minimize the differences from the default options for the current emulation (the default emulation being native zsh, shown as in zshoptions(1)). Options that are on by default for the emulation are shown with the prefix no only if they are off, while other options are shown without the prefix no and only if they are on. In addition to options changed from the default state by the user, any options activated automatically by the shell (for example, SHIN_STDIN or INTERACTIVE) will be shown in the list. The format is further modified by the option KSH_OPTION_PRINT, however the rationale for choosing options with or without the no prefix remains the same in this case.

It also makes sense to use:

# unsetopt | grep hist
noappendhistory
cshjunkiehistory
histallowclobber
nohistbeep
histexpiredupsfirst
histfindnodups
histignoredups
histlexwords
histnofunctions
nohistsavebycopy
histsubstpattern
sharehistory

If no arguments are supplied, the names of all options currently unset are printed.

Or just follow the help and use

# setopt kshoptionprint
# setopt | grep hist
noappendhistory       off
nobanghist            on
cshjunkiehistory      off
extendedhistory       on
histallowclobber      off
nohistbeep            off
histexpiredupsfirst   off
histfcntllock         on
histfindnodups        off
histignorealldups     on
histignoredups        off
histignorespace       on
histlexwords          off
histnofunctions       off
histnostore           on
histreduceblanks      on
nohistsavebycopy      off
histsavenodups        on
histsubstpattern      off
histverify            on
incappendhistory      on
sharehistory          off

Note that the output of setopt and unsetopt match when the kshoptionprint option is used.

like image 196
ZyX Avatar answered Oct 17 '22 14:10

ZyX


To show the current value, whether you have set it or not (in which case it shows the default value):

➜  ~ echo $SAVEHIST
10000
➜  ~ echo $HISTSIZE 
10000
like image 28
becko Avatar answered Oct 17 '22 16:10

becko