broke up Utility

This commit is contained in:
Joey Hess 2011-10-16 00:31:25 -04:00
parent 91366c896d
commit 23f2a12816
16 changed files with 126 additions and 112 deletions

View file

@ -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