libtmux.Server.from_env
- Module
- libtmux
- Declared in
- Server
- Package
- libtmux
- Source
- src/libtmux/server.py
- Other languages
- Ruby Lua TypeScript Rust Go Java .NETC++ Swift
-
Return the tmux server this process's pane is attached to.
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.- Parameters
-
-
env ( t.Mapping[str, str] | None ) – Environment to read. Defaults to
os.environ, which is what a process running inside a pane wants; pass an explicit mapping to resolve on behalf of another pane.
-
- Returns
-
ServerServer bound to the socket named by$TMUX. Not verified to be alive -- useServer.is_alivefor that. - Raises
-
-
NotInsideTmux – When
$TMUXis unset, empty, or not shaped like tmux's triple.
-
Discussed in Attaching to tmux · Environment
In other ports The server this process is running inside
- Ruby No source-verified Ruby equivalent is recorded for this operation.
- Lua No source-verified Lua equivalent is recorded for this operation.
- TypeScript no equivalent on
Server - Rust
server.Server.from_env - Go no equivalent on
Server - Java no equivalent on
Server - .NET
LibTmux.Server.FromEnvironment - C++
libtmux::Server::from_env - Swift no equivalent on
Server
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 emptylet 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"));0 declared, 0 inherited