commercialhaskell / path

Typed filepath
Other
122 stars 45 forks source link

Hidden files #169

Closed NorfairKing closed 1 month ago

NorfairKing commented 3 years ago

I find myself rewriting functions like these a lot:

hidden :: Path Rel File -> Bool
hidden = goFile
  where
    goFile :: Path Rel File -> Bool
    goFile f = isHiddenIn (parent f) f || goDir (parent f)
    goDir :: Path Rel Dir -> Bool
    goDir f
      | parent f == f = False
      | otherwise = isHiddenIn (parent f) f || goDir (parent f)

isHiddenIn :: Path b Dir -> Path b t -> Bool
isHiddenIn curdir ad =
  case stripProperPrefix curdir ad of
    Nothing -> False
    Just rp -> "." `isPrefixOf` toFilePath rp

Would it be valuable to put them into the path library?