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

New Homebrew formula for justniffer

Justniffer (http://justniffer.sourceforge.net/) – A very cool little TCP sniffer specialized for capturing HTTP traffic.

Example invocations:

$ justniffer -i en1 -p "port 80"
10.64.168.204 - - [22/Dec/2011:11:45:03 -0800] "GET /wiki/Brew HTTP/1.1" 200 23163 "" "curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3"

$ justniffer-grab-http-traffic -d . -i en1
...
^C
...
$ tree
.
├── bits.wikimedia.org/
│   ├── _w_extensions_1_18_OggHandler_OggPlayer_js_12index.js
│   └── _w_extensions_1_18_OggHandler_play_pngindex.png
├── en.wikipedia.org/
│   ├── _w_index_php_title_Special_3ABannerListLoader_cache__cn_js_language_en_project_wikipedia_country_USindex.js
│   ├── _wiki_Agile_software_developmentindex.html
│   ├── _wiki_Kent_Beckindex.html
│   └── _wiki_Martin_Fowlerindex.html
...

https://github.com/mxcl/homebrew/pull/9220

Vim screen corruption with screen/tmux and matchparen.vim

I’ve been experiencing an irritating bug for a few weeks and I finally eliminated it by disabling matchparen.vim

The bug happens when I’m using vim in an ssh session (to a Linux machine) with GNU Screen or tmux (on the server) in iTerm2.app or Terminal.app on Mac OS X and editing PHP code. If I type “require dirname(__FILE__) .“, then after typing the closing parenthesis, the screen gets corrupted such that it looks like I typed “require dirnam((__FILE_))” (missing “e”). Hitting Control-L refreshes the screen of course, but it’s irritating nonetheless.

Yesterday, I got the bug to disappear by putting this in my ~/.vimrc.local (I’m using Janus):

" vim's parenthesis highlighting causes screen corruption when vim is running
" inside GNU screen or tmux?
let loaded_matchparen = 1

I don’t know if this is a bug in matchparen.vim or something else.

If I type slowly, it looks like after typing the closing parenthesis, both the opening and closing parenthesis are highlighted correctly. Things go haywire after typing a space after the closing parenthesis. It looks like it’s attempting to replace the highlighted open parenthesis with a normal parenthesis but it does it one cursor position to the left, resulting in the “e” in dirname getting overwritten with a parenthesis and the highlighted open parenthesis is still present next to it.

Here’s a screenshot: http://cl.ly/1E1I2X0t3e1F3c3F2I2J

If I understood more clearly what the problem is, then I’d try to fix it and submit a patch, but I’m not very knowledgable about terminal issues. If someone points me in the right direction, I might be able to come up with a patch…

I’ll be posting this to the vim_dev mailing list as well.