align object by selected edge

I couldn't find anything in the search....maybe it exists already?

I wanted a script to align the mesh based on selected edge..straighten it in X, Y OR Z

https://www.dropbox.com/s/4k0ybtaccrbil7f/alignobjectbyedge.jpg