Created
May 16, 2013 12:49
-
-
Save crabmusket/5591481 to your computer and use it in GitHub Desktop.
Monitor a directory to rebuild pandoc files automatically.
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 Filesystem (getWorkingDirectory) | |
import Filesystem.Path (extensions) | |
import System.FSNotify | |
import System.Exit | |
import System.Environment | |
import System.Cmd | |
import Control.Concurrent | |
import Control.Monad | |
import Data.String (fromString) | |
main = do | |
cwd <- getWorkingDirectory | |
args <- getArgs | |
when (null args) $ do | |
putStrLn "Please give at least one filename (with no extension, .pandoc is assumed)" | |
exitFailure | |
let files = map (\f -> (fromString $ f ++ ".pandoc", f)) args | |
putStrLn "Watching current directory, press RETURN to exit." | |
withManager $ \man -> do | |
_ <- forkIO $ do | |
watchTree man cwd (const True) $ \fp -> do | |
case fp of | |
Removed _ _ -> return () | |
Added file _ -> maybeCompile file files | |
Modified file _ -> maybeCompile file files | |
_ <- getLine | |
exitSuccess | |
maybeCompile file files = case lookup file files of | |
Just f -> do | |
let command = "pandoc " ++ f ++ ".pandoc -N --smart --webtex -c buttondown.css -o " ++ f ++ ".html" | |
system command | |
return () | |
Nothing -> return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment