Triggering a command line on file change
Today I was migrating a somewhat old codebase to Ruby on Rails 6.0.0. As per usual, this can be a very tidious job requiring a bunch of depencies to be updated as well. In this case, the Gemfile
contains around 150 lines.
When I have to do that kind of job, the first thing I do is commenting out every single gem except for rails itself, then bundle update
, then I re-add the other gems to the Gemfile
.
It rarely goes smoothly, since every gem has it’s own dependencies and sometime the bundle
command has trouble to find a way to update everything in one go, so I usually re-add 2-5 gems at once then run bundle update
on my modified Gemfile
, until all the dependencies have been re-added.
The whole process of going back and forth to editing, saving, running the bundle command is somewhat exhausting, so today I decided to have a look at a more productive way to do this : the following command uses inotifywait
to detect whenever I save the Gemfile
then run bundle update
automagically.
while inotifywait -e close_write Gemfile; do bundle update; done