#[macro_export]
macro_rules! run_shell {
(@cmd ($cmd:expr) -b, $($tail:tt)*) => {{
$crate::run_shell!(@cmd ({
$cmd.background()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -C, $($tail:tt)*) => {{
$crate::run_shell!(@cmd ({
$cmd.tmux_command()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -E, $($tail:tt)*) => {{
$crate::run_shell!(@cmd ({
$cmd.redirect_stderr()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -d $delay:expr, $($tail:tt)*) => {{
$crate::run_shell!(@cmd ({
$cmd.delay($delay)
}) $($tail)*)
}};
(@cmd ($cmd:expr) -t $target_pane:expr, $($tail:tt)*) => {{
$crate::run_shell!(@cmd ({
$cmd.target_pane($target_pane)
}) $($tail)*)
}};
(@cmd ($cmd:expr) $shell_command:expr, $($tail:tt)*) => {{
$crate::run_shell!(@cmd ({
$cmd.shell_command($shell_command)
}) $($tail)*)
}};
(@cmd ($cmd:expr)) => {{
$cmd
}};
() => {{
$crate::RunShell::new()
}};
(($cmd:expr), $($tail:tt)*) => {{
$crate::run_shell!(@cmd ($cmd) $($tail)*,)
}};
($($tail:tt)*) => {{
$crate::run_shell!(@cmd ({ $crate::RunShell::new() }) $($tail)*,)
}};
}
#[test]
fn run_shell_macro() {
use std::borrow::Cow;
let run_shell = run_shell!();
#[cfg(feature = "tmux_1_8")]
let run_shell = run_shell!((run_shell), -b);
#[cfg(feature = "tmux_3_2")]
let run_shell = run_shell!((run_shell), -C);
#[cfg(feature = "tmux_3_6")]
let run_shell = run_shell!((run_shell), -E);
#[cfg(feature = "tmux_3_2")]
let run_shell = run_shell!((run_shell), -d "1");
#[cfg(feature = "tmux_1_8")]
let run_shell = run_shell!((run_shell), -t "2");
#[cfg(feature = "tmux_1_5")]
let run_shell = run_shell!((run_shell), "3");
#[cfg(not(feature = "cmd_alias"))]
let cmd = "run-shell";
#[cfg(feature = "cmd_alias")]
let cmd = "run";
let mut s = Vec::new();
s.push(cmd);
#[cfg(feature = "tmux_1_8")]
s.push("-b");
#[cfg(feature = "tmux_3_2")]
s.push("-C");
#[cfg(feature = "tmux_3_6")]
s.push("-E");
#[cfg(feature = "tmux_3_2")]
s.extend_from_slice(&["-d", "1"]);
#[cfg(feature = "tmux_1_8")]
s.extend_from_slice(&["-t", "2"]);
#[cfg(feature = "tmux_1_5")]
s.push("3");
let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
let run_shell = run_shell.build().to_vec();
assert_eq!(run_shell, s);
}