-
-
Save jamesdavidson/62aba35a483367099d03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# OPTIONS -Wall #-} | |
module Main where | |
import Control.Concurrent (threadDelay) | |
import System.Environment (getArgs) | |
import System.INotify | |
main :: IO () | |
main = do | |
args <- getArgs | |
if (null args) | |
then usage | |
else watch args | |
usage :: IO () | |
usage = putStrLn "Usage: watch-read file ..." | |
watch :: [FilePath] -> IO () | |
watch fs = withINotify $ \inotify -> do | |
print fs | |
mapM_ (\f -> addWatch inotify [Modify, CloseWrite] f (handleEvent f)) fs | |
threadDelay (10 * microsecsPerSec) | |
where | |
handleEvent :: FilePath -> Event -> IO () | |
handleEvent f e = putStrLn (f ++ ": " ++ show e) | |
microsecsPerSec = 1000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment