watch

command module
v0.0.0-...-2f29955 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 8 Imported by: 0

README

Watch

Watch runs a command each time a set of files changes. Watch is a clone of the 9fans/go Watch tool but is made to work outside of Acme.

There are some differences between the 9fans/go Watch tool and this tool, instead of relying on the current working directory to find files to monitor, the user needs to specify (with globbing support) which files to specifically watch. Another difference is the notion of an unescaped % in the arguments list which is substituted with file path of the file that was changed.

Watch may not be as efficient as it could be (using syscalls) but is written so that it is as simple and cross-platform as possible.

Usage

watch '*.go' go run %

License

MIT

Documentation

Overview

Command watch runs a command when a set of files changes.

Usage:

watch [ -d delay ] 'pattern' cmd [ args... ]

Watch works by periodically checking the status of the specified files using os.Stat. When a change is detected (e.g., modification time or file size), the command specified by the user is executed.

To save system resources, a delay is used (specified in seconds), which allows watch to intermittenly check for file changes. This approach also prevents multiple rapid executions if several changes are made rapidly.

The pattern (e.g., '*.go', '*' or a file name) specifies which files to watch. If the pattern is meant to be globbed it needs to be quoted to prevent the shell from interpreting it. Watch only takes one pattern as an argument.

The command to be executed needs to exist in `$PATH` or a full file path is required. If one or more unescaped `%` exists in the arguments list it will be replaced with the file path of the file that was modified.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL