How to straighten a curved mesh with a rig?

There’s a way to straighten out any kind of mesh in any direction by adding an “edge” to the transform orientations.

(Select two vertices, go to the “transform orientation” dropdown, click the “+”… a new option called “edge” will appear at the bottom of the list. Scaling a loop in this orientation along x and z will align it to the straight line between the two selected points.)

A bit hidden, but very useful. But also a lot of manual adjustments if you want to apply that on a number of loops, or on a rigged mesh.

So my question: how would I do that using bones?