Add --quiet, --timings, --colo[u]r, --bell (#698)
This commit is contained in:
parent
16e606e944
commit
9af9189ac4
|
@ -3078,6 +3078,15 @@ dependencies = [
|
|||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "terminal_size"
|
||||
version = "0.1.17"
|
||||
|
@ -3697,6 +3706,7 @@ dependencies = [
|
|||
"project-origins",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"termcolor",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
|
|
|
@ -19,7 +19,7 @@ _watchexec() {
|
|||
|
||||
case "${cmd}" in
|
||||
watchexec)
|
||||
opts="-w -c -o -W -r -s -k -d -p -n -E -1 -N -e -f -i -v -h -V --watch --clear --on-busy-update --watch-when-idle --restart --signal --kill --stop-signal --stop-timeout --debounce --stdin-quit --no-vcs-ignore --no-project-ignore --no-global-ignore --no-default-ignore --no-discover-ignore --ignore-nothing --postpone --delay-run --poll --shell --no-shell-long --no-environment --emit-events-to --only-emit-events --env --no-process-group --notify --project-origin --workdir --exts --filter --filter-file --ignore --ignore-file --fs-events --no-meta --print-events --verbose --log-file --manual --completions --help --version [COMMAND]..."
|
||||
opts="-w -c -o -W -r -s -k -d -p -n -E -1 -N -q -e -f -i -v -h -V --watch --clear --on-busy-update --watch-when-idle --restart --signal --kill --stop-signal --stop-timeout --debounce --stdin-quit --no-vcs-ignore --no-project-ignore --no-global-ignore --no-default-ignore --no-discover-ignore --ignore-nothing --postpone --delay-run --poll --shell --no-shell-long --no-environment --emit-events-to --only-emit-events --env --no-process-group --notify --color --timings --quiet --bell --project-origin --workdir --exts --filter --filter-file --ignore --ignore-file --fs-events --no-meta --print-events --verbose --log-file --manual --completions --help --version [COMMAND]..."
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
@ -97,6 +97,10 @@ _watchexec() {
|
|||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--color)
|
||||
COMPREPLY=($(compgen -W "auto always never" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--project-origin)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
|
|
|
@ -36,6 +36,7 @@ set edit:completion:arg-completer[watchexec] = {|@words|
|
|||
cand --emit-events-to 'Configure event emission'
|
||||
cand -E 'Add env vars to the command'
|
||||
cand --env 'Add env vars to the command'
|
||||
cand --color 'When to use terminal colours'
|
||||
cand --project-origin 'Set the project origin'
|
||||
cand --workdir 'Set the working directory'
|
||||
cand -e 'Filename extensions to filter to'
|
||||
|
@ -72,6 +73,10 @@ set edit:completion:arg-completer[watchexec] = {|@words|
|
|||
cand -1 'Testing only: exit Watchexec after the first run'
|
||||
cand -N 'Alert when commands start and end'
|
||||
cand --notify 'Alert when commands start and end'
|
||||
cand --timings 'Print how long the command took to run'
|
||||
cand -q 'Don''t print starting and stopping messages'
|
||||
cand --quiet 'Don''t print starting and stopping messages'
|
||||
cand --bell 'Ring the terminal bell on command completion'
|
||||
cand --no-meta 'Don''t emit fs events for metadata changes'
|
||||
cand --print-events 'Print events that trigger actions'
|
||||
cand -v 'Set diagnostic log level'
|
||||
|
|
|
@ -10,6 +10,7 @@ complete -c watchexec -l poll -d 'Poll for filesystem changes' -r
|
|||
complete -c watchexec -l shell -d 'Use a different shell' -r
|
||||
complete -c watchexec -l emit-events-to -d 'Configure event emission' -r -f -a "{environment '',stdin '',file '',json-stdin '',json-file '',none ''}"
|
||||
complete -c watchexec -s E -l env -d 'Add env vars to the command' -r
|
||||
complete -c watchexec -l color -d 'When to use terminal colours' -r -f -a "{auto '',always '',never ''}"
|
||||
complete -c watchexec -l project-origin -d 'Set the project origin' -r -f -a "(__fish_complete_directories)"
|
||||
complete -c watchexec -l workdir -d 'Set the working directory' -r -f -a "(__fish_complete_directories)"
|
||||
complete -c watchexec -s e -l exts -d 'Filename extensions to filter to' -r
|
||||
|
@ -38,6 +39,9 @@ complete -c watchexec -l only-emit-events -d 'Only emit events to stdout, run no
|
|||
complete -c watchexec -l no-process-group -d 'Don\'t use a process group'
|
||||
complete -c watchexec -s 1 -d 'Testing only: exit Watchexec after the first run'
|
||||
complete -c watchexec -s N -l notify -d 'Alert when commands start and end'
|
||||
complete -c watchexec -l timings -d 'Print how long the command took to run'
|
||||
complete -c watchexec -s q -l quiet -d 'Don\'t print starting and stopping messages'
|
||||
complete -c watchexec -l bell -d 'Ring the terminal bell on command completion'
|
||||
complete -c watchexec -l no-meta -d 'Don\'t emit fs events for metadata changes'
|
||||
complete -c watchexec -l print-events -d 'Print events that trigger actions'
|
||||
complete -c watchexec -s v -l verbose -d 'Set diagnostic log level'
|
||||
|
|
|
@ -12,6 +12,10 @@ module completions {
|
|||
[ "environment" "stdin" "file" "json-stdin" "json-file" "none" ]
|
||||
}
|
||||
|
||||
def "nu-complete watchexec color" [] {
|
||||
[ "auto" "always" "never" ]
|
||||
}
|
||||
|
||||
def "nu-complete watchexec filter_fs_events" [] {
|
||||
[ "access" "create" "remove" "rename" "modify" "metadata" ]
|
||||
}
|
||||
|
@ -53,6 +57,10 @@ module completions {
|
|||
--no-process-group # Don't use a process group
|
||||
-1 # Testing only: exit Watchexec after the first run
|
||||
--notify(-N) # Alert when commands start and end
|
||||
--color: string@"nu-complete watchexec color" # When to use terminal colours
|
||||
--timings # Print how long the command took to run
|
||||
--quiet(-q) # Don't print starting and stopping messages
|
||||
--bell # Ring the terminal bell on command completion
|
||||
--project-origin: string # Set the project origin
|
||||
--workdir: string # Set the working directory
|
||||
--exts(-e): string # Filename extensions to filter to
|
||||
|
|
|
@ -39,6 +39,7 @@ Register-ArgumentCompleter -Native -CommandName 'watchexec' -ScriptBlock {
|
|||
[CompletionResult]::new('--emit-events-to', 'emit-events-to', [CompletionResultType]::ParameterName, 'Configure event emission')
|
||||
[CompletionResult]::new('-E', 'E ', [CompletionResultType]::ParameterName, 'Add env vars to the command')
|
||||
[CompletionResult]::new('--env', 'env', [CompletionResultType]::ParameterName, 'Add env vars to the command')
|
||||
[CompletionResult]::new('--color', 'color', [CompletionResultType]::ParameterName, 'When to use terminal colours')
|
||||
[CompletionResult]::new('--project-origin', 'project-origin', [CompletionResultType]::ParameterName, 'Set the project origin')
|
||||
[CompletionResult]::new('--workdir', 'workdir', [CompletionResultType]::ParameterName, 'Set the working directory')
|
||||
[CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'Filename extensions to filter to')
|
||||
|
@ -75,6 +76,10 @@ Register-ArgumentCompleter -Native -CommandName 'watchexec' -ScriptBlock {
|
|||
[CompletionResult]::new('-1', '1', [CompletionResultType]::ParameterName, 'Testing only: exit Watchexec after the first run')
|
||||
[CompletionResult]::new('-N', 'N ', [CompletionResultType]::ParameterName, 'Alert when commands start and end')
|
||||
[CompletionResult]::new('--notify', 'notify', [CompletionResultType]::ParameterName, 'Alert when commands start and end')
|
||||
[CompletionResult]::new('--timings', 'timings', [CompletionResultType]::ParameterName, 'Print how long the command took to run')
|
||||
[CompletionResult]::new('-q', 'q', [CompletionResultType]::ParameterName, 'Don''t print starting and stopping messages')
|
||||
[CompletionResult]::new('--quiet', 'quiet', [CompletionResultType]::ParameterName, 'Don''t print starting and stopping messages')
|
||||
[CompletionResult]::new('--bell', 'bell', [CompletionResultType]::ParameterName, 'Ring the terminal bell on command completion')
|
||||
[CompletionResult]::new('--no-meta', 'no-meta', [CompletionResultType]::ParameterName, 'Don''t emit fs events for metadata changes')
|
||||
[CompletionResult]::new('--print-events', 'print-events', [CompletionResultType]::ParameterName, 'Print events that trigger actions')
|
||||
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Set diagnostic log level')
|
||||
|
|
|
@ -33,6 +33,7 @@ _watchexec() {
|
|||
'--emit-events-to=[Configure event emission]:MODE:(environment stdin file json-stdin json-file none)' \
|
||||
'*-E+[Add env vars to the command]:KEY=VALUE: ' \
|
||||
'*--env=[Add env vars to the command]:KEY=VALUE: ' \
|
||||
'--color=[When to use terminal colours]:MODE:(auto always never)' \
|
||||
'--project-origin=[Set the project origin]:DIRECTORY:_files -/' \
|
||||
'--workdir=[Set the working directory]:DIRECTORY:_files -/' \
|
||||
'*-e+[Filename extensions to filter to]:EXTENSIONS: ' \
|
||||
|
@ -69,6 +70,10 @@ _watchexec() {
|
|||
'-1[Testing only\: exit Watchexec after the first run]' \
|
||||
'-N[Alert when commands start and end]' \
|
||||
'--notify[Alert when commands start and end]' \
|
||||
'--timings[Print how long the command took to run]' \
|
||||
'-q[Don'\''t print starting and stopping messages]' \
|
||||
'--quiet[Don'\''t print starting and stopping messages]' \
|
||||
'--bell[Ring the terminal bell on command completion]' \
|
||||
'(--fs-events)--no-meta[Don'\''t emit fs events for metadata changes]' \
|
||||
'--print-events[Print events that trigger actions]' \
|
||||
'*-v[Set diagnostic log level]' \
|
||||
|
|
|
@ -33,6 +33,7 @@ is-terminal = "0.4.4"
|
|||
notify-rust = "4.9.0"
|
||||
serde_json = "1.0.107"
|
||||
tempfile = "3.8.1"
|
||||
termcolor = "1.4.0"
|
||||
tracing = "0.1.40"
|
||||
which = "5.0.0"
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use watchexec_signals::Signal;
|
|||
const OPTSET_FILTERING: &str = "Filtering";
|
||||
const OPTSET_COMMAND: &str = "Command";
|
||||
const OPTSET_DEBUGGING: &str = "Debugging";
|
||||
const OPTSET_OUTPUT: &str = "Output";
|
||||
|
||||
include!(env!("BOSION_PATH"));
|
||||
|
||||
|
@ -122,6 +123,7 @@ pub struct Args {
|
|||
#[arg(
|
||||
short = 'c',
|
||||
long = "clear",
|
||||
help_heading = OPTSET_OUTPUT,
|
||||
num_args = 0..=1,
|
||||
default_missing_value = "clear",
|
||||
value_name = "MODE",
|
||||
|
@ -603,7 +605,7 @@ pub struct Args {
|
|||
/// of the command.
|
||||
#[arg(
|
||||
long,
|
||||
help_heading = OPTSET_COMMAND,
|
||||
help_heading = OPTSET_OUTPUT,
|
||||
conflicts_with_all = ["command", "completions", "manual"],
|
||||
)]
|
||||
pub only_emit_events: bool,
|
||||
|
@ -641,9 +643,51 @@ pub struct Args {
|
|||
///
|
||||
/// With this, Watchexec will emit a desktop notification when a command starts and ends, on
|
||||
/// supported platforms. On unsupported platforms, it may silently do nothing, or log a warning.
|
||||
#[arg(long, short = 'N')]
|
||||
#[arg(
|
||||
short = 'N',
|
||||
long,
|
||||
help_heading = OPTSET_OUTPUT,
|
||||
)]
|
||||
pub notify: bool,
|
||||
|
||||
/// When to use terminal colours
|
||||
#[arg(
|
||||
long,
|
||||
help_heading = OPTSET_OUTPUT,
|
||||
default_value = "auto",
|
||||
value_name = "MODE",
|
||||
alias = "colour",
|
||||
)]
|
||||
pub color: ColourMode,
|
||||
|
||||
/// Print how long the command took to run
|
||||
///
|
||||
/// This may not be exactly accurate, as it includes some overhead from Watchexec itself. Use
|
||||
/// the `time` utility, high-precision timers, or benchmarking tools for more accurate results.
|
||||
#[arg(
|
||||
long,
|
||||
help_heading = OPTSET_OUTPUT,
|
||||
)]
|
||||
pub timings: bool,
|
||||
|
||||
/// Don't print starting and stopping messages
|
||||
///
|
||||
/// By default Watchexec will print a message when the command starts and stops. This option
|
||||
/// disables this behaviour, so only the command's output, warnings, and errors will be printed.
|
||||
#[arg(
|
||||
short,
|
||||
long,
|
||||
help_heading = OPTSET_OUTPUT,
|
||||
)]
|
||||
pub quiet: bool,
|
||||
|
||||
/// Ring the terminal bell on command completion
|
||||
#[arg(
|
||||
long,
|
||||
help_heading = OPTSET_OUTPUT,
|
||||
)]
|
||||
pub bell: bool,
|
||||
|
||||
/// Set the project origin
|
||||
///
|
||||
/// Watchexec will attempt to discover the project's "origin" (or "root") by searching for a
|
||||
|
@ -893,7 +937,7 @@ pub enum FsEvent {
|
|||
Metadata,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, ValueEnum)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
|
||||
pub enum ShellCompletion {
|
||||
Bash,
|
||||
Elvish,
|
||||
|
@ -903,6 +947,13 @@ pub enum ShellCompletion {
|
|||
Zsh,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
|
||||
pub enum ColourMode {
|
||||
Auto,
|
||||
Always,
|
||||
Never,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TimeSpan<const UNITLESS_NANOS_MULTIPLIER: u64 = { 1_000_000_000 }>(pub Duration);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::{
|
|||
env::current_dir,
|
||||
ffi::{OsStr, OsString},
|
||||
fs::File,
|
||||
io::{stderr, IsTerminal, Write},
|
||||
path::Path,
|
||||
process::Stdio,
|
||||
sync::Arc,
|
||||
|
@ -12,6 +13,7 @@ use std::{
|
|||
use clearscreen::ClearScreen;
|
||||
use miette::{miette, IntoDiagnostic, Report, Result};
|
||||
use notify_rust::Notification;
|
||||
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
|
||||
use tokio::{process::Command as TokioCommand, time::sleep};
|
||||
use tracing::{debug, debug_span, error};
|
||||
use watchexec::{
|
||||
|
@ -24,11 +26,20 @@ use watchexec::{
|
|||
use watchexec_events::{Event, Keyboard, ProcessEnd, Tag};
|
||||
use watchexec_signals::Signal;
|
||||
|
||||
use crate::{state::State, emits::events_to_simple_format};
|
||||
use crate::{
|
||||
args::{Args, ClearMode, EmitEvents, OnBusyUpdate},
|
||||
args::{Args, ClearMode, ColourMode, EmitEvents, OnBusyUpdate},
|
||||
state::RotatingTempFile,
|
||||
};
|
||||
use crate::{emits::events_to_simple_format, state::State};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct OutputFlags {
|
||||
quiet: bool,
|
||||
colour: ColorChoice,
|
||||
timings: bool,
|
||||
bell: bool,
|
||||
toast: bool,
|
||||
}
|
||||
|
||||
pub fn make_config(args: &Args, state: &State) -> Result<Config> {
|
||||
let _span = debug_span!("args-runtime").entered();
|
||||
|
@ -82,7 +93,10 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
|
|||
if args.only_emit_events {
|
||||
config.on_action(move |mut action| {
|
||||
// if we got a terminate or interrupt signal, quit
|
||||
if action.signals().any(|sig| sig == Signal::Terminate || sig == Signal::Interrupt) {
|
||||
if action
|
||||
.signals()
|
||||
.any(|sig| sig == Signal::Terminate || sig == Signal::Interrupt)
|
||||
{
|
||||
action.quit();
|
||||
return action;
|
||||
}
|
||||
|
@ -109,14 +123,20 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
|
|||
|
||||
match emit_events_to {
|
||||
EmitEvents::Stdin => {
|
||||
println!("{}", events_to_simple_format(action.events.as_ref()).unwrap_or_default());
|
||||
println!(
|
||||
"{}",
|
||||
events_to_simple_format(action.events.as_ref()).unwrap_or_default()
|
||||
);
|
||||
}
|
||||
EmitEvents::JsonStdin => {
|
||||
for event in action.events.iter().filter(|e| !e.is_empty()) {
|
||||
println!("{}", serde_json::to_string(event).unwrap_or_default());
|
||||
}
|
||||
}
|
||||
other => unreachable!("emit_events_to should have been validated earlier: {:?}", other),
|
||||
other => unreachable!(
|
||||
"emit_events_to should have been validated earlier: {:?}",
|
||||
other
|
||||
),
|
||||
}
|
||||
|
||||
action
|
||||
|
@ -132,8 +152,19 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
|
|||
let stop_signal = args.stop_signal;
|
||||
let stop_timeout = args.stop_timeout.0;
|
||||
|
||||
let notif = args.notify;
|
||||
let print_events = args.print_events;
|
||||
let outflags = OutputFlags {
|
||||
quiet: args.quiet,
|
||||
colour: match args.color {
|
||||
ColourMode::Auto if !std::io::stdin().is_terminal() => ColorChoice::Never,
|
||||
ColourMode::Auto => ColorChoice::Auto,
|
||||
ColourMode::Always => ColorChoice::Always,
|
||||
ColourMode::Never => ColorChoice::Never,
|
||||
},
|
||||
timings: args.timings,
|
||||
bell: args.bell,
|
||||
toast: args.notify,
|
||||
};
|
||||
|
||||
let workdir = Arc::new(args.workdir.clone());
|
||||
|
||||
|
@ -282,7 +313,7 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
|
|||
setup_process(
|
||||
innerjob.clone(),
|
||||
context.command.clone(),
|
||||
notif,
|
||||
outflags,
|
||||
)
|
||||
});
|
||||
}
|
||||
|
@ -295,7 +326,7 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
|
|||
setup_process(
|
||||
innerjob.clone(),
|
||||
context.command.clone(),
|
||||
notif,
|
||||
outflags,
|
||||
)
|
||||
});
|
||||
}
|
||||
|
@ -308,7 +339,7 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
|
|||
setup_process(
|
||||
innerjob.clone(),
|
||||
context.command.clone(),
|
||||
notif,
|
||||
outflags,
|
||||
)
|
||||
});
|
||||
});
|
||||
|
@ -317,7 +348,7 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
|
|||
} else {
|
||||
job.start();
|
||||
job.run(move |context| {
|
||||
setup_process(innerjob.clone(), context.command.clone(), notif)
|
||||
setup_process(innerjob.clone(), context.command.clone(), outflags)
|
||||
});
|
||||
}
|
||||
})
|
||||
|
@ -396,11 +427,12 @@ fn interpret_command_args(args: &Args) -> Result<Arc<Command>> {
|
|||
|
||||
#[cfg(windows)]
|
||||
fn available_powershell() -> String {
|
||||
// TODO
|
||||
todo!("figure out if powershell.exe is available, and use that, otherwise use pwsh.exe")
|
||||
}
|
||||
|
||||
fn setup_process(job: Job, command: Arc<Command>, notif: bool) {
|
||||
if notif {
|
||||
fn setup_process(job: Job, command: Arc<Command>, outflags: OutputFlags) {
|
||||
if outflags.toast {
|
||||
Notification::new()
|
||||
.summary("Watchexec: change detected")
|
||||
.body(&format!("Running {command}"))
|
||||
|
@ -413,13 +445,23 @@ fn setup_process(job: Job, command: Arc<Command>, notif: bool) {
|
|||
);
|
||||
}
|
||||
|
||||
if !outflags.quiet {
|
||||
let mut stderr = StandardStream::stderr(outflags.colour);
|
||||
stderr.reset().ok();
|
||||
stderr
|
||||
.set_color(ColorSpec::new().set_fg(Some(Color::Green)))
|
||||
.ok();
|
||||
writeln!(&mut stderr, "[Running: {command}]").ok();
|
||||
stderr.reset().ok();
|
||||
}
|
||||
|
||||
tokio::spawn(async move {
|
||||
job.to_wait().await;
|
||||
job.run(move |context| end_of_process(context.current, notif));
|
||||
job.run(move |context| end_of_process(context.current, outflags));
|
||||
});
|
||||
}
|
||||
|
||||
fn end_of_process(state: &CommandState, notif: bool) {
|
||||
fn end_of_process(state: &CommandState, outflags: OutputFlags) {
|
||||
let CommandState::Finished {
|
||||
status,
|
||||
started,
|
||||
|
@ -430,24 +472,26 @@ fn end_of_process(state: &CommandState, notif: bool) {
|
|||
};
|
||||
|
||||
let duration = *finished - *started;
|
||||
let msg = match status {
|
||||
ProcessEnd::ExitError(code) => {
|
||||
format!("Command exited with {code}, lasted {duration:?}")
|
||||
}
|
||||
let timing = if outflags.timings {
|
||||
format!(", lasted {duration:?}")
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
let (msg, fg) = match status {
|
||||
ProcessEnd::ExitError(code) => (format!("Command exited with {code}{timing}"), Color::Red),
|
||||
ProcessEnd::ExitSignal(sig) => {
|
||||
format!("Command killed by {sig:?}, lasted {duration:?}")
|
||||
(format!("Command killed by {sig:?}{timing}"), Color::Magenta)
|
||||
}
|
||||
ProcessEnd::ExitStop(sig) => {
|
||||
format!("Command stopped by {sig:?}, lasted {duration:?}")
|
||||
}
|
||||
ProcessEnd::Continued => format!("Command continued, lasted {duration:?}"),
|
||||
ProcessEnd::Exception(ex) => {
|
||||
format!("Command ended by exception {ex:#x}, lasted {duration:?}")
|
||||
}
|
||||
ProcessEnd::Success => format!("Command was successful, lasted {duration:?}"),
|
||||
ProcessEnd::ExitStop(sig) => (format!("Command stopped by {sig:?}{timing}"), Color::Blue),
|
||||
ProcessEnd::Continued => (format!("Command continued{timing}"), Color::Cyan),
|
||||
ProcessEnd::Exception(ex) => (
|
||||
format!("Command ended by exception {ex:#x}{timing}"),
|
||||
Color::Yellow,
|
||||
),
|
||||
ProcessEnd::Success => (format!("Command was successful{timing}"), Color::Green),
|
||||
};
|
||||
|
||||
if notif {
|
||||
if outflags.toast {
|
||||
Notification::new()
|
||||
.summary("Watchexec: command ended")
|
||||
.body(&msg)
|
||||
|
@ -459,6 +503,19 @@ fn end_of_process(state: &CommandState, notif: bool) {
|
|||
drop,
|
||||
);
|
||||
}
|
||||
|
||||
if !outflags.quiet {
|
||||
let mut stderr = StandardStream::stderr(outflags.colour);
|
||||
stderr.reset().ok();
|
||||
stderr.set_color(ColorSpec::new().set_fg(Some(fg))).ok();
|
||||
writeln!(&mut stderr, "[{msg}]").ok();
|
||||
stderr.reset().ok();
|
||||
}
|
||||
|
||||
if outflags.bell {
|
||||
eprint!("\x07");
|
||||
stderr().flush().ok();
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_events_to_command(
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
.SH NAME
|
||||
watchexec \- Execute commands when watched files change
|
||||
.SH SYNOPSIS
|
||||
\fBwatchexec\fR [\fB\-w\fR|\fB\-\-watch\fR] [\fB\-c\fR|\fB\-\-clear\fR] [\fB\-o\fR|\fB\-\-on\-busy\-update\fR] [\fB\-r\fR|\fB\-\-restart\fR] [\fB\-s\fR|\fB\-\-signal\fR] [\fB\-\-stop\-signal\fR] [\fB\-\-stop\-timeout\fR] [\fB\-d\fR|\fB\-\-debounce\fR] [\fB\-\-stdin\-quit\fR] [\fB\-\-no\-vcs\-ignore\fR] [\fB\-\-no\-project\-ignore\fR] [\fB\-\-no\-global\-ignore\fR] [\fB\-\-no\-default\-ignore\fR] [\fB\-\-no\-discover\-ignore\fR] [\fB\-\-ignore\-nothing\fR] [\fB\-p\fR|\fB\-\-postpone\fR] [\fB\-\-delay\-run\fR] [\fB\-\-poll\fR] [\fB\-\-shell\fR] [\fB\-n \fR] [\fB\-\-no\-environment\fR] [\fB\-\-emit\-events\-to\fR] [\fB\-\-only\-emit\-events\fR] [\fB\-E\fR|\fB\-\-env\fR] [\fB\-\-no\-process\-group\fR] [\fB\-N\fR|\fB\-\-notify\fR] [\fB\-\-project\-origin\fR] [\fB\-\-workdir\fR] [\fB\-e\fR|\fB\-\-exts\fR] [\fB\-f\fR|\fB\-\-filter\fR] [\fB\-\-filter\-file\fR] [\fB\-i\fR|\fB\-\-ignore\fR] [\fB\-\-ignore\-file\fR] [\fB\-\-fs\-events\fR] [\fB\-\-no\-meta\fR] [\fB\-\-print\-events\fR] [\fB\-v\fR|\fB\-\-verbose\fR]... [\fB\-\-log\-file\fR] [\fB\-\-manual\fR] [\fB\-\-completions\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fICOMMAND\fR]
|
||||
\fBwatchexec\fR [\fB\-w\fR|\fB\-\-watch\fR] [\fB\-c\fR|\fB\-\-clear\fR] [\fB\-o\fR|\fB\-\-on\-busy\-update\fR] [\fB\-r\fR|\fB\-\-restart\fR] [\fB\-s\fR|\fB\-\-signal\fR] [\fB\-\-stop\-signal\fR] [\fB\-\-stop\-timeout\fR] [\fB\-d\fR|\fB\-\-debounce\fR] [\fB\-\-stdin\-quit\fR] [\fB\-\-no\-vcs\-ignore\fR] [\fB\-\-no\-project\-ignore\fR] [\fB\-\-no\-global\-ignore\fR] [\fB\-\-no\-default\-ignore\fR] [\fB\-\-no\-discover\-ignore\fR] [\fB\-\-ignore\-nothing\fR] [\fB\-p\fR|\fB\-\-postpone\fR] [\fB\-\-delay\-run\fR] [\fB\-\-poll\fR] [\fB\-\-shell\fR] [\fB\-n \fR] [\fB\-\-no\-environment\fR] [\fB\-\-emit\-events\-to\fR] [\fB\-\-only\-emit\-events\fR] [\fB\-E\fR|\fB\-\-env\fR] [\fB\-\-no\-process\-group\fR] [\fB\-N\fR|\fB\-\-notify\fR] [\fB\-\-color\fR] [\fB\-\-timings\fR] [\fB\-q\fR|\fB\-\-quiet\fR] [\fB\-\-bell\fR] [\fB\-\-project\-origin\fR] [\fB\-\-workdir\fR] [\fB\-e\fR|\fB\-\-exts\fR] [\fB\-f\fR|\fB\-\-filter\fR] [\fB\-\-filter\-file\fR] [\fB\-i\fR|\fB\-\-ignore\fR] [\fB\-\-ignore\-file\fR] [\fB\-\-fs\-events\fR] [\fB\-\-no\-meta\fR] [\fB\-\-print\-events\fR] [\fB\-v\fR|\fB\-\-verbose\fR]... [\fB\-\-log\-file\fR] [\fB\-\-manual\fR] [\fB\-\-completions\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fICOMMAND\fR]
|
||||
.SH DESCRIPTION
|
||||
Execute commands when watched files change.
|
||||
.PP
|
||||
|
@ -372,6 +372,22 @@ Alert when commands start and end
|
|||
|
||||
With this, Watchexec will emit a desktop notification when a command starts and ends, on supported platforms. On unsupported platforms, it may silently do nothing, or log a warning.
|
||||
.TP
|
||||
\fB\-\-color\fR=\fIMODE\fR [default: auto]
|
||||
When to use terminal colours
|
||||
.TP
|
||||
\fB\-\-timings\fR
|
||||
Print how long the command took to run
|
||||
|
||||
This may not be exactly accurate, as it includes some overhead from Watchexec itself. Use the `time` utility, high\-precision timers, or benchmarking tools for more accurate results.
|
||||
.TP
|
||||
\fB\-q\fR, \fB\-\-quiet\fR
|
||||
Don\*(Aqt print starting and stopping messages
|
||||
|
||||
By default Watchexec will print a message when the command starts and stops. This option disables this behaviour, so only the command\*(Aqs output, warnings, and errors will be printed.
|
||||
.TP
|
||||
\fB\-\-bell\fR
|
||||
Ring the terminal bell on command completion
|
||||
.TP
|
||||
\fB\-\-project\-origin\fR=\fIDIRECTORY\fR
|
||||
Set the project origin
|
||||
|
||||
|
|
|
@ -15,10 +15,11 @@ watchexec - Execute commands when watched files change
|
|||
\[**\--shell**\] \[**-n **\] \[**\--no-environment**\]
|
||||
\[**\--emit-events-to**\] \[**\--only-emit-events**\]
|
||||
\[**-E**\|**\--env**\] \[**\--no-process-group**\]
|
||||
\[**-N**\|**\--notify**\] \[**\--project-origin**\] \[**\--workdir**\]
|
||||
\[**-e**\|**\--exts**\] \[**-f**\|**\--filter**\] \[**\--filter-file**\]
|
||||
\[**-i**\|**\--ignore**\] \[**\--ignore-file**\] \[**\--fs-events**\]
|
||||
\[**\--no-meta**\] \[**\--print-events**\]
|
||||
\[**-N**\|**\--notify**\] \[**\--color**\] \[**\--timings**\]
|
||||
\[**-q**\|**\--quiet**\] \[**\--bell**\] \[**\--project-origin**\]
|
||||
\[**\--workdir**\] \[**-e**\|**\--exts**\] \[**-f**\|**\--filter**\]
|
||||
\[**\--filter-file**\] \[**-i**\|**\--ignore**\] \[**\--ignore-file**\]
|
||||
\[**\--fs-events**\] \[**\--no-meta**\] \[**\--print-events**\]
|
||||
\[**-v**\|**\--verbose**\]\... \[**\--log-file**\] \[**\--manual**\]
|
||||
\[**\--completions**\] \[**-h**\|**\--help**\]
|
||||
\[**-V**\|**\--version**\] \[*COMMAND*\]
|
||||
|
@ -508,6 +509,30 @@ With this, Watchexec will emit a desktop notification when a command
|
|||
starts and ends, on supported platforms. On unsupported platforms, it
|
||||
may silently do nothing, or log a warning.
|
||||
|
||||
**\--color**=*MODE* \[default: auto\]
|
||||
|
||||
: When to use terminal colours
|
||||
|
||||
**\--timings**
|
||||
|
||||
: Print how long the command took to run
|
||||
|
||||
This may not be exactly accurate, as it includes some overhead from
|
||||
Watchexec itself. Use the \`time\` utility, high-precision timers, or
|
||||
benchmarking tools for more accurate results.
|
||||
|
||||
**-q**, **\--quiet**
|
||||
|
||||
: Dont print starting and stopping messages
|
||||
|
||||
By default Watchexec will print a message when the command starts and
|
||||
stops. This option disables this behaviour, so only the commands output,
|
||||
warnings, and errors will be printed.
|
||||
|
||||
**\--bell**
|
||||
|
||||
: Ring the terminal bell on command completion
|
||||
|
||||
**\--project-origin**=*DIRECTORY*
|
||||
|
||||
: Set the project origin
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue