This avoids problems when the filter command is a substring of a entry command. Instead the filter will check the first element of the entry command (split by whitespace) and check if that element matches exactly. It will also check each command of each pipe instead of just the fist command used in a pipe.
For example the following will not match anymore:
» histdb-rs -c 'tr' --all-hosts
tmn cmd
2020-06-19 trayer --edge top --align right --width 10 --height 27 --monitor 0 --transparent
false --tint 0x00000000
But the following will now match
» histdb-rs -c 'tr' --all-hosts
tmn cmd
12:58 echo "test test" | tr -d ' '
To get the old behaviour use the regex matcher instead:
» cargo run -- -t '^tr.*' --all-hosts
tmn cmd
2020-06-19 trayer --edge top --align right --width 10 --height 27 --monitor 0 --transparent
false --tint 0x00000000
L3I6AA6NRA3KLTUADBDDKYYJUT3YS2R34XSVBBCK3XAY7YO3ZVJAC
}
fn filter_command(entry_command: &str, command: &str) -> bool {
entry_command
.split('|')
.map(|pipe_command| {
pipe_command
.split_whitespace()
.next()
.map_or(false, |entry_command| entry_command == command)
})
.any(|has_command| has_command)
}
}
#[cfg(test)]
mod test {
use super::Filter;
#[test]
fn filter_command() {
let cases = vec![
("tr -d ' '", true),
("echo 'tr'", false),
("echo 'test test' | tr -d ' '", true),
("echo 'test test' | echo tr -d ' '", false),
];
let command = "tr";
for case in cases {
assert_eq!(Filter::filter_command(case.0, command), case.1)
}