Skip to content

Instantly share code, notes, and snippets.

@JustusAdam
Last active April 19, 2017 14:56
Show Gist options
  • Save JustusAdam/1467acc1a9baeab31982f7601656d293 to your computer and use it in GitHub Desktop.
Save JustusAdam/1467acc1a9baeab31982f7601656d293 to your computer and use it in GitHub Desktop.
Watch a shake project for changes and recompile on change
{-# LANGUAGE BangPatterns #-}
import Control.Concurrent
import Control.Monad
import Data.Foldable
import qualified Data.HashSet as HS
import System.Directory
import System.Environment
import System.FilePath
import System.FSNotify
import System.Process
shakeCmd = callProcess "./ShakeFile.hs"
shakeTargets = undefined -- add your shake targets here
reloadChrome = "tell application \"Google Chrome\"\n\
\ activate\n\
\ tell application \"System Events\"\n\
\ tell process \"Google Chrome\"\n\
\ keystroke \"r\" using {command down, shift down}\n\
\ end tell\n\
\ end tell\n\
\end tell\n\
\\n\
\tell application \"Code\" to activate\n\
\"
main = do
cwd <- getCurrentDirectory
shakeCmd ["--live"]
!files <- HS.fromList . map (cwd </>) . lines <$> readFile "live.txt"
removeFile "live.txt"
let dirs = HS.map takeDirectory files
withManager $ \mgr -> do
for_ dirs $ \dir ->
watchDir
mgr
dir
(flip HS.member files . eventPath)
(const $ do
shakeCmd shakeTargets
void $ readCreateProcess (proc "osascript" []) reloadChrome)
-- sleep forever (until interrupted)
forever $ threadDelay 1000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment