Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. module Main where
  2.  
  3. import System.Environment ( getArgs )
  4. import System.FSNotify
  5. import System.FilePath.Posix ( takeFileName )
  6. import System.Process ( spawnProcess )
  7. import Control.Monad ( forever, void )
  8. import Control.Concurrent ( threadDelay )
  9.  
  10. main :: IO ()
  11. main = withManager $ \mgr -> do
  12. args <- getArgs
  13. let exe = head args
  14. files = tail args
  15. watchDir mgr "." (modified files) (action exe files)
  16. forever $ threadDelay 1000000
  17. where
  18. modified :: [FilePath] -> Event -> Bool
  19. modified files (Modified path _ False) = (takeFileName path) `elem` files
  20. modified _ _ = False
  21.  
  22. action :: FilePath -> [FilePath] -> Event -> IO ()
  23. action proc files ev = do
  24. print ev
  25. putStrLn $ "calling " <> show proc <> " with " <> show files
  26. void $ spawnProcess proc files
  27.  
  28. watchConf :: WatchConfig
  29. watchConf = defaultConfig { confDebounce = Debounce 50 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement