module HSInstall.Paths
( getShareDir )
where
import System.Directory ( doesDirectoryExist )
import System.Environment ( getExecutablePath )
import System.FilePath ( (</>), takeDirectory, takeFileName )
getShareDir :: IO FilePath -> IO FilePath
getShareDir cabalDataDir = do
appDir <- stripVersion . takeFileName <$> cabalDataDir
sharePath <- ( </> "share" </> appDir )
. takeDirectory . takeDirectory <$> getExecutablePath
sharePathExists <- doesDirectoryExist sharePath
if sharePathExists
then return sharePath
else fail $ "Share directory " ++ sharePath ++ " does not exist"
stripVersion :: String -> String
stripVersion = reverse . tail . dropWhile (/= '-') . reverse