Coder Social home page Coder Social logo

gowatch's Introduction

Turn file system events into JSON stream.

(Does not support recursive directory watching.)

Install

go get github.com/hayeah/gowatch

Usage

gowatch dir ...

It would ouput a JSON stream that you can pipe into another program for filtering & processing. Supposed we are watching a directory called test, you get output like:

> ./gowatch test
{"event":"chmod","path":"test/foobar"}
{"event":"remove","path":"test/foobar"}
{"event":"create","path":"test/foobar"}
{"event":"chmod","path":"test/foobar"}

Slice and dice as you please.

Example

It is convenient to combine gowatch with a JSON processing tool like jq.

Suppose we'd like to execute a command whenenver a new file is added, we can build a pipeline:

> ./gowatch test | unbuffer -p jq -M 'select(.event == "create")' | gogo 'echo process new file {{.path}}'
2014/11/29 11:35:04 watching: test
2014/11/29 11:35:06 run cmd: echo process new file test/foo
process new file test/foo
2014/11/29 11:35:06 run cmd: echo process new file test/bar
process new file test/bar
  • unbuffer - This disables buffering so jq sends output down the pipe as soon as possible.
    • -p is used in a pipeline to read input from upstream.
  • jq - It selects only the create events.
    • -M disables output color. This prevents JSON parser downstream from choking.
  • gogo - A utility to run processes for each object in a JSON stream. See: hayeah/gogo

File System Events Supported

See: fsnotify.Op

const (
    Create Op  = 1 << iota
    Write
    Remove
    Rename
    Chmod
)

gowatch's People

Contributors

hayeah avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.