1 module Hcompta.Lib.Path where
3 import Control.Applicative ((<$>))
4 import Control.Monad (liftM)
5 import Control.Monad.IO.Class (liftIO)
6 import System.Directory (getHomeDirectory)
7 import System.FilePath ((</>))
8 import qualified System.FilePath.Posix as Path
10 -- | Return an absolute 'FilePath', given the current working directory and a path.
12 -- * "~" as prefix is expanded to the process's user's home directory
13 -- * "-" as path is unchanged
14 -- * ~USER is not supported
15 abs :: FilePath -> FilePath -> IO FilePath
16 abs _ "-" = return "-"
19 (if Path.isRelative path
24 expand :: FilePath -> IO FilePath
26 if Path.isPathSeparator sep
27 then liftIO $ (</> p) <$> getHomeDirectory
28 else fail "~USERNAME in path is not supported"