summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tmux.rs37
1 files changed, 9 insertions, 28 deletions
diff --git a/src/tmux.rs b/src/tmux.rs
index 8a0d581..72d85d8 100644
--- a/src/tmux.rs
+++ b/src/tmux.rs
@@ -1,4 +1,4 @@
-use std::{path::PathBuf, process::Command};
+use std::process::Command;
use crate::Session;
@@ -39,29 +39,23 @@ 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("display")
.arg("-p")
- .arg(Self::SESSION_FORMAT)
+ .arg(format!(
+ "#{{?#{{m:*{},#{{socket_path}}}},#S,#{{host}}}}",
+ self.socket
+ ))
.output()?
.stdout;
std::str::from_utf8(&stdout)?
.lines()
- .map(ron::from_str)
+ .map(|name| Session {
+ name: name.to_string(),
+ state: crate::State::Discovered,
+ })
.last()
- .transpose()?
.ok_or(Error::NotFound)
}
@@ -87,19 +81,6 @@ 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)]