bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Default time for unmarked history lines


From: Eduardo A . Bustamante López
Subject: Re: Default time for unmarked history lines
Date: Thu, 7 Jan 2016 14:07:42 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

On Thu, Jan 07, 2016 at 04:33:32PM +0000, Reuben Thomas wrote:
> Would it be better to have the default time for unmarked history lines to
> be the epoch rather than the current time?
> 
> I recently added time recording, via HISTTIMEFORMAT, to my bash history. It
> is odd that now when listing it, all the old lines have the current time
> and date; in particular, it violates the expectation that the history will
> (unless I have done odd things to it) be ordered monotonically.
> 
> It would seem more natural to use the time of the epoch.
> 
> I have worked around this problem by annotating all the old lines with "#1"
> (I was a bit surprised that "#0" didn't work, I learned something new about
> UNIX time!).
> 
> -- 
> http://rrt.sc3d.org

You seem to have two points:

(1) It's more *natural* (to you) to use the time of the epoch
(2) The history should be ordered monotonically (increasing?)

Regarding (2):

It is already monotonically increasing. And using the epoch is no different to
using the current time, is it? Both are constant values. See:

    dualbus@hp ~ % cat -n script 
         1  printf '%s\n' echo\ {3,2,1} > ~/.bash_history
         2  HISTTIMEFORMAT='%Y-%m-%dT%H:%M:%S ' bash -i <<EOF
         3  echo a; sleep 1
         4  echo b; sleep 1
         5  history
         6  EOF
         7  cat ~/.bash_history
    
    dualbus@hp ~ % zsh script       
    dualbus@hp:~$ echo a; sleep 1
    a
    dualbus@hp:~$ echo b; sleep 1
    b
    dualbus@hp:~$ history
        1  2016-01-07T14:04:04 echo 3
        2  2016-01-07T14:04:04 echo 2
        3  2016-01-07T14:04:04 echo 1
        4  2016-01-07T14:04:04 echo a; sleep 1
        5  2016-01-07T14:04:05 echo b; sleep 1
        6  2016-01-07T14:04:06 history
    dualbus@hp:~$ exit
    echo 3
    echo 2
    echo 1
    #1452197044
    echo a; sleep 1
    #1452197045
    echo b; sleep 1
    #1452197046
    history

As you can see, the order of the entries is kept.

So, given that (2) does not hold, this boils down to having a different default
for unmarked entries. I don't see why the epoch is better though.

Perhaps I misunderstood (2) though.

-- 
Eduardo Bustamante
https://dualbus.me/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]