turtle 1.5.7 → 1.5.8
raw patch · 4 files changed
+75/−8 lines, 4 filesdep ~foldldep ~temporary
Dependency ranges changed: foldl, temporary
Files
- CHANGELOG.md +8/−0
- src/Turtle/Pattern.hs +7/−3
- src/Turtle/Prelude.hs +57/−2
- turtle.cabal +3/−3
CHANGELOG.md view
@@ -1,3 +1,11 @@+1.5.8++* Bug fix: `invert` no longer rejects inputs where a prefix matches the inverted+ pattern+ * See: https://github.com/Gabriel439/Haskell-Turtle-Library/pull/297+* Add lsdepth, findtree, cmin, and cmax+* Increase upper bound on `temporary` and `foldl`+ 1.5.7 * Increase upper bound on `doctest`
src/Turtle/Pattern.hs view
@@ -444,11 +444,15 @@ [] >>> match (invert "A") "B" [()]+>>> match (invert "A") "AA"+[()] -} invert :: Pattern a -> Pattern ()-invert p = Pattern (StateT (\str -> case runStateT (runPattern p) str of- [] -> [((), "")]- _ -> [] ))+invert p = Pattern (StateT f)+ where+ f str = case match p str of+ [] -> [((), "")]+ _ -> [] {-| Match a `Char`, but return `Text`
src/Turtle/Prelude.hs view
@@ -170,6 +170,7 @@ , ls , lsif , lstree+ , lsdepth , cat , grep , grepText@@ -183,6 +184,7 @@ , inplaceSuffix , inplaceEntire , find+ , findtree , yes , nl , paste@@ -269,6 +271,8 @@ , PosixCompat.isDirectory , PosixCompat.isSymbolicLink , PosixCompat.isSocket+ , cmin+ , cmax -- * Headers , WithHeader(..)@@ -305,7 +309,7 @@ import qualified Data.Set as Set import Data.Text (Text, pack, unpack) import Data.Time (NominalDiffTime, UTCTime, getCurrentTime)-import Data.Time.Clock.POSIX (POSIXTime)+import Data.Time.Clock.POSIX (POSIXTime, posixSecondsToUTCTime) import Data.Traversable import qualified Data.Text as Text import qualified Data.Text.IO as Text@@ -1005,6 +1009,29 @@ then return child <|> lstree child else return child ++{- | Stream the recursive descendents of a given directory+ between a given minimum and maximum depth+-}+lsdepth :: Int -> Int -> FilePath -> Shell FilePath+lsdepth mn mx path =+ lsdepthHelper 1 mn mx path+ where+ lsdepthHelper :: Int -> Int -> Int -> FilePath -> Shell FilePath+ lsdepthHelper depth l u p = + if depth > u+ then empty+ else do+ child <- ls p+ isDir <- testdir child+ if isDir+ then if depth >= l+ then return child <|> lsdepthHelper (depth + 1) l u child+ else lsdepthHelper (depth + 1) l u child+ else if depth >= l+ then return child+ else empty+ {-| Stream all recursive descendents of the given directory This skips any directories that fail the supplied predicate@@ -1635,6 +1662,34 @@ file_stat <- lstat file return (not (PosixCompat.isSymbolicLink file_stat)) +-- | Filter a shell of FilePaths according to a given pattern+findtree :: Pattern a -> Shell FilePath -> Shell FilePath+findtree pat files = do+ path <- files+ Right txt <- return (Filesystem.toText path)+ _:_ <- return (match pat txt)+ return path++{- | Check if a file was last modified after a given+ timestamp+-} +cmin :: MonadIO io => UTCTime -> FilePath -> io Bool+cmin t file = do+ status <- lstat file+ return (adapt status)+ where+ adapt x = posixSecondsToUTCTime (modificationTime x) > t++{- | Check if a file was last modified before a given+ timestamp+-} +cmax :: MonadIO io => UTCTime -> FilePath -> io Bool+cmax t file = do+ status <- lstat file+ return (adapt status)+ where+ adapt x = posixSecondsToUTCTime (modificationTime x) < t+ -- | A Stream of @\"y\"@s yes :: Shell Line yes = fmap (\_ -> "y") endless@@ -2065,7 +2120,7 @@ sortOn :: (Functor io, MonadIO io, Ord b) => (a -> b) -> Shell a -> io [a] sortOn f = sortBy (comparing f) --- | Return a list of the elements of the given `Shell`, sortesd by the given function and keeping duplicates:+-- | Return a list of the elements of the given `Shell`, sorted by the given function and keeping duplicates: -- -- >>> sortBy (comparing fst) (select [(1,'a'),(4,'b'),(2,'c'),(3,'d'),(3,'e'),(7,'f')]) -- [(1,'a'),(2,'c'),(3,'d'),(3,'e'),(4,'b'),(7,'f')]
turtle.cabal view
@@ -1,5 +1,5 @@ Name: turtle-Version: 1.5.7+Version: 1.5.8 Cabal-Version: >=1.10 Build-Type: Simple License: BSD3@@ -57,7 +57,7 @@ containers >= 0.5.0.0 && < 0.6 , directory >= 1.0.7 && < 1.4 , exceptions >= 0.4 && < 0.11,- foldl >= 1.1 && < 1.4 ,+ foldl >= 1.1 && < 1.5 , hostname < 1.1 , managed >= 1.0.3 && < 1.1 , process >= 1.0.1.1 && < 1.7 ,@@ -65,7 +65,7 @@ system-filepath >= 0.3.1 && < 0.5 , system-fileio >= 0.2.1 && < 0.4 , stm < 2.5 ,- temporary < 1.3 ,+ temporary < 1.4 , text < 1.3 , time < 1.9 , transformers >= 0.2.0.0 && < 0.6 ,