Skip to content

Instantly share code, notes, and snippets.

@jamesdavidson
Forked from kfish/watch-read.hs
Last active August 29, 2015 14:15
Show Gist options
  • Save jamesdavidson/62aba35a483367099d03 to your computer and use it in GitHub Desktop.
Save jamesdavidson/62aba35a483367099d03 to your computer and use it in GitHub Desktop.
{-# 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