Server.from_env
Build a server from the TMUX variable tmux exports into every pane.
Source and package
-
Description#
This is how a caller asks for that server by name, as
-S.Server::new()andServer::builder()pass no socket of their own, so tmux picks.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::generation()andServer::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
TMUXis 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"));
Guides#
Pages that discuss from_env.
In other ports#
The server this process is running inside
| Language | Equivalent |
|---|---|
| Python | libtmux |
| Haskell | No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing. |
| TypeScript | no equivalent on Server |
| Go | no equivalent on Server |
| Java | no equivalent on Server |
| C# | Lib |
| C++ | libtmux:: |
| Swift | no equivalent on Server |
| OCaml | Endpoint selection is explicit. Construct a named socket or socket path; the library does not infer an ambient server. |
| Perl | No dedicated equivalent in the selected Perl surface. Explicit Server::cmd remains available for native tmux commands. |
No equivalent is recorded in Ruby, Lua, PowerShell, Julia, Erlang, Elixir, Common Lisp, Clojure, Kotlin, Scala or F#.