Skip to content

Instantly share code, notes, and snippets.

@crabmusket
Created May 16, 2013 12:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crabmusket/5591481 to your computer and use it in GitHub Desktop.
Save crabmusket/5591481 to your computer and use it in GitHub Desktop.
Monitor a directory to rebuild pandoc files automatically.
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