All Projects â†’ radovskyb â†’ Watcher

radovskyb / Watcher

Licence: bsd-3-clause
watcher is a Go package for watching for files or directory changes without using filesystem events.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Watcher

Notify
🔭 Cross-platform filesystem notification library for Rust.
Stars: ✭ 1,123 (+11.85%)
Mutual labels:  watcher, cross-platform
Starhub
All about your Github account, public and private activity, watch stars, followers and much more.
Stars: ✭ 60 (-94.02%)
Mutual labels:  watcher, notifier
Keyvast
KeyVast - A key value store
Stars: ✭ 33 (-96.71%)
Mutual labels:  cross-platform
Cuttlefish
Transactional email server with a lovely web interface
Stars: ✭ 985 (-1.89%)
Mutual labels:  cross-platform
Proxy Watcher
A library that recursively watches an object for mutations via Proxies and tells you which paths changed.
Stars: ✭ 35 (-96.51%)
Mutual labels:  watcher
Env Cmd
Setting environment variables from a file
Stars: ✭ 969 (-3.49%)
Mutual labels:  cross-platform
Nativescript Cli
Command-line interface for building NativeScript apps
Stars: ✭ 977 (-2.69%)
Mutual labels:  cross-platform
Sers
Serial port access for the Go programming language.
Stars: ✭ 30 (-97.01%)
Mutual labels:  cross-platform
Codenameone
Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
Stars: ✭ 992 (-1.2%)
Mutual labels:  cross-platform
Revery
âš¡ Native, high-performance, cross-platform desktop apps - built with Reason!
Stars: ✭ 7,812 (+678.09%)
Mutual labels:  cross-platform
Extensionsindex
Slicer extensions index
Stars: ✭ 36 (-96.41%)
Mutual labels:  cross-platform
Monogame
One framework for creating powerful cross-platform games.
Stars: ✭ 8,014 (+698.21%)
Mutual labels:  cross-platform
Expo Stack
🎮🧱 stack game clone made in expo (ios, android, web), three.js, react native
Stars: ✭ 34 (-96.61%)
Mutual labels:  cross-platform
Erewhon Game
Video game about programming your spaceships to destroy other programmed spaceships o/
Stars: ✭ 35 (-96.51%)
Mutual labels:  cross-platform
Pushclient
A cross-platform method of using Firebase Cloud Messaging (FCM) to receive push notifications
Stars: ✭ 33 (-96.71%)
Mutual labels:  cross-platform
Simplifyify
A simplified Browserify and Watchify CLI
Stars: ✭ 37 (-96.31%)
Mutual labels:  cross-platform
Tomanocupacero
Uma CLI cross-platform que reproduz um áudio do Mc Poze em loop. "toma no cu pacero to chei de ódio"
Stars: ✭ 33 (-96.71%)
Mutual labels:  cross-platform
Mvvmlight
The main purpose of the toolkit is to accelerate the creation and development of MVVM applications in Xamarin.Android, Xamarin.iOS, Xamarin.Forms, Windows 10 UWP, Windows Presentation Foundation (WPF), Silverlight, Windows Phone.
Stars: ✭ 973 (-3.09%)
Mutual labels:  cross-platform
Electron Create Menu
a default menu for your electron applications, with convenience functions for multiplatform use and i18n.
Stars: ✭ 35 (-96.51%)
Mutual labels:  cross-platform
Aurelia
Aurelia 2, a standards-based, front-end framework designed for high-performing, ambitious applications.
Stars: ✭ 995 (-0.9%)
Mutual labels:  cross-platform

watcher

Build Status

watcher is a Go package for watching for files or directory changes (recursively or non recursively) without using filesystem events, which allows it to work cross platform consistently.

watcher watches for changes and notifies over channels either anytime an event or an error has occurred.

Events contain the os.FileInfo of the file or directory that the event is based on and the type of event and file or directory path.

Installation
Features
Example
Contributing
Watcher Command

Update

  • Event.OldPath has been added [Aug 17, 2019]
  • Added new file filter hooks (Including a built in regexp filtering hook) [Dec 12, 2018]
  • Event.Path for Rename and Move events is now returned in the format of fromPath -> toPath

Chmod event is not supported under windows.

Installation

go get -u github.com/radovskyb/watcher/...

Features

  • Customizable polling interval.
  • Filter Events.
  • Watch folders recursively or non-recursively.
  • Choose to ignore hidden files.
  • Choose to ignore specified files and folders.
  • Notifies the os.FileInfo of the file that the event is based on. e.g Name, ModTime, IsDir, etc.
  • Notifies the full path of the file that the event is based on or the old and new paths if the event was a Rename or Move event.
  • Limit amount of events that can be received per watching cycle.
  • List the files being watched.
  • Trigger custom events.

Todo

  • Write more tests.
  • Write benchmarks.

Example

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/radovskyb/watcher"
)

func main() {
	w := watcher.New()

	// SetMaxEvents to 1 to allow at most 1 event's to be received
	// on the Event channel per watching cycle.
	//
	// If SetMaxEvents is not set, the default is to send all events.
	w.SetMaxEvents(1)

	// Only notify rename and move events.
	w.FilterOps(watcher.Rename, watcher.Move)

	// Only files that match the regular expression during file listings
	// will be watched.
	r := regexp.MustCompile("^abc$")
	w.AddFilterHook(watcher.RegexFilterHook(r, false))

	go func() {
		for {
			select {
			case event := <-w.Event:	
				fmt.Println(event) // Print the event's info.
			case err := <-w.Error:
				log.Fatalln(err)
			case <-w.Closed:
				return
			}
		}
	}()

	// Watch this folder for changes.
	if err := w.Add("."); err != nil {
		log.Fatalln(err)
	}

	// Watch test_folder recursively for changes.
	if err := w.AddRecursive("../test_folder"); err != nil {
		log.Fatalln(err)
	}

	// Print a list of all of the files and folders currently
	// being watched and their paths.
	for path, f := range w.WatchedFiles() {
		fmt.Printf("%s: %s\n", path, f.Name())
	}

	fmt.Println()

	// Trigger 2 events after watcher started.
	go func() {
		w.Wait()
		w.TriggerEvent(watcher.Create, nil)
		w.TriggerEvent(watcher.Remove, nil)
	}()

	// Start the watching process - it'll check for changes every 100ms.
	if err := w.Start(time.Millisecond * 100); err != nil {
		log.Fatalln(err)
	}
}

Contributing

If you would ike to contribute, simply submit a pull request.

Command

watcher comes with a simple command which is installed when using the go get command from above.

Usage

Usage of watcher:
  -cmd string
    	command to run when an event occurs
  -dotfiles
    	watch dot files (default true)
  -ignore string
        comma separated list of paths to ignore
  -interval string
    	watcher poll interval (default "100ms")
  -keepalive
    	keep alive when a cmd returns code != 0
  -list
    	list watched files on start
  -pipe
    	pipe event's info to command's stdin
  -recursive
    	watch folders recursively (default true)
  -startcmd
    	run the command when watcher starts

All of the flags are optional and watcher can also be called by itself:

watcher

(watches the current directory recursively for changes and notifies any events that occur.)

A more elaborate example using the watcher command:

watcher -dotfiles=false -recursive=false -cmd="./myscript" main.go ../

In this example, watcher will ignore dot files and folders and won't watch any of the specified folders recursively. It will also run the script ./myscript anytime an event occurs while watching main.go or any files or folders in the previous directory (../).

Using the pipe and cmd flags together will send the event's info to the command's stdin when changes are detected.

First create a file called script.py with the following contents:

import sys

for line in sys.stdin:
	print (line + " - python")

Next, start watcher with the pipe and cmd flags enabled:

watcher -cmd="python script.py" -pipe=true

Now when changes are detected, the event's info will be output from the running python script.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].