Librarian runs pre-configured commands against a group of files that match a set of filters. The group of files is called a library. Librarian can either search for files in a library or watch for when files in the library are created or updated.
To run Librarian once, where it exits after searching through a list of configured libraries, run:
sh
fs-librarian single-shot path/to/config.toml
To make Librarian continually watch for when files in configured libraries are created or updated, run:
sh
fs-librarian watch path/to/config.toml
You can use the pre-built binaries on the release page or build Librarian on your own. To build Librarian, make sure you have Rust installed on your machine (installation instructions are here) then run:
sh
make clean build
The binary target/release/fs-librarian
will be generated.
An example configuration file can be found here.
In the Librarian configuration file, define one or more "libraries" of files. A library is a set of files that match defined search filters. Supported search filters are:
For each of the defined libraries, provide a Tera template (whose syntax is based on Jinja2) of the command that should run when a file is found. The following variables are available to the template:
{{ file_path }}
: The path to the file that was found{{ mime_type }}
: The MIME type for the file that was found. Run the fs-librarian test mime <path to a file>
command to display the MIME types of files you are unsure about.The following configuration snippet defines a music library which watches for files inside the Downloads and /tmp directories that have MIME types matching the audio/.+
regex (e.g. audio/flac
and audio/ogg
). When an audio file is found, it is moved to the Music directory:
```toml [libraries.music] command = """ mv "{{ file_path }}" /home/jrogena/Music/ """
[libraries.music.filter] directories = [ "/home/jrogena/Downloads", "/tmp" ] mimetyperegexes = [ "audio/.+" ] ```
The following configurations, related to filesystem watching, are available:
min_command_exec_freq
: Optional. The minimum frequency (in seconds) between running the configured command against a file. Useful in situations where a file is updated frequently but you don't want Librarian to run against the file as frequently as it is updated.
The following snippet is an example filesystem watching configuration:
toml
[fs_watch]
min_command_exec_freq = 60
Consider the following when using Librarian:
IN_CREATE
and IN_CLOSE_WRITE
on Linux) when a file is changed. You can avoid the pre-configured command from running more than once for every file update using the min_command_exec_freq
option.