Core LibrarystableAPI Reference

Choose documentation 3

stable

Current version

stable
English

Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

Python API

method libtmux stable

Server.from_env

Return the tmux server this process's pane is attached to.

Source and package
Qualified name
libtmux.Server.from_env
Module
libtmux
Declared in
Server
Package
libtmux
Source
src/libtmux/server.py
Other languages
PowerShell Julia Ruby Lua TypeScript Rust Go Java C#C++ Swift Kotlin Scala F#
from_env ( cls, env: t.Mapping[str, str] | None = None ) → Server

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
>>> socket_path = server.cmd(
... "display-message", "-p", "-t", pane.pane_id, "#{socket_path}"
... ).stdout[0]
>>> env = {"TMUX": f"{socket_path},1,0", "TMUX_PANE": pane.pane_id}
>>> TmuxServer.from_env(env)
Server(socket_path=...)
>>> TmuxServer.from_env(env).is_alive()
True

Outside 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
  • 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

Server Server bound to the socket named by $TMUX. Not verified to be alive -- use Server.is_alive for that.

Raises
  • NotInsideTmux – When $TMUX is unset, empty, or not shaped like tmux's triple.

Discussed in Environment

In other ports The server this process is running inside
  • PowerShell
    No source-verified PowerShell equivalent is recorded for this operation.
  • Julia
    No source-verified Julia equivalent is recorded for this operation.
  • 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
  • Go
    no equivalent on Server
  • Java
    no equivalent on Server
  • C#
  • C++
  • Swift
    no equivalent on Server
  • Kotlin
    No source-verified Kotlin equivalent is recorded for this operation.
  • Scala
    No source-verified Scala equivalent is recorded for this operation.
  • F#
    No source-verified F# equivalent is recorded for this operation.
Esc

Type to search.

Reference preview Open reference