diff --git a/completions/zsh b/completions/zsh
index cdf8328..2eb13da 100644
--- a/completions/zsh
+++ b/completions/zsh
@@ -13,6 +13,7 @@ args=(
'(-h --help)'{-h,--help}'[Prints help information]'
'(-k --kill)'{-k,--kill}'[Send SIGKILL to child processes (deprecated, use -s SIGKILL instead)]'
'(-n --no-shell)'{-n,--no-shell}'[Do not wrap command in ''sh -c'' resp. ''cmd.exe /C'']'
+ '--no-environment[Do not set WATCHEXEC_*_PATH environment variables for child process]'
'(-p --postpone)'{-p,--postpone}'[Wait until first change to execute command]'
'(-r --restart)'{-r,--restart}'[Restart the process if it''s still running]'
'(-V --version)'{-V,--version}'[Prints version information]'
diff --git a/doc/watchexec.1.html b/doc/watchexec.1.html
index c9b55de..1f9f242 100644
--- a/doc/watchexec.1.html
+++ b/doc/watchexec.1.html
@@ -90,6 +90,7 @@
-f
, --filter
patternIgnores modifications from paths that do not match pattern. This option can be specified multiple times, where a match on any given pattern causes the path to trigger command.
-s
, --signal
Sends the specified signal (e.g. SIGKILL
) to the child process. Defaults to SIGTERM
.
-n
, --no-shell
Execute command directly, do not wrap it in sh -c
resp. cmd.exe /C
. This is especially useful in combination with --signal
, as the signal is then send directly to the specified command. While --no-shell
is a little more performant than the default, it prevents using shell-features like pipes and redirects.
+--no-environment
Do not set WATCHEXEC_*_PATH environment variables for child process.
-i
, --ignore
patternIgnores modifications from paths that match pattern. This option can be specified multiple times, and a match on any pattern causes the path to be ignored.
-w
, --watch
pathMonitor a specific path for changes. By default, the current working directory is watched. This may be specified multiple times, where a change in any watched directory (and subdirectories) causes command to be executed.
-r
, --restart
Terminates the child process group if it is still running when subsequent file modifications are detected. By default, sends SIGTERM
; use --kill
to send SIGKILL
.
diff --git a/doc/watchexec.1.ronn b/doc/watchexec.1.ronn
index 7912607..c7f4d11 100644
--- a/doc/watchexec.1.ronn
+++ b/doc/watchexec.1.ronn
@@ -28,6 +28,9 @@ Sends the specified signal (e.g. `SIGKILL`) to the child process. Defaults to `S
* `-n`, `--no-shell`:
Execute command directly, do not wrap it in `sh -c` resp. `cmd.exe /C`. This is especially useful in combination with `--signal`, as the signal is then send directly to the specified command. While `--no-shell` is a little more performant than the default, it prevents using shell-features like pipes and redirects.
+* `--no-environment`:
+Do not set WATCHEXEC_*_PATH environment variables for child process.
+
* `-i`, `--ignore` :
Ignores modifications from paths that match . This option can be specified multiple times, and a match on any pattern causes the path to be ignored.
diff --git a/src/cli.rs b/src/cli.rs
index 90e4d89..dcef984 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -58,6 +58,9 @@ pub struct Args {
/// Do not wrap the commands in a shell.
#[builder(default)]
pub no_shell: bool,
+ /// Do not set WATCHEXEC_*_PATH environment variables for child process.
+ #[builder(default)]
+ pub no_environment: bool,
/// Skip auto-loading .gitignore files
#[builder(default)]
pub no_vcs_ignore: bool,
@@ -207,6 +210,9 @@ where
.help("Do not wrap command in 'sh -c' resp. 'cmd.exe /C'")
.short("n")
.long("no-shell"))
+ .arg(Arg::with_name("no-environment")
+ .help("Do not set WATCHEXEC_*_PATH environment variables for child process")
+ .long("no-environment"))
.arg(Arg::with_name("once").short("1").hidden(true))
.arg(Arg::with_name("watch-when-idle")
.help("Ignore events while the process is still running")
@@ -302,6 +308,7 @@ where
debug: args.is_present("verbose"),
run_initially: !args.is_present("postpone"),
no_shell: args.is_present("no-shell"),
+ no_environment: args.is_present("no-environment"),
no_vcs_ignore: args.is_present("no-vcs-ignore"),
no_ignore: args.is_present("no-ignore"),
once: args.is_present("once"),
diff --git a/src/process.rs b/src/process.rs
index 9b9185f..72cea33 100644
--- a/src/process.rs
+++ b/src/process.rs
@@ -5,8 +5,8 @@ use crate::pathop::PathOp;
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
-pub fn spawn(cmd: &[String], updated_paths: &[PathOp], no_shell: bool) -> Result {
- self::imp::Process::new(cmd, updated_paths, no_shell).map_err(|e| e.into())
+pub fn spawn(cmd: &[String], updated_paths: &[PathOp], no_shell: bool, no_environment: bool) -> Result {
+ self::imp::Process::new(cmd, updated_paths, no_shell, no_environment).map_err(|e| e.into())
}
pub use self::imp::Process;
@@ -83,7 +83,7 @@ mod imp {
#[allow(clippy::mutex_atomic)]
impl Process {
- pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool) -> Result {
+ pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool, no_environment: bool) -> Result {
use nix::unistd::*;
use std::convert::TryInto;
use std::os::unix::process::CommandExt;
@@ -107,7 +107,12 @@ mod imp {
debug!("Assembled command {:?}", command);
- let command_envs = super::collect_path_env_vars(updated_paths);
+ let command_envs = if no_environment {
+ Vec::new()
+ } else {
+ super::collect_path_env_vars(updated_paths)
+ };
+
for &(ref name, ref val) in &command_envs {
command.env(name, val);
}
@@ -229,7 +234,7 @@ mod imp {
}
impl Process {
- pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool) -> Result {
+ pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool, no_environment: bool) -> Result {
use std::convert::TryInto;
use std::os::windows::io::IntoRawHandle;
use std::os::windows::process::CommandExt;
@@ -304,7 +309,12 @@ mod imp {
command.creation_flags(CREATE_SUSPENDED);
debug!("Assembled command {:?}", command);
- let command_envs = super::collect_path_env_vars(updated_paths);
+ let command_envs = if no_environment {
+ Vec::new()
+ } else {
+ super::collect_path_env_vars(updated_paths)
+ };
+
for &(ref name, ref val) in &command_envs {
command.env(name, val);
}
diff --git a/src/run.rs b/src/run.rs
index 0a25e12..76e7ce0 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -185,7 +185,7 @@ impl ExecHandler {
debug!("Launching child process");
let mut guard = self.child_process.write()?;
- *guard = Some(process::spawn(&self.args.cmd, ops, self.args.no_shell)?);
+ *guard = Some(process::spawn(&self.args.cmd, ops, self.args.no_shell, self.args.no_environment)?);
Ok(())
}