Hi there,
There's one script that follows a similar flow:
Roughly, this does:
* detect which revision control system is being used, like git
* detect locally modified files
* format all files into temporary outputs
* create a diff from unformatted vs. formatted files
* pass the diff through a generic interactive patch program, and prompt you to accept changes one hunk at a time
(Up to the user to `git add` these changes after formatting.)
The formatter should already delete trailing whitespace, so the diff vs. formatted code is the check.
Does this help?