Crates.io | spyrun |
lib.rs | spyrun |
version | |
source | src |
created_at | 2024-08-17 03:03:18.112186 |
updated_at | 2024-10-12 05:11:27.18831 |
description | File watcher and command executor |
homepage | |
repository | https://github.com/yukimemi/spyrun |
max_upload_size | |
id | 1341207 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
spyrun is a tool that watches files and executes commands when specific events occur. It can watch for file modifications, additions, and more.
cargo install spyrun
spyrun operates using a configuration file.
> spyrun --help
Usage: spyrun.exe [OPTIONS]
Options:
-c, --config <FILE> Sets a custom config file [default: spyrun.toml]
-d, --debug... Turn debugging information on
-h, --help Print help
-V, --version Print version
spyrun's configuration file is in TOML format.
The default filename is spyrun.toml
, located in the same directory as the executable.
The configuration file specifies the files to watch, the commands to execute, and various other options.
[vars]
base = '{{ cwd }}/example'
hostname = '{{ env(arg="COMPUTERNAME") }}'
version = '20240407_125639'
fn_toast = '''
function Show-Toast {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][String]$title,
[Parameter(Mandatory=$true)][String]$message,
[Parameter(Mandatory=$true)][String]$detail
)
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
$app_id = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
$content = @"
<?xml version="1.0" encoding="utf-8"?>
<toast>
<visual>
<binding template="ToastGeneric">
<text>$($title)</text>
<text>$($message)</text>
<text>$($detail)</text>
</binding>
</visual>
</toast>
"@
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($content)
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($app_id).Show($toast)
}
'''
[cfg]
stop_flg = '{{ base }}/stop.flg'
stop_force_flg = '{{ base }}/stop.force.flg'
max_threads = 8
[log]
path = '{{ base }}/log/{{ cmd_stem }}.log'
level = 'info'
[init]
cmd = 'powershell'
arg = ['-NoProfile', '-Command', '''& {
{{ fn_toast }}
Show-Toast -title "spyrun {{ version }} on {{ hostname }}" -message "spyrun is running" -detail "spyrun path is {{ cmd_path }}. config path is {{ cfg_path }}."
}''']
# watch files and notifiy.
[[spys]]
name = 'toast'
input = '{{ base }}/watch_dir'
output = '{{ base }}/log'
[[spys.patterns]]
pattern = '\.txt$'
cmd = 'powershell'
arg = ['-NoProfile', '-Command', '''& {
{{ fn_toast }}
Show-Toast -title "{{ event_name }}" -message "{{ event_path }} is {{ event_kind }}" -detail "name: {{ event_name }}. dir: {{ event_dir }}"
}''']
Variables can be set freely. Variables are defined in alphabetical order. Therefore, it is necessary to pay attention to the order.
[vars]
a = "a"
b = "b and {{ a }}"
[vars]
a = "a and {{ b }}"
b = "b"
The file path to stop the spyrun. When it detects that this path has been created or modified, it completes all running operations and exits.
The file path to force stop the spyrun. When it detects that this path has been created or modified, it forces the spyrun to stop immediately.
The maximum number of threads to use in the spyrun. The default value is based on the number of CPU cores.
The path to the log file.
The log level.
The default value is info
.
You can specify the following values.
Init is executed when spyrun starts.
The command to execute.
The arguments to pass to the command.
The list of spy.
The name of the spy.
The list of events. Default value is ['Create', 'Modify']. You can specify the following values.
The path to watch.
The path to output. Standard output and standard error is written to this path.
If you want to watch the input path recursively, set this to true. Default value is false.
If you want to debounce execution, set this setting. Default value is 50 milliseconds.
If you want to throttle execution, set this setting. Default value is 0 milliseconds.
debounce or throttle is applied to this key. Default value is Display for CommandInfo.
The delay to wait before executing the command. Default value is 0 milliseconds.
Execute after 5000 milliseconds.
delay = [5000]
Waits randomly between 5000 milliseconds and 10000 milliseconds before executing.
delay = [5000, 10000]
The list of patterns.
The pattern to watch. This is a regular expression.
The command to execute.
The arguments to pass to the command.
If you want to watch the input path in a polling mode, set this setting.
The interval to watch the input path.
If you want to walk the input path, set this setting. If this is set, the input path is also walked when spyrun starts.
The minimum depth to walk the input path.
The maximum depth to walk the input path.
If you want to follow symlinks, set this setting.
The pattern to match the input path. This is a regular expression.
The delay to wait before walking the input path.
Walk after 5000 milliseconds.
delay = [5000]
Waits randomly between 5000 milliseconds and 10000 milliseconds.
delay = [5000, 10000]
spyrun is distributed under the MIT License.