Last active
September 6, 2019 01:08
-
-
Save theSeafarer/d6638915c225c2c950a57dc428ffb607 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
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