1 module Hcompta.LCC.Lib.FilePath where
3 import Control.Applicative ((<$>))
4 import Control.Monad (Monad(..))
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
11 -- | Return an absolute 'FilePath', given the current working directory and a path.
13 -- * "~" as prefix is expanded to the process's user's home directory
14 -- * "-" as path is unchanged
15 -- * ~USER is not supported
16 path_absolute :: FilePath -> FilePath -> IO FilePath
17 path_absolute _ "-" = return "-"
18 path_absolute cwd path =
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"