← til

Opening the last migration

May 7, 2020
unix

I use Tim Pope's excellent rails.vim and its shortcuts. One of the shortcuts I use pretty regularly is :Emigration or :Emi to edit the last migration.

I usually create the migration from bash, by invoking the usual Rails commands. After the migration is created, I find it hard to edit that file, because of the timestamp in the name. That's why I usually open Vim and then use :Emi to edit that file.

Well, I've decided to write a small bash function to edit that file straight from bash:

emi() {
  $EDITOR $(find -E db/migrate -type f | sort | tail -n 1)
}

Place it in your .bashrc or .zshrc and you're good to go.