Linux port by @cubizh. Tested on OSX.