module Hcompta.LCC.Lib.FilePath where import Control.Applicative ((<$>)) import Control.Monad (Monad(..)) import Control.Monad.IO.Class (liftIO) import Prelude (($), FilePath, IO, id) import System.Directory (getHomeDirectory) import System.FilePath (()) import qualified System.FilePath.Posix as Path -- | Return an absolute 'FilePath', given the current working directory and a path. -- -- * "~" as prefix is expanded to the process's user's home directory -- * "-" as path is unchanged -- * ~USER is not supported path_absolute :: FilePath -> FilePath -> IO FilePath path_absolute _ "-" = return "-" path_absolute cwd path = (if Path.isRelative path then (cwd ) else id) <$> expand path where expand :: FilePath -> IO FilePath expand ('~':sep:p) = if Path.isPathSeparator sep then liftIO $ ( p) <$> getHomeDirectory else fail "~USERNAME in path is not supported" expand p = return p