timestampzsh

Unable to read the timestamp of Zsh history


Problem: to understand the following timestamp

1241036430

at ~/.history

: 1241036336:0;vim ~/.zshrc
: 1241036379:0;vim ~/bin/HideTopBar
: 1241036421:0;ls
: 1241036430:0;cat ~/.history

when I have

setopt EXTENDED_HISTORY
HISTFILE=~/.history

in .zshrc.

How can you read the timestamp?


Solution

  • This simple util, called localtime is gold for reading files with timestamps:

    #!/usr/bin/perl
    # http://perl.plover.com/classes/mybin/samples/source/localtime
    
    if ($ARGV[0] eq '-f') {
      *show_localtime = \&show_localtime_list;
      shift;
    }
    
    if (@ARGV) {
      for (@ARGV) {
        print show_localtime($_), "\n";
      }
    } else {
      while (<>) {
        s/^(\d+)/show_localtime($1)/e;
        print;
      }
    }
    
    
    sub show_localtime {
      my $t = shift;
      scalar localtime $t;
    }
    
    sub show_localtime_list {
      my $t = shift;
      my @a = localtime $t;
      "@a\n"
    }
    

    It handles lots of cases, and seem to understand both timestamps in seconds and mini-seconds, etc.

    $ localtime < ~/.histfile
    <snip>
    : Sat Sep 17 05:55:17 2016:0;cat localtime