Server.from_env
Return the tmux server this process's pane is attached to.
Source and package
-
Description#
Reads the socket path out of
TMUX, which tmux exports into every pane it spawns as"<socket_path>,<server_pid>,<session_id>". Only the socket path is used: the pid and the session id are frozen at pane spawn, and the session id goes stale as soon as the pane's window is moved between sessions. Costs no tmux subprocess -- it is a pure read of the environment.Examples#
>>> 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 empty- Parameters
- Returns
-
ServerServer bound to the socket named byTMUX. Not verified to be alive -- useServer.is_alive()for that. - Raises
-
-
Not
Inside – WhenTmux TMUXis unset, empty, or not shaped like tmux's triple.
-
Guides#
Pages that discuss from_env.
In other ports#
The server this process is running inside
| Language | Equivalent |
|---|---|
| Haskell | No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing. |
| TypeScript | no equivalent on Server |
| Rust | 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#.