Skip to content

Commit

Permalink
behaives the same as tail -f
Browse files Browse the repository at this point in the history
  • Loading branch information
athanclark committed Oct 15, 2017
1 parent 0e768e0 commit a6f35ef
Show file tree
Hide file tree
Showing 5 changed files with 3,079 additions and 22 deletions.
28 changes: 28 additions & 0 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Path
import qualified Data.ByteString.Lazy as BS
import qualified Data.Text as T
import Data.Attoparsec.Text (parseOnly, endOfInput, eitherP)
import Data.Attoparsec.Path (absFilePath, relFilePath, absDirPath)
import System.INotify (initINotify, removeWatch, killINotify)
import System.File.Follow (follow)
import System.Directory (getCurrentDirectory)
import System.Environment (getArgs)
import Control.Monad (forever)
import Control.Exception (bracket)
import Control.Concurrent (threadDelay)


main = do
[f] <- getArgs
f <- case parseOnly (eitherP absFilePath relFilePath <* endOfInput) (T.pack f) of
Left e -> error e
Right eAR -> case eAR of
Left a -> pure a
Right r -> do
d <- getCurrentDirectory
case parseOnly (absDirPath <* endOfInput) (T.pack (d ++ "/")) of
Left e -> error e
Right d' ->
pure (d' </> r)
i <- initINotify
bracket (follow i f BS.putStr) (\watch -> removeWatch watch >> killINotify i) $ \_ -> forever $ threadDelay 50000
9 changes: 6 additions & 3 deletions follow-file.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ Library
, utf8-string
, vector

Test-suite filefollow-tests
Type: exitcode-stdio-1.0
Executable follow-file
Default-Language: Haskell2010
Hs-Source-Dirs: test
Hs-Source-Dirs: app
Main-is: Main.hs
Build-Depends: base
, bytestring
, follow-file
, path
, text
, attoparsec
, attoparsec-path
, hinotify
, directory

Expand Down
Loading

0 comments on commit a6f35ef

Please sign in to comment.