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