summaryrefslogtreecommitdiff
path: root/Utility/Path.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-10-16 00:31:25 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-10-16 00:50:12 -0400
commit23f2a12816e250f6780f80443ef6ec31c13fca9e (patch)
tree98de024aa2909caa39f82a76ccde182afef5093b /Utility/Path.hs
parent91366c896d9c9cb4519b451a64ed4d1e0ff52cb3 (diff)
broke up Utility
Diffstat (limited to 'Utility/Path.hs')
-rw-r--r--Utility/Path.hs22
1 files changed, 22 insertions, 0 deletions
diff --git a/Utility/Path.hs b/Utility/Path.hs
index 1c68b87bb..38e7bd05c 100644
--- a/Utility/Path.hs
+++ b/Utility/Path.hs
@@ -14,6 +14,9 @@ import System.Directory
import Data.List
import Data.Maybe
import Control.Applicative
+import System.Posix.User
+
+import Utility.Monad
{- Returns the parent directory of a path. Parent of / is "" -}
parentDir :: FilePath -> FilePath
@@ -112,3 +115,22 @@ preserveOrder (l:ls) new = found ++ preserveOrder ls rest
-}
runPreserveOrder :: ([FilePath] -> IO [FilePath]) -> [FilePath] -> IO [FilePath]
runPreserveOrder a files = preserveOrder files <$> a files
+
+{- Lists the contents of a directory.
+ - Unlike getDirectoryContents, paths are not relative to the directory. -}
+dirContents :: FilePath -> IO [FilePath]
+dirContents d = map (d </>) . filter notcruft <$> getDirectoryContents d
+ where
+ notcruft "." = False
+ notcruft ".." = False
+ notcruft _ = True
+
+{- Current user's home directory. -}
+myHomeDir :: IO FilePath
+myHomeDir = homeDirectory <$> (getUserEntryForID =<< getEffectiveUserID)
+
+{- Checks if a command is available in PATH. -}
+inPath :: String -> IO Bool
+inPath command = getSearchPath >>= anyM indir
+ where
+ indir d = doesFileExist $ d </> command