diff options
author | Toby Vincent <tobyv@tobyvin.dev> | 2023-10-29 19:28:09 -0500 |
---|---|---|
committer | Toby Vincent <tobyv@tobyvin.dev> | 2023-10-29 19:28:09 -0500 |
commit | dd5692c76b9d5ba57e5f4f6f00a850de64d49632 (patch) | |
tree | 81ae8e5795141a29cc0b502744085049290395a5 | |
parent | 539fd0f26c83064b748bbd040fdf27f302f27cb7 (diff) |
fix: exclude local session when attached
-rw-r--r-- | src/tmux.rs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/tmux.rs b/src/tmux.rs index b53c172..8a0d581 100644 --- a/src/tmux.rs +++ b/src/tmux.rs @@ -1,4 +1,4 @@ -use std::process::Command; +use std::{path::PathBuf, process::Command}; use crate::Session; @@ -39,9 +39,18 @@ impl Tmux { } pub fn attached(&self) -> Result<Session, Error> { + if Self::current_socket()? + .file_name() + .and_then(|f| f.to_str()) + .is_some_and(|f| f != self.socket) + { + return Self::local_session()? + .first() + .ok_or(Error::NotFound) + .cloned(); + } + let stdout = Command::new("tmux") - .arg("-L") - .arg(&self.socket) .arg("display") .arg("-p") .arg(Self::SESSION_FORMAT) @@ -78,6 +87,19 @@ impl Tmux { Ok(sessions) } + + pub fn current_socket() -> Result<PathBuf, Error> { + let stdout = Command::new("tmux") + .arg("display") + .arg("-p") + .arg("#{session_path}") + .output()? + .stdout; + + std::str::from_utf8(&stdout) + .map(Into::into) + .map_err(Into::into) + } } #[cfg(test)] |