-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWatch.hs
executable file
·48 lines (41 loc) · 1.55 KB
/
Watch.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env stack runhaskell --
{-# 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 = ["script-html", "slides"]
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 \"Sublime Text\" to activate\n\
\"
main = do
cwd <- getCurrentDirectory
shakeCmd ["--live"]
!files <- HS.fromList . map (cwd </>) . lines <$> readFile "live.txt"
removeFile "live.txt"
let dirs = HS.filter (("docs" `notElem`) . splitDirectories) $ 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