No joke, I just spent an hour trying to figure out how to do this in Blender because I really needed it. Thank you!!
If you continue to update this I’d love a way to bind a key to this because I can see myself using this often.
EDIT: I swear that your script is actually fixing a bug that I keep having in Blender. If I snap the 3D cursor to an edge it will align one axis but the other two go off randomly. If I run your script after that, re-align the cursor, it actually is fixed.
EDIT 3: In this image I snapped to the edge that’s running across the front face of this cylinder (top left). You can see the axis are off, even after I run your script (top right). However, if I snap the 3D cursor again immediately after running your script once it fixes it (bottom left) and then running your script a second time fixes it to a usable state (bottom right). So it’s not that your script breaks anything, it actually fixes the issue that exists in Blender for me.