libtmux Reference MCP Search
On this page

server.Server.from_env

View as Markdown

Module
server
Declared in
Server
Package
libtmux
Source
crates/libtmux/src/server.rs
from_env ( ) Result<Self, Error>
method [source]
method [source]
from_env

Build a server from the TMUX variable tmux exports into every pane.

tmux sets TMUX to `<socket_path>,<server_pid>,<session_id>`. Only the socket path is used: the pid and session id are frozen when the pane spawns, and the session id goes stale as soon as the pane's window is moved to another session.

Being frozen is what makes the pid worth something to a caller who wants to know the daemon has not been replaced since. A server that restarts on the same socket answers here just as well, and reissues ids from the start, so Server::generation and Server::require_generation are what tell the two apart. This does not check on its own initiative, because that would cost a round trip on a call documented as running no tmux command.

This runs no tmux command and does not check that the server is alive; use Server::is_alive for that.

Errors

Returns an error when TMUX is unset, empty, or not shaped like that triple, and when the socket path it names is unusable.

Examples

let outside = libtmux::Server::from_env_value(None::<OsString>);
assert!(outside.is_err(), "a process outside tmux has no TMUX value");

let inside = libtmux::Server::from_env_value(Some("/tmp/tmux-1000/default,7,$0"))?;
assert_eq!(inside.socket_path(), std::path::Path::new("/tmp/tmux-1000/default"));

Discussed in Environment

0 declared, 0 inherited

Esc

Type to search.