LinuxCommandLibrary

reflex

Tool to watch a directory and rerun a command when certain files change.

TLDR

Rebuild with make if any file changes

$ reflex make
copy


Compile and run Go application if any .go file changes
$ reflex --regex='[\.go$]' [go run .]
copy


Ignore a directory when watching for changes
$ reflex --inverse-regex='[^dir/]' [command]
copy


Run command when reflex starts and restarts on file changes
$ reflex --start-service=true [command]
copy


Substitute the filename that changed in
$ reflex -- echo {}
copy

SYNOPSIS

reflex [OPTIONS] [COMMAND]

DESCRIPTION

Reflex is a small tool to watch a directory and rerun a command when certain files change. It's great for automatically running compile/lint/test tasks and for reloading your application when the code changes.

OPTIONS

--all=True|False

Include normally ignored files (VCS and editor special files). Defaults to False.

-c, --config=FILE

A configuration file that describes how to run reflex (or '-' to read the configuration from stdin).

-d, --decoration=DECORATION

How to decorate command output. Choices: none, plain, fancy. Default is plain.

-g, --glob=GLOB_LIST

A shell glob expression to match filenames. (May be repeated.)

-G, --inverse-glob=GLOB_LIST

A shell glob expression to exclude matching filenames. (May be repeated.)

-R, --inverse-regex=REGEX

A regular expression to exclude matching filenames. (May be repeated.)

--only-dirs=True|False

Only match directories (not files). Defaults to false.

--only-files=True|False

Only match files (not directories). Defaults to false.

-r, --regex=REGEX

A regular expression to match filenames. (May be repeated.)

-e, --sequential=True|False

Don't run multiple commands at the same time. Defaults to false.

-t, --shutdown-timeout=TIMEOUT

Allow services this long to shut down. Defaults to 500ms.

-s, --start-service=True|False

Indicates that the command is a long-running process to be restarted on matching changes. Defaults to false.

--substitute=STRING

The substitution symbol that is replaced with the filename in a command. Defaults to "{}"

-v, --verbose=True|False

Verbose mode: print out more information about what reflex is doing. Defaults to false.

EXAMPLES

Print each .txt file if it changes:

reflex -r '\.txt$' echo {}

Run make(1) if any of the .c files in this directory change:

reflex -g '*.c' make

Build and run a server; rebuild and restart when .java files change:

reflex -r '\.java$' -s -- sh -c 'make && java bin/Server'

Copied to clipboard