diff options
author | 2012-12-17 13:29:10 -0400 | |
---|---|---|
committer | 2012-12-17 13:29:10 -0400 | |
commit | caadeb495bd603a6f2b19064c4aaaec752bc3b6d (patch) | |
tree | a9ff9380331c93c0c4c4ab4b2f78d1c8b6f0ad58 /Utility/Path.hs | |
parent | 63f72a295e4607061f768068e310a446bec806aa (diff) | |
parent | 922e0d2c13d2c9105beeb18fe4eeb90dbddea76c (diff) |
Merge branch 'master' into desymlink
Conflicts:
debian/changelog
doc/design/assistant/desymlink.mdwn
Diffstat (limited to 'Utility/Path.hs')
-rw-r--r-- | Utility/Path.hs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/Utility/Path.hs b/Utility/Path.hs index 4bab297da..ba836d9b6 100644 --- a/Utility/Path.hs +++ b/Utility/Path.hs @@ -132,11 +132,25 @@ relHome path = do then "~/" ++ relPathDirToFile home path else path -{- Checks if a command is available in PATH. -} +{- Checks if a command is available in PATH. + - + - The command may be fully-qualified, in which case, this succeeds as + - long as it exists. -} inPath :: String -> IO Bool -inPath command = getSearchPath >>= anyM indir +inPath command = isJust <$> searchPath command + +{- Finds a command in PATH and returns the full path to it. + - + - The command may be fully qualified already, in which case it will + - be returned if it exists. + -} +searchPath :: String -> IO (Maybe FilePath) +searchPath command + | isAbsolute command = check command + | otherwise = getSearchPath >>= getM indir where - indir d = doesFileExist $ d </> command + indir d = check $ d </> command + check f = ifM (doesFileExist f) ( return (Just f), return Nothing ) {- Checks if a filename is a unix dotfile. All files inside dotdirs - count as dotfiles. -} |