libtmux.Session.from_env
Python
- Python
- Ruby Unavailable
- Lua Unavailable
- TypeScript
- Rust
- Go Unavailable
- Java Unavailable
- .NET
- C++ Unavailable
- Swift Unavailable
- Module
- libtmux
- Declared in
- Session
- Package
- libtmux
- Source
- src/libtmux/session.py
- Other languages
- Ruby Lua TypeScriptRust Go Java .NET C++ Swift
-
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.- 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
In other ports The session 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
session.Session.fromEnv - Rust
session.Session.from_env - Go no equivalent on
Session - Java no equivalent on
Session - .NET
LibTmux.Session.FromEnvironmentAsync - C++ no equivalent on
Session - Swift no equivalent on
Session
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 $TMUX cannot mislead it:
>>> env = {"TMUX": f"{socket_path},1,999", "TMUX_PANE": pane.pane_id}>>> Session.from_env(env).session_id == session.session_idTrue>>> Session.from_env(env)Session($1 ...)const current = await Session.fromEnv();current.name;use libtmux::{Pane, Session};
let session = server.new_session("locating-session").await?;let pane = session.panes().await?.remove(0);
// Standing in for the environment tmux gives a process it starts.let found = Session::from_env_value(server, Some(pane.id().as_ref())).await?;
assert_eq!(found.expect("the session exists").id(), session.id());0 declared, 0 inherited