Skip to content

Instantly share code, notes, and snippets.

@theSeafarer
Last active September 6, 2019 01:08
Show Gist options
  • Save theSeafarer/d6638915c225c2c950a57dc428ffb607 to your computer and use it in GitHub Desktop.
Save theSeafarer/d6638915c225c2c950a57dc428ffb607 to your computer and use it in GitHub Desktop.
module Main where
import System.Environment ( getArgs )
import System.FSNotify
import System.FilePath.Posix ( takeFileName )
import System.Process ( spawnProcess )
import Control.Monad ( forever, void )
import Control.Concurrent ( threadDelay )
main :: IO ()
main = withManager $ \mgr -> do
args <- getArgs
let exe = head args
files = tail args
watchDir mgr "." (modified files) (action exe files)
forever $ threadDelay 1000000
where
modified :: [FilePath] -> Event -> Bool
modified files (Modified path _ False) = (takeFileName path) `elem` files
modified _ _ = False
action :: FilePath -> [FilePath] -> Event -> IO ()
action proc files ev = do
print ev
putStrLn $ "calling " <> show proc <> " with " <> show files
void $ spawnProcess proc files
watchConf :: WatchConfig
watchConf = defaultConfig { confDebounce = Debounce 50 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment