summaryrefslogtreecommitdiffstats
path: root/src/tmux.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-05-08 17:21:18 -0500
committerToby Vincent <tobyv13@gmail.com>2023-05-08 17:21:18 -0500
commitc0d77c1eadc1d0304369d6bc8107ac9843be93f0 (patch)
tree60c983ab9cd7dd4a0318b58abeab6309ffcd75a8 /src/tmux.rs
parent3f94c60de5059a7549d959944de2b8d73ae0cee9 (diff)
feat: add exclude-attached flag to tmux config
Diffstat (limited to 'src/tmux.rs')
-rw-r--r--src/tmux.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/tmux.rs b/src/tmux.rs
index e3efbd5..b1f1af2 100644
--- a/src/tmux.rs
+++ b/src/tmux.rs
@@ -13,6 +13,9 @@ pub struct Tmux {
/// tmux socket-name, equivelent to `tmux -L <socket-name>`
#[arg(short = 'L', long = "tmux_socket", default_value = "ssh")]
pub socket: String,
+
+ #[arg(short = 'E', long)]
+ pub exclude_attached: bool,
}
impl Tmux {
@@ -34,6 +37,24 @@ impl Tmux {
.collect::<Result<_, _>>()
.map_err(Into::into)
}
+
+ pub fn attached(&self) -> Result<Session, Error> {
+ let stdout = Command::new("tmux")
+ .arg("-L")
+ .arg(&self.socket)
+ .arg("display")
+ .arg("-p")
+ .arg(Self::SESSION_FORMAT)
+ .output()?
+ .stdout;
+
+ std::str::from_utf8(&stdout)?
+ .lines()
+ .map(ron::from_str)
+ .last()
+ .transpose()?
+ .ok_or(Error::NotFound)
+ }
}
#[cfg(test)]
@@ -59,6 +80,7 @@ mod tests {
let tmux = Tmux {
socket: SOCKET.to_owned(),
+ exclude_attached: false,
};
let sessions: Vec<_> = tmux.list()?.into_iter().map(|s| s.name).collect();