In some occasion, after making some changes to different files, we might want to apply some operations only on the changed files.
Assuming you’re using
git for version control, we can use
git diff --name-only to get a list of changed files.
In shell, we can use
$(<command) to run a command and capture its output.
Combining these two, we can apply an operation on changed files by:
$ <command> $(git diff --name-only)
Previously I am not using any code formatter on my client project. Even though, I can run the formatter directly on the whole project, I am afraid that some code might break (since I don’t have a full test coverage).
Hence, I plan to slowly format my code whenever I make any changes with this command:
bundle exec standardrb $(git diff --name-only) --fix