Skip to content

Instantly share code, notes, and snippets.

@jhrcek
Last active May 17, 2018 10:35
Show Gist options
  • Save jhrcek/b763bf2979a1e294db6246534c280093 to your computer and use it in GitHub Desktop.
Save jhrcek/b763bf2979a1e294db6246534c280093 to your computer and use it in GitHub Desktop.
Haskell script using fsnotify to watch for filesystem events in given dir
#!/usr/bin/env stack
-- stack script --resolver lts-10.9 --package fsnotify
{-# LANGUAGE OverloadedStrings #-}
import Control.Concurrent (threadDelay)
import Control.Monad (forever)
import System.Environment (getArgs)
import System.FSNotify (watchTree, withManager)
main :: IO ()
main = do
[dir] <- getArgs
withManager $ \mgr -> do
watchTree mgr dir (const True) print
forever $ threadDelay 1000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment