In case anyone is interested I created a module for it and submitted a pull request to @zerojay's retropie extra repository:

https://github.com/zerojay/RetroPie-Extra/pull/184

I only tested on my pc but it should work on the pi too.