server.Server.from_env
- Module
- server
- Declared in
- Server
- Package
- libtmux
- Source
- crates/libtmux/src/server.rs
- Other languages
- Python TypeScript Go Java .NETC++ Swift
-
Build a server from the
TMUXvariable tmux exports into every pane.tmux sets
TMUXto `<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::generationandServer::require_generationare 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_alivefor that.Errors
Returns an error when
TMUXis unset, empty, or not shaped like that triple, and when the socket path it names is unusable.Discussed in Environment
In other ports The server this process is running inside
- Python
libtmux.Server.from_env - TypeScript no equivalent on
Server - Go no equivalent on
Server - Java no equivalent on
Server - .NET
LibTmux.Server.FromEnvironment - C++
libtmux::Server::from_env - Swift no equivalent on
Server
- Python
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"));>>> from libtmux.server import Server as TmuxServer # doctest: +HIDE>>> socket_path = server.cmd( # doctest: +HIDE... "display-message", "-p", "-t", pane.pane_id, "#{socket_path}"... ).stdout[0]>>> env = { # doctest: +HIDE... "TMUX": f"{socket_path},1,0",... "TMUX_PANE": pane.pane_id,... }>>> TmuxServer.from_env(env)Server(socket_path=...)>>> TmuxServer.from_env(env).is_alive()TrueOutside a pane there is no server to name:
>>> try:... TmuxServer.from_env({})... except exc.NotInsideTmux as e:... print(e)Not inside a tmux pane: $TMUX is unset or empty0 declared, 0 inherited