.\" .\" Copyright (c) 2012 Eric Radman .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above .\" copyright notice and this permission notice appear in all copies. .\" .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .Dd April 17 2018 $ .Dt ENTR 1 .Os .Sh NAME .Nm entr .Nd run arbitrary commands when files change .Sh SYNOPSIS .Nm .Op Fl cdprs .Ar utility .Op Ar argument /_ ... .Sh DESCRIPTION A list of files provided on the standard input and the .Ar utility is executed using the supplied arguments if any of them change. .Nm waits for the child process to finish before responding to subsequent file system events. A TTY is also opened before entering the watch loop in order to support interactive utilities. .Pp The arguments are as follows: .Bl -tag -width Ds .It Fl c Execute .Pa /usr/bin/clear before invoking the .Ar utility specified on the command line. .It Fl d Track the directories of regular files provided as input and exit if a new file is added. This option also enables directories to be specified explicitly. Files with names beginning with .Ql \&. are ignored. .It Fl n Run in non-interactive mode. In this mode .Nm entr does not attempt to read from the TTY or change its properties. .It Fl p Postpone the first execution of the .Ar utility until a file is modified. .It Fl r Reload a persistent child process. As with the standard mode of operation, a .Ar utility which terminates is not executed again until a file system or keyboard event is processed. .Dv SIGTERM is used to terminate the .Ar utility before it is restarted. A process group is created to prevent shell scripts from masking signals. .Nm waits for the .Ar utility to exit to ensure that resources such as sockets have been closed. Control of the TTY is not transferred the child process. .It Fl s Evaluate the first argument using the interpreter specified by the .Ev SHELL environment variable. When this flag is set, the name of the shell and exit code is printed after each invocation. .El .Pp The first argument named .Ar /_ is replaced with the absolute path of the first file to trigger an event. If the restart option is used the first file under watch is treated as the default. .Sh COMMANDS .Nm listens for keyboard input and responds to the following commands: .Bl -tag -width Ic .It SPACE Execute the utility immediately. If the .Ql -r option is set this will terminate and restart the child process as if a file change event had occurred. .It q Quit; equivalent pressing Ctrl\-C. .El .Sh ENVIRONMENT If .Ev PAGER is undefined, .Nm will assign .Pa /bin/cat to prevent interactive utilities from waiting for keyboard input if output does not fit on the screen. .Pp If .Ev SHELL is undefined, .Nm entr will use .Pa /bin/sh . .Sh EXIT STATUS The .Nm utility exits with one of the following values: .Pp .Bl -tag -width Ds -offset indent -compact .It Li 0 .Dv SIGINT or .Dv SIGTERM was received .It Li 1 No regular files were provided as input or an error occurred .It Li 2 A file was added to a directory and the directory watch option was specified .El .Sh EXAMPLES Rebuild a project if source files change, limiting output to the first 20 lines: .Pp .Dl $ find src/ | entr -s 'make | head -n 20' .Pp Launch and auto-reload a node.js server: .Pp .Dl $ ls *.js | entr -r node app.js .Pp Launch and auto-reload a node.js server as a background task: .Pp .Dl $ (ls *.js | entr -r node app.js &) .Pp Clear the screen and run a query after the SQL script is updated: .Pp .Dl $ echo my.sql | entr -p psql -f /_ .Pp Rebuild project if a source file is modified or added to the src/ directory: .Pp .Dl $ while true; do ls src/*.rb | entr -d make; done