zsh-users
 help / color / mirror / code / Atom feed
* Infinite history size
@ 2013-12-14 10:48 Chris Down
  2013-12-14 11:49 ` ZyX
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Down @ 2013-12-14 10:48 UTC (permalink / raw)
  To: Zsh users

[-- Attachment #1: Type: text/plain, Size: 726 bytes --]

Hello,

I am looking to remove the upper limits on the history size in zsh.

In bash, and some other shells, this can be done by nullfying (note: not
unsetting) HIST{,FILE}SIZE, and then making sure readline's
"history-size" is -1. On zsh, doing the same thing with HISTSIZE and
SAVEHIST results in HISTSIZE becoming 1, and SAVEHIST becoming 0.

Setting an indiscriminately high number is not really appropriate -- I
have years of (uniq'd by last usage) history that I would like to
also import, and even that is fairly substantial:

    $ wc -l .bash_history
    32539 .bash_history

Since I don't have any plans for this size to decrease, using a high
number is probably not a wise idea.

How can I do this in zsh?

Thanks.

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Infinite history size
  2013-12-14 10:48 Infinite history size Chris Down
@ 2013-12-14 11:49 ` ZyX
  2013-12-14 11:53   ` Chris Down
  0 siblings, 1 reply; 5+ messages in thread
From: ZyX @ 2013-12-14 11:49 UTC (permalink / raw)
  To: Chris Down; +Cc: Zsh users

14.12.13, 14:52, "Chris Down" <chris@chrisdown.name>":
> 
> Hello,
> 
> I am looking to remove the upper limits on the history size in zsh.
> 
> In bash, and some other shells, this can be done by nullfying (note: not
> unsetting) HIST{,FILE}SIZE, and then making sure readline's
> "history-size" is -1. On zsh, doing the same thing with HISTSIZE and
> SAVEHIST results in HISTSIZE becoming 1, and SAVEHIST becoming 0.

It is not possible for history to occupy more memory then you have thus if you think there is no upper limit then you are false.

> 
> Setting an indiscriminately high number is not really appropriate -- I
> have years of (uniq'd by last usage) history that I would like to
> also import, and even that is fairly substantial:
> 
>     $ wc -l .bash_history
>     32539 .bash_history
> 
> Since I don't have any plans for this size to decrease, using a high
> number is probably not a wise idea.

You should determine how much memory you have, how much of it you can allow to be occupied by the history (AFAIK it is always fully loaded into memory) and act accordingly. Removing the limit is not wiser as it leaves you with an idea that there is no limit while it is always limited by available resources.

Or if you do not think you will ever hit a problem with resource exhaustion you can just set HISTSIZE to LONG_MAX from limits.h: it is the maximum number HISTSIZE can have.

> 
> 
> How can I do this in zsh?
> 
> Thanks.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Infinite history size
  2013-12-14 11:49 ` ZyX
@ 2013-12-14 11:53   ` Chris Down
  2013-12-15 20:06     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Down @ 2013-12-14 11:53 UTC (permalink / raw)
  To: ZyX; +Cc: Zsh users

[-- Attachment #1: Type: text/plain, Size: 991 bytes --]

On 2013-12-14 15:49:12 +0400, ZyX wrote:
> It is not possible for history to occupy more memory then you have
> thus if you think there is no upper limit then you are false.

While true, any "infinite" related to resource consumption in computer
science has similar restrictions related to the environment, I
considered it an implicit caveat of my request.

> You should determine how much memory you have, how much of it you can
> allow to be occupied by the history (AFAIK it is always fully loaded
> into memory) and act accordingly. Removing the limit is not wiser as
> it leaves you with an idea that there is no limit while it is always
> limited by available resources.
>
> Or if you do not think you will ever hit a problem with resource
> exhaustion you can just set HISTSIZE to LONG_MAX from limits.h: it is
> the maximum number HISTSIZE can have.

So I'll take the answer as "you can't" (although LONG_MAX is obviously
not something that I'm going to reach :-) ).

Thanks anyway.

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Infinite history size
  2013-12-14 11:53   ` Chris Down
@ 2013-12-15 20:06     ` Bart Schaefer
  2013-12-15 20:17       ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2013-12-15 20:06 UTC (permalink / raw)
  To: Zsh users

On Dec 14,  6:48pm, Chris Down wrote:
} 
} In bash, and some other shells, this can be done by nullfying (note: not
} unsetting) HIST{,FILE}SIZE, and then making sure readline's
} "history-size" is -1.

I think what you've found there is a behavior of readline, not especially
a behavior of the shells in question.  Since zsh doesn't use readline, ...

On Dec 14,  7:53pm, Chris Down wrote:
}
} So I'll take the answer as "you can't" (although LONG_MAX is obviously
} not something that I'm going to reach :-) ).

Although setting a very large number is probably the easiest way, you
could do something along these lines:

    SAVEHIST=$(( $(wc -l $HISFILE) * 2 ))
    HISTSIZE=$SAVEHIST
    zshaddhistory() {
      if (( HISTNO == HISTSIZE ));
      then
        (( HISTSIZE *= 2 )) 
	SAVEHIST=$HISTSIZE
      fi
      return 0
    }

I haven't tested that, and obviously it needs some tweaking for cases
where file size actually becomes a significant fraction of LONG_MAX.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Infinite history size
  2013-12-15 20:06     ` Bart Schaefer
@ 2013-12-15 20:17       ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2013-12-15 20:17 UTC (permalink / raw)
  To: Zsh users

On Dec 15, 12:06pm, Bart Schaefer wrote:
>
>     SAVEHIST=$(( $(wc -l $HISFILE) * 2 ))
> 
> I haven't tested that

And plainly so, given the typo for $HISTFILE.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-12-15 20:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-14 10:48 Infinite history size Chris Down
2013-12-14 11:49 ` ZyX
2013-12-14 11:53   ` Chris Down
2013-12-15 20:06     ` Bart Schaefer
2013-12-15 20:17       ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).