This is a shell scripting question really, but relates to rails.
I create a Rails migration like this:
~/dropbox/rails/f6$ rails g migration ModifyWord
Rails then creates the migration script, and reports the name back on the console:
~/dropbox/rails/f6$ rails g migration ModifyWord
invoke active_record
create db/migrate/20121231080052_modify_word.rb
I then edit the migration file using vi, like this:
~/dropbox/rails/f6$ vi db/migrate/20121231080052_modify_word.rb
I’d like to be able to do the vi filename as a single command, perhaps via a shell script that can have an alias to it added to my .bash_rc.
That is, I would run the command after the migration and it would look at the filename reported.
Any suggestions on how I should approach this?
SOLUTION
Based on per Michaël Witrant’s suggestion, I have added to aliases to my bash profile.
- cm to cat the last created migration file
-
vm to vi the last created migration file
alias cm=’cat
ls db/migrate/*.rb | tail -n 1‘alias vm=’vi
ls db/migrate/*.rb | tail -n 1‘
Since it starts with a time stamp, it should always be the last file alphabetically so I’d simply do something like this: