Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On 3/26/15 8:28 PM, Christoph Anton Mitterer wrote: > So why not make a thrid mode like: > - if cmdhist=on lithist=not-in-file > which keeps: > if true; then\n > echo foo\n > fi > in the history > but writes the serialised "if true; then echo foo ; fi" to the history > file. Because there are a number of keywords and metacharacters that can be followed by a newline but not a semicolon (e.g. `while'). There's just not a one-for-one correspondence. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On Thu, 2015-03-26 at 16:54 -0400, Chet Ramey wrote: > The solution cannot be bash-specific; the history library is used by many > other applications. One, design-wise ugly, idea: Couldn't you abuse the history comment char another time for that? Like consider anything between a ^#[[:digit:]] to be part of one command: With HISTTIMEFORMAT set that could look like: #1427416260 echo foo #1427416363 if true; then echo bar fi #1427416625 ./and_so_on If HISTTIMEFORMAT is not set, you could simply write 0 #0 echo foo #0 if true; then echo bar fi #0 ./and_so_on AFAICS, this wouldn't break compatibility - anything that matches ^#[[:digit:]] is already now not stored in the history files, AFAICS - of course one would probably need to clear the history when one enables the shopt for using the above schema (or otherwise one could see extremely big multiline commands) Or one may just start with that way of parsing the file, the first time a ^#[[:digit:]] is encountered, and anything before is considered to be single commands per line. Cheers, Chris.
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On Thu, 2015-03-26 at 15:21 -0400, Chet Ramey wrote: > What do you mean "ignore its effect"? You have newlines embedded in > history entries; what do you plan to do about them? Well that was just the uneducated idea based on blind assumptions by *not* having read the code O:-) AFAIU, both already works: - if cmdhist=on lithist=off => we get the "if true; then echo foo ; fi" layout for both history and history file + in both cases each command stays "one command". - if cmdhist=on lithist=on => we get the layout with embedded newlines in the history (with each command staying "one command"), but in the history file it "breaks" and the multiline command is split up in several commands Right? So why not make a thrid mode like: - if cmdhist=on lithist=not-in-file which keeps: if true; then\n echo foo\n fi in the history but writes the serialised "if true; then echo foo ; fi" to the history file. Of course on re-loading the history it would again be the form without \n, but better having the serialised form than mutliple commands. And it would then at least work for the current command history Cheers, Chris.
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On Thu, 2015-03-26 at 16:26 -0400, Chet Ramey wrote: > > And b) it seems kinda ugly that one needs to explicitly set a default > > value that would be set later anyway. > Maybe. Okay, keep me tuned if you should plan to actually do that, cause then I can revise manually setting it :) > It is what it is, and it's an effective workaround that you can > use today. Sure, thanks for that,... > > Wasn't it possible to simply set the default for histchars earlier in > > the startup? > histchars defaulting is part of the interactive shell setup; environment > variables are scanned before any other setup so they are available when > the startup files are read. The interactive shell startup comes after > the startup files are read so the startup files can set any appropriate > variables. One other possibility would be, if HISTTIMEFORMAT is set and histchars is not, while you read in the .bash_history, assume only there the default of "#" and ignore these lines. That way would probably not change the behaviour a lot. Cheers, Chris.
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 3/26/15 4:51 PM, Eric Blake wrote: > On 03/26/2015 01:21 PM, Chet Ramey wrote: >> >> What do you mean "ignore its effect"? You have newlines embedded >> in history entries; what do you plan to do about them? > > Can't history lines be recorded as $'...\n...' so as to be one line > per command, even when the command contained newlines? The solution cannot be bash-specific; the history library is used by many other applications. - -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/ -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (Darwin) iEYEARECAAYFAlUUcf4ACgkQu1hp8GTqdKv/IQCfaR9tppTwWZlP2ElGv2oGYWdY j9cAnjOmU1rs5N+Jljc80aH0++qQdYRD =h0EB -END PGP SIGNATURE-
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On 03/26/2015 01:21 PM, Chet Ramey wrote: > > What do you mean "ignore its effect"? You have newlines embedded in > history entries; what do you plan to do about them? Can't history lines be recorded as $'...\n...' so as to be one line per command, even when the command contained newlines? -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On 3/25/15 8:06 PM, Christoph Anton Mitterer wrote: > On Wed, 2015-03-25 at 16:19 -0400, Chet Ramey wrote: >> When you start bash, and source your .bashrc, the history comment character >> is not set. You haven't set it in .bashrc, I assume > Yes, I haven't. > >> Since that's not set, the lines beginning with >> `#[digit]' are not recognized as timestamps and treated as ordinary history >> entries. >> You can fix this by assigning to histchars before setting HISTFILESIZE: >> histchars='!^#' > Okay that works in principle. > > But a) this means truncation of the history file happens immediately > each the HISTFILESIZE is set and not just when the shell quits, right? Yes. > And b) it seems kinda ugly that one needs to explicitly set a default > value that would be set later anyway. Maybe. It is what it is, and it's an effective workaround that you can use today. > Wasn't it possible to simply set the default for histchars earlier in > the startup? histchars defaulting is part of the interactive shell setup; environment variables are scanned before any other setup so they are available when the startup files are read. The interactive shell startup comes after the startup files are read so the startup files can set any appropriate variables. > Apart from that, it's not really directly obvious that histchars also > affects the history itself and not just history expansion. > E.g. it's normally not even set in my shell environment (not even the > default value). You get the default values. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On 3/25/15 6:03 PM, Christoph Anton Mitterer wrote: > On Wed, 2015-03-25 at 16:21 -0400, Chet Ramey wrote: >> https://lists.gnu.org/archive/html/bug-bash/2011-02/msg00042.html > Maybe I've missed something but that thread basically just discussed the > same issue without giving a solution, right? It's intended to illustrate that the issue is complex and that solutions are not simple. > I understand you concerns about any format changes, that's why my idea > was to allow "lithist" set but ignore it's effect when the history file > is written... wouldn't that work out? What do you mean "ignore its effect"? You have newlines embedded in history entries; what do you plan to do about them? -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On Wed, 2015-03-25 at 16:19 -0400, Chet Ramey wrote: > When you start bash, and source your .bashrc, the history comment character > is not set. You haven't set it in .bashrc, I assume Yes, I haven't. > Since that's not set, the lines beginning with > `#[digit]' are not recognized as timestamps and treated as ordinary history > entries. > You can fix this by assigning to histchars before setting HISTFILESIZE: > histchars='!^#' Okay that works in principle. But a) this means truncation of the history file happens immediately each the HISTFILESIZE is set and not just when the shell quits, right? And b) it seems kinda ugly that one needs to explicitly set a default value that would be set later anyway. Wasn't it possible to simply set the default for histchars earlier in the startup? If someone wants to set histchars he'd have to do it anyway, and for those who want to stick with the defaults, this would solve the above issue. Apart from that, it's not really directly obvious that histchars also affects the history itself and not just history expansion. E.g. it's normally not even set in my shell environment (not even the default value). Thanks, Chris.
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On Wed, 2015-03-25 at 16:21 -0400, Chet Ramey wrote: > https://lists.gnu.org/archive/html/bug-bash/2011-02/msg00042.html Maybe I've missed something but that thread basically just discussed the same issue without giving a solution, right? I understand you concerns about any format changes, that's why my idea was to allow "lithist" set but ignore it's effect when the history file is written... wouldn't that work out? Cheers, Chris.
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On 3/25/15 3:50 PM, Christoph Anton Mitterer wrote: > There is the lithist thingy, to preserve newlines in commands which I'd > quite like. > But it doesn't work obviously when [re-]storing [from/]to the history > file. > > Would it be possible to have e.g. another option, so that things work > like lithist=on for the session history, but like lithist=of (i.e. ";" > added where possible) when storing to the history file? https://lists.gnu.org/archive/html/bug-bash/2011-02/msg00042.html The thread starts with https://lists.gnu.org/archive/html/bug-bash/2011-02/msg00025.html -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On 3/25/15 3:02 PM, Christoph Anton Mitterer wrote: > On Wed, 2015-03-25 at 14:48 -0400, Chet Ramey wrote: >> The history file truncation code already skips lines that look like history >> timestamps. Look at history.c:history_truncate_file(). > Ah? Hmm was that only recently introduced? > I'm having bash4.3 with patches up to including 33. And this time I > looked whether Debian added any of it's goodness ;-) > > > When I set e.g. in .bashrc: > HISTSIZE=50 > HISTFILESIZE=50 > HISTTIMEFORMAT=$'%c\t' Here's what happens. The history timestamp code depends on the setting of the history `comment character' -- that's the `#' that it uses to denote the start of a timestamp entry. The history comment character disables history expansion for every subsequent character on a line. When you start bash, and source your .bashrc, the history comment character is not set. You haven't set it in .bashrc, I assume, and it doesn't acquire its default value until later on in the interactive shell initialization process. Since that's not set, the lines beginning with `#[digit]' are not recognized as timestamps and treated as ordinary history entries. You can fix this by assigning to histchars before setting HISTFILESIZE: histchars='!^#' Those are the defaults. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On Wed, 2015-03-25 at 15:09 -0400, Chet Ramey wrote: > > I'm having bash4.3 with patches up to including 33. And this time I > > looked whether Debian added any of it's goodness ;-) > I'll take a look. Thanks :) Speaking of feature-requests and history... There is the lithist thingy, to preserve newlines in commands which I'd quite like. But it doesn't work obviously when [re-]storing [from/]to the history file. Would it be possible to have e.g. another option, so that things work like lithist=on for the session history, but like lithist=of (i.e. ";" added where possible) when storing to the history file? Cheers, Chris.
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On 3/25/15 3:02 PM, Christoph Anton Mitterer wrote: > On Wed, 2015-03-25 at 14:48 -0400, Chet Ramey wrote: >> The history file truncation code already skips lines that look like history >> timestamps. Look at history.c:history_truncate_file(). > Ah? Hmm was that only recently introduced? Bash-3.0. > I'm having bash4.3 with patches up to including 33. And this time I > looked whether Debian added any of it's goodness ;-) I'll take a look. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On Wed, 2015-03-25 at 14:48 -0400, Chet Ramey wrote: > The history file truncation code already skips lines that look like history > timestamps. Look at history.c:history_truncate_file(). Ah? Hmm was that only recently introduced? I'm having bash4.3 with patches up to including 33. And this time I looked whether Debian added any of it's goodness ;-) When I set e.g. in .bashrc: HISTSIZE=50 HISTFILESIZE=50 HISTTIMEFORMAT=$'%c\t' Then: $ rm .bash_history $ history -c Then start a new shell and then enter commands $ echo 1 $ echo 2 ... $ echo 50 When I do now a: $ history I see all the 50 (+/- 1) But when I leave the shell and go into a new one: $ histroy gives me only about the last 25 (i.e. echo 27 to echo 50 + "history"), and these are also the only entries in .bash_history, i.e.: #1427309882 echo 27 #1427309882 echo 28 [snip snap] #1427309882 echo 50 #1427309884 history Cheers, Chris.
Re: feature-request: don't count history time comment lines when in HISTFILESIZE
On 3/25/15 2:07 PM, Christoph Anton Mitterer wrote: > Hey. > > When HISTTIMEFORMAT is used the history time comment lines are written > to HISTFILE. > Therefore, HISTFILESIZE is effectively only half as large. > > Would it be possible to simply not count the history time comment lines > when enforcing HISTFILESIZE? The history file truncation code already skips lines that look like history timestamps. Look at history.c:history_truncate_file(). -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
feature-request: don't count history time comment lines when in HISTFILESIZE
Hey. When HISTTIMEFORMAT is used the history time comment lines are written to HISTFILE. Therefore, HISTFILESIZE is effectively only half as large. Would it be possible to simply not count the history time comment lines when enforcing HISTFILESIZE? Cheers, Chris.