tmux_interface/commands/global_and_session_environment/
show_environment_macro.rs1#[macro_export]
27macro_rules! show_environment {
28 (@cmd ($cmd:expr) -h, $($tail:tt)*) => {{
30 $crate::show_environment!(@cmd ({
31 $cmd.hidden()
32 }) $($tail)*)
33 }};
34 (@cmd ($cmd:expr) -g, $($tail:tt)*) => {{
36 $crate::show_environment!(@cmd ({
37 $cmd.global()
38 }) $($tail)*)
39 }};
40 (@cmd ($cmd:expr) -s, $($tail:tt)*) => {{
42 $crate::show_environment!(@cmd ({
43 $cmd.as_shell_commands()
44 }) $($tail)*)
45 }};
46 (@cmd ($cmd:expr) -t $target_session:expr, $($tail:tt)*) => {{
48 $crate::show_environment!(@cmd ({
49 $cmd.target_session($target_session)
50 }) $($tail)*)
51 }};
52 (@cmd ($cmd:expr) $variable:expr, $($tail:tt)*) => {{
54 $crate::show_environment!(@cmd ({
55 $cmd.variable($variable)
56 }) $($tail)*)
57 }};
58 (@cmd ($cmd:expr)) => {{
62 $cmd
63 }};
64 () => {{
65 $crate::ShowEnvironment::new()
66 }};
67 (($cmd:expr), $($tail:tt)*) => {{
68 $crate::show_environment!(@cmd ($cmd) $($tail)*,)
69 }};
70 ($($tail:tt)*) => {{
71 $crate::show_environment!(@cmd ({ $crate::ShowEnvironment::new() }) $($tail)*,)
72 }};
73
74}
75
76#[test]
77fn show_environment() {
78 use crate::TargetSession;
79 use std::borrow::Cow;
80
81 let target_session = TargetSession::Raw("1").to_string();
107
108 let show_environment = show_environment!();
109 #[cfg(feature = "tmux_3_2")]
110 let show_environment = show_environment!((show_environment), -h);
111 #[cfg(feature = "tmux_1_0")]
112 let show_environment = show_environment!((show_environment), -g);
113 #[cfg(feature = "tmux_2_1")]
114 let show_environment = show_environment!((show_environment), -s);
115 #[cfg(feature = "tmux_1_7")]
116 let show_environment = show_environment!((show_environment), -t & target_session);
117 #[cfg(feature = "tmux_1_7")]
118 let show_environment = show_environment!((show_environment), "2");
119
120 #[cfg(not(feature = "cmd_alias"))]
121 let cmd = "show-environment";
122 #[cfg(feature = "cmd_alias")]
123 let cmd = "showenv";
124
125 let mut s = Vec::new();
126 s.push(cmd);
127 #[cfg(feature = "tmux_3_2")]
128 s.push("-h");
129 #[cfg(feature = "tmux_1_0")]
130 s.push("-g");
131 #[cfg(feature = "tmux_2_1")]
132 s.push("-s");
133 #[cfg(feature = "tmux_1_7")]
134 s.extend_from_slice(&["-t", "1"]);
135 #[cfg(feature = "tmux_1_7")]
136 s.push("2");
137 let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
138
139 let show_environment = show_environment.build().to_vec();
140
141 assert_eq!(show_environment, s);
142}