Skip to content

Commit a8942aa

Browse files
committed
Fix watchexec execution of custom commands - they need to act as a shell, not a flat command. Also fix 'finished running' dialog
1 parent b8b0245 commit a8942aa

1 file changed

Lines changed: 23 additions & 20 deletions

File tree

src/bin/tectonic/v2cli.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use tectonic_bundles::Bundle;
2424
use tectonic_docmodel::workspace::{Workspace, WorkspaceCreator};
2525
use tectonic_status_base::plain::PlainStatusBackend;
2626
use tokio::runtime;
27+
use watchexec::event::ProcessEnd;
2728
use watchexec::{
2829
action::{Action, Outcome, PreSpawn},
2930
command::{Command, Shell},
@@ -537,12 +538,19 @@ impl WatchCommand {
537538
.into_string()
538539
.expect("Executable path wasn't valid UTF-8");
539540
let mut cmds = Vec::new();
541+
542+
#[cfg(windows)]
543+
let shell = Shell::Cmd;
544+
#[cfg(unix)]
545+
let shell = Shell::Unix("bash".to_string());
546+
540547
for x in self.execute.iter() {
541548
let x = x.trim();
542549
if !x.is_empty() {
543-
let cmd = Command::Exec {
544-
prog: exe_name.clone(),
545-
args: vec!["-X".to_string(), x.to_string()],
550+
let cmd = Command::Shell {
551+
shell: shell.clone(),
552+
args: vec![],
553+
command: format!("{exe_name} -X {}", x.to_string()),
546554
};
547555
cmds.push(cmd)
548556
}
@@ -555,23 +563,6 @@ impl WatchCommand {
555563
});
556564
}
557565

558-
#[cfg(windows)]
559-
let (shell, command) = (
560-
Shell::Cmd,
561-
"echo [Finished running. Exit status: %ERRORLEVEL%]",
562-
);
563-
#[cfg(unix)]
564-
let (shell, command) = (
565-
Shell::Unix("bash".to_string()),
566-
"echo [Finished running. Exit status: $?]",
567-
);
568-
569-
cmds.push(Command::Shell {
570-
shell,
571-
args: vec![],
572-
command: command.to_string(),
573-
});
574-
575566
let mut runtime_config = watchexec::config::RuntimeConfig::default();
576567
runtime_config.commands(cmds);
577568

@@ -611,6 +602,18 @@ impl WatchCommand {
611602
return Ok::<_, Infallible>(());
612603
}
613604

605+
for complete in event.completions() {
606+
match complete {
607+
Some(ProcessEnd::Success) => {
608+
println!("[Finished Running. Exit Status: 0]")
609+
}
610+
Some(ProcessEnd::ExitError(err)) => {
611+
println!("[Finished Running. Exit Status: {}]", err.get())
612+
}
613+
_ => (),
614+
}
615+
}
616+
614617
let paths = event.paths().collect::<Vec<_>>();
615618
if !paths.is_empty() {
616619
action.outcome(Outcome::IfRunning(

0 commit comments

Comments
 (0)