On this page
libtmux.Session.from_env
- Module
- libtmux
- Declared in
- Session
- Package
- libtmux
- Source
- src/libtmux/session.py
-
Return the session this process's pane belongs to.
The session id baked into
$TMUXis frozen at pane spawn and goes stale the moment the pane's window is moved or linked elsewhere, so it is never read. tmux is asked instead: the pane row thatPane.from_envfetches is stamped with the session tmux considers canonical for that pane's window.Examples
>>> socket_path = server.cmd( # doctest: +HIDE ... "display-message", "-p", "-t", pane.pane_id, "#{socket_path}" ... ).stdout[0]Even a deliberately wrong session id in
$TMUXcannot mislead it:>>> env = {"TMUX": f"{socket_path},1,999", "TMUX_PANE": pane.pane_id} >>> Session.from_env(env).session_id == session.session_id True>>> Session.from_env(env) Session($1 ...)- Parameters
-
-
env ( t.Mapping[str, str] | None ) – Environment to read. Defaults to
os.environ.
-
- Returns
- Raises
-
-
NotInsideTmux – When
$TMUXor$TMUX_PANEis unset or malformed. -
TmuxObjectDoesNotExist – When the pane named by
$TMUX_PANEis gone. -
LibTmuxException – When the server named by
$TMUXis unreachable. -
ValueError – When the resolved pane carries no
session_id. Surfaces a clear error underpython -O, where anassertwould be stripped.
-
Discussed in Environment
0 declared, 0 inherited