Last active
April 19, 2017 14:56
-
-
Save JustusAdam/1467acc1a9baeab31982f7601656d293 to your computer and use it in GitHub Desktop.
Watch a shake project for changes and recompile on change
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
{-# 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