summaryrefslogtreecommitdiffstats
path: root/src/tmux.rs
diff options
context:
space:
mode:
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();