touched

A small, IO-heavy library that monitors files for changes and runs either a system shell command or a Haskell `IO ()` action.


Keywords
library, mit, program, System.Touched, System.Touched.OnlyOne, System.Touched.Procedure
License
MIT
Install
cabal install touched-0.2.0.1

Documentation

Touched

A Haskell tool for waiting patiently until a file changes, and then doing something.

Install from Hackage with cabal install touched.

System.Touched

System.Touched defines an extremely minimal API: it exports just two types and five functions.

  • data Procedure a b

    A type defining a procedure and a handle type. Constructed with either async or cmd by default. Type synonyms:

    • type AsyncCmd = Procedure CreateProcess CmdHandles
    • type AsyncIO = Procedure (IO ()) ThreadId
  • onChangeAny :: Bool -> [FilePath] -> Procedure a b -> IO ()

    If any of the files at [FilePath] has changed, the procedure is killed and re-launched. Always launches the procedure the first time, whether a change has happened or not.

    If the first Bool parameter is true, directories are scanned recursively.

  • onChangeAll :: Bool -> [FilePath] -> Procedure a b -> IO ()

    Nearly identical to onChangeAny, with the exception that each and every file specified (or all files in a directory, if recursive) must have changed to (re)launch the procedure.

  • onChangeFile :: FilePath -> Procedure a b -> IO ()

    Also nearly identical to onChangeAny and onChangeAll but takes a single file or directory and never searches directories recursively.

  • async :: IO () -> AsyncIO

    Creates a process out of a Haskell IO thunk.

  • cmd :: String -> AsyncCmd

    Creates a process out of a string to be launched in the system shell.

touched-cli

Included with the library is a simple executable for use from a command line. It's pretty easy to use. This is equivalent to the onChangeAny example above:

  touched --call="git commit -am Auto-commit" README.md LICENSE src/System/Touched.md

Known Issues

  • When you kill the process you're in, shell processes launched by Touched may continue running. This is on the top of the «to-fix» queue.