spy 0.7 → 0.8
raw patch · 4 files changed
+41/−22 lines, 4 filesdep +unix
Dependencies added: unix
Files
- README.md +23/−9
- spy.cabal +5/−3
- src/Main.hs +4/−3
- src/Spy/Watcher.hs +9/−7
README.md view
@@ -1,18 +1,23 @@ Spy === -Spy is a compact file system watcher for Mac OS X and Linux (Note: Should work on Windows but is currently untested).+Spy is a compact file system watcher for Mac OS X and Linux (Note: Should work+on Windows but is currently untested). Usage ===== -Spy expects a single argument, the directory or a single file to watch. Spy currently supports two different modes: watch and run mode.+Spy expects a single argument, the directory or a single file to watch. Spy+currently supports two different modes: watch and run mode.+Press `CTRL-D` to stop watching for file system changes. Watch mode ----------- -In output mode Spy will print the path to a modified file to STDOUT (followed by a newline) whenever a file modification (new file added, file modified, file deleted) occurs.+In output mode Spy will print the path to a modified file to STDOUT (followed+by a newline) whenever a file modification (new file added, file modified, file+deleted) occurs. $> spy watch . path/to/modified/file@@ -21,11 +26,14 @@ $> spy . -It's possible to watch a single file (this obviously only shows changes to that particular file):+It's possible to watch a single file (this obviously only shows changes to that+particular file): $> spy /path/to/file -The default format is the full path to the modified file followed by a newline. To make it easier to parse the output, the `--format=json` changes the output to be printed formatted as a JSON object (again followed by a newline).+The default format is the full path to the modified file followed by a newline.+To make it easier to parse the output, the `--format=json` changes the output+to be printed formatted as a JSON object (again followed by a newline). $> spy watch --format=json . {"path":"/path/to/modified.file","flag":"Added","time":"2012-12-20 11:26:56.859456 UTC"}@@ -35,7 +43,8 @@ For directories the following options apply: -An optional second argument can be used to filter the files in the given directory using a glob pattern:+An optional second argument can be used to filter the files in the given+directory using a glob pattern: $> spy watch /path/to/directory "*.md" @@ -43,13 +52,18 @@ Run mode -------- -In run mode Spy will execute a given command whenever a file modification occurs without printing modifications to stdout. The command will be executed with the path to the modified file as the last argument.+In run mode Spy will execute a given command whenever a file modification+occurs without printing modifications to stdout. The command will be executed+with the path to the modified file as the last argument. $> spy run "./run-build.sh" -In the example above the shell script `run-build.sh` would be executed with the path to the modified file as the first argument.+In the example above the shell script `run-build.sh` would be executed with the+path to the modified file as the first argument. -If the command to be executed does not expect any (additional) arguments the `--notify-only` flag can be used. This will cause spy to execute the command without passing the path as an argument:+If the command to be executed does not expect any (additional) arguments the+`--notify-only` flag can be used. This will cause spy to execute the command+without passing the path as an argument: $> spy run --notify-only "rake test" .
spy.cabal view
@@ -1,5 +1,5 @@ name: spy-version: 0.7+version: 0.8 license: BSD3 license-file: LICENSE author: Stefan Saasen@@ -38,7 +38,8 @@ json >= 0.7, directory >= 1.1, system-filepath >= 0.4.7,- time >= 1.4+ time >= 1.4,+ unix executable spy main-is: Main.hs@@ -53,7 +54,8 @@ json >= 0.7, directory >= 1.1, system-filepath >= 0.4.7,- time >= 1.4+ time >= 1.4,+ unix ghc-options: -Wall
src/Main.hs view
@@ -7,7 +7,7 @@ import Spy.Watcher version :: String-version = "spy v0.7, (C) Stefan Saasen"+version = "spy v0.8, (C) Stefan Saasen" watch :: Spy watch = Watch@@ -40,5 +40,6 @@ main = do config <- cmdArgsRun mode canonicalizedDir <- canonicalizePath $ dir config- spy config { dir = addTrailingPathSeparator canonicalizedDir }- putStrLn "No eyes on the target"+ putStrLn "Press Ctrl-D to stop"+ spy (config { dir = addTrailingPathSeparator canonicalizedDir }) $+ putStrLn "No eyes on the target"
src/Spy/Watcher.hs view
@@ -11,7 +11,7 @@ ,containsHiddenPathElement ) where -import System.FSNotify+import System.FSNotify (withManager, watchTree, Event(..)) import System.Console.CmdArgs import System.Cmd import System.Exit@@ -23,6 +23,7 @@ import Data.Time.Clock(UTCTime) import Data.Maybe (fromMaybe, maybeToList, fromJust) import Text.JSON+import Spy.Daemon -- | The output format when Spy prints out changes to STDOUT data Format = Json | Plain deriving (Show, Eq, Data, Typeable)@@ -46,12 +47,13 @@ plainFormat = Plain -- | Register for FS events using the given Spy config.-spy :: Spy -> IO String-spy config = withManager $ \wm ->- watchTree wm (decodeString $ dir config)- (not . skipEvent config . eventPath)- (handleEvent config) >>- getLine+spy :: Spy -> IO b -> IO ()+spy config after = withManager $ \wm ->+ runIndefinitely+ (watchTree wm (decodeString $ dir config)+ (not . skipEvent config . eventPath)+ (handleEvent config)) + (const after) -- | Handle the FS event based on the current Spy run configuration handleEvent :: Spy -> Event -> IO ()