~bin/
things in my bin
Fri Dec 4 10:17:37 2009

Little function I stuck in my bashrc, maybe it'll be useful. Uses the .viminfo file to get a list of recently edited files. Obiously not much use unless you use vim as your One True Editor.

vl [-]    # edit most recently edited file
vl [-] 0  # equivalent to above
vl [-] 3  # 4th last edited file (we're 0 indexed)

If $1 is -, show what we'd do but don't do it.

vl() {
 [ "$1" == '-' ] && shift && local echo=echo
 fl=$(awk -v h="$HOME" -v q=${1:-0} '
  $1 == ">" {
   if ( system("test -f " $2) ) next
   if( y++ != q ) next
   sub(/^~/,h,$2)
   print $2
   exit
  }
 ' .viminfo)
 [ "$fl" ] || return
 $echo vim $fl
}