SHARE
TWEET

Untitled

a guest Sep 17th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top