bash: Displaying the time at which historical commands were executed

Yesterday’s find. This will be indispensable the next time I wonder how long a command took which I forgot to time. Or the next time I want to know when a certain change went into effect.

$ HISTTIMEFORMAT="[%s] [%Y-%m-%d %H:%M:%S] " history 5
  653  [1329580687] [2012-02-18 07:58:07] sleep 5
  654  [1329580693] [2012-02-18 07:58:13] date
  655  [1329580698] [2012-02-18 07:58:18] sleep 5
  656  [1329580704] [2012-02-18 07:58:24] uptime
  657  [1329580709] [2012-02-18 07:58:29] HISTTIMEFORMAT="[%s] [%Y-%m-%d %H:%M:%S] " history 5
marca@scml-marca:/usr/local$ HISTTIMEFORMAT="[%s] [%Y-%m-%d %H:%M:%S] " history 100 | grep brew
  571  [1329173341] [2012-02-13 14:49:01] mv /Users/marca/perl5/perlbrew/perls/perl-5.15.6/bin/tarcolor /Users/marca/perl5/perlbrew/perls/perl-5.15.6/bin/tarcolor~
  574  [1329173354] [2012-02-13 14:49:14] brew uninstall tarcolor
  585  [1329173533] [2012-02-13 14:52:13] brew install -v tarcolor
  586  [1329173547] [2012-02-13 14:52:27] mv /Users/marca/perl5/perlbrew/perls/perl-5.15.6/bin/tarcolor~ /Users/marca/perl5/perlbrew/perls/perl-5.15.6/bin/tarcolor
  642  [1329528177] [2012-02-17 17:22:57] brew outdated
  643  [1329528194] [2012-02-17 17:23:14] brew home bdw-gc
  644  [1329528223] [2012-02-17 17:23:43] brew upgrade
  651  [1329580648] [2012-02-18 07:57:28] HISTTIMEFORMAT="[%s] [%Y-%m-%d %H:%M:%S] " history 100 | grep brew

Discovered this at http://stackoverflow.com/q/1862510/638434 while looking up how to add the execution time of the last command to the bash prompt. There is a nice tip there for doing that as well as adding growl notification for long-running commands.

Here’s the former in action:

marca@scml-marca:/usr/local$ export PS1='[last: ${timer_show}] '$PS1
[last: 0] marca@scml-marca:/usr/local$ date ; sleep 60 ; date
Sat Feb 18 08:23:29 PST 2012
Sat Feb 18 08:24:29 PST 2012
[last: 60] marca@scml-marca:/usr/local$ uptime
 8:27  up 4 days, 18:47, 3 users, load averages: 0.02 0.10 0.13

Pull request for Python pip installer accepted

https://github.com/pypa/pip/pull/374

The pull request addresses a UnicodeDecodeError bug in pip. It affects pip in Python 3 and it’s triggered when a package install fails and emits Unicode characters to the console. A classic case of this are gcc error messages which use exotic quotes.

It adds a test for the issue and then fixes it. Fixing this also required making a fix to Ian Bicking’s ScriptTest package, which was incorporated in ScriptTest 1.2.

The pip fix has not been included in an official pip release yet.