blacknon / hwatch

A modern alternative to the watch command, records the differences in execution results and can check this differences at after.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Watching a command with pipe

trustin opened this issue · comments

Hi!

I'm trying to use hwatch for the following command:

ls | wc -l

I tried the following but none worked so far:

  • hwatch -- 'ls | wc -l'
  • hwatch -- ls '|' wc -l

Wow!

I also confirmed it.
Apparently, it seems to be a bug caused by the change in Version 0.3.5.
Thank you!!

The cause is that the processing at the time of command execution was changed in order to specify the -s option.

hwatch/src/exec.rs

Lines 58 to 90 in 4a94258

// split self.shell_command
let shell_commands =
shell_words::split(&self.shell_command).expect("shell command parse error.");
// set shell_command args, to exec_cmd_args.
exec_cmd = shell_commands[0].to_string();
if shell_commands.len() >= 2 {
let length = shell_commands.len();
let shell_command_args = shell_commands[1..length].to_vec();
// shell_command_args to exec_cmd_args
for shell_command_arg in shell_command_args {
let exec_cmd_arg: String;
if shell_command_arg.contains("{COMMAND}") {
exec_cmd_arg = str::replace(
&shell_command_arg,
crate::SHELL_COMMAND_EXECCMD,
&command_str,
);
is_shellcmd_template = true;
} else {
exec_cmd_arg = shell_command_arg;
}
// push exec_cmd_arg to exec_cmd_args
exec_cmd_args.push(exec_cmd_arg);
}
}
// add exec command..
if !is_shellcmd_template {
exec_cmd_args.push(command_str.clone());
}

We will fix it early.

NOTE:

The cause was that it was quoted by using shell_words :: join.

let command_str = shell_words::join(self.command.clone());

Thanks a lot for a very quick fix, @blacknon! 🙇 Just installed and confirmed the fix works.