From dd5692c76b9d5ba57e5f4f6f00a850de64d49632 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Sun, 29 Oct 2023 19:28:09 -0500 Subject: fix: exclude local session when attached --- src/tmux.rs | 28 +++++++++++++++++++++++++--- 1 file 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 { + 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 { + 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)] -- cgit v1.2.3-70-g09d2