Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Memory usage of history?
- X-seq: zsh-workers 38762
- From: Christian Neukirchen <chneukirchen@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Memory usage of history?
- Date: Sat, 25 Jun 2016 19:43:48 +0200
- In-reply-to: <CAH+w=7YQz6iaJf0k=OkX2bQSL26ohU3wLRVYgki_Z6jLOYpzSw__6555.25048864565$1466819341$gmane$org@mail.gmail.com> (Bart Schaefer's message of "Fri, 24 Jun 2016 18:47:47 -0700")
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20160624134706.GA22704@linux.vnet.ibm.com> <CAH+w=7YQz6iaJf0k=OkX2bQSL26ohU3wLRVYgki_Z6jLOYpzSw__6555.25048864565$1466819341$gmane$org@mail.gmail.com>
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:
> On Fri, Jun 24, 2016 at 6:47 AM, Dominik Vogt <vogt@xxxxxxxxxxxxxxxxxx> wrote:
>>
>> (A colleague
>> says his zshs use 200 MB memory each with a history size of a
>> million lines).
>
> To expand on Eric's answer, zsh reads the entire $HISTFILE and retains
> the last $HISTSIZE entries. So a large $HISTFILE also slows down
> startup, even if it doesn't consume lots of memory.
>
> I can't imagine anyone having a million useful lines of history. A
> few tens of thousands at most.
I use the following functions to create an additional, write-only,
daily history, and a helper to search it:
# Keep an archive of all commands typed.
# Initialize using:
# cat /data/dump/juno/2015<->/home/chris/.zsh_history | sort -u | grep '^:' |
# gawk -F: '{print $0 >> "chris@juno-" strftime("%Y-%m-%d", $2)}'
# 04sep2015 +chris+
mkdir -p ~/.zarchive
zshaddhistory() {
local words=( ${(z)1} )
local w1=$words[1]
(( $+aliases[$w1] )) && w1=$aliases[$w1]
if [[ -n $1 && $1 != $'\n' && $w1 != " "* ]]; then
printf ': %s:0;%s' ${(%):-%D{%s}} "$1" >> \
~/.zarchive/${(%):-%n@%m-%D{%Y-%m-%d}}
fi
}
# za WORDS... - search .zarchive for WORDS
za() {
grep -a -r -e "${(j:.*:)@}" ~/.zarchive |
sed 's/[ \t]*$//' |
sort -r | sort -t';' -k2 -u | sort |
sed $'s,^[^:]*/,,; s,::[^;]*;,\u00A0\u00A0,'
}
alias za=' za'
--
Christian Neukirchen <chneukirchen@xxxxxxxxx> http://chneukirchen.org
Messages sorted by:
Reverse Date,
Date,
Thread,
Author