Session.from_env
Return the session this process's pane belongs to.
Source and package
- Qualified name
-
libtmux.Session. from _env - Module
- libtmux
- Declared in
Session- Package
- libtmux
- Source
- src/libtmux/session.py
- Other languages
- Perl Erlang PowerShell Julia Elixir Haskell Common Lisp Ruby Lua TypeScriptRust Go Java C# C++ Swift Kotlin Scala OCaml F# Clojure
-
Description#
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_env()fetches 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_idTrue>>> Session.from_env(env)Session($1 ...)- Parameters
- Returns
- Raises
-
-
Not
Inside – WhenTmux TMUXorTMUX_PANEis unset or malformed. -
Tmux
Object – When the pane named byDoes Not Exist TMUX_PANEis gone. -
Lib
Tmux – When the server named byException TMUXis unreachable. -
Value
Error – When the resolved pane carries nosession_id. Surfaces a clear error underpython -O, where anassertwould be stripped.
-
Guides#
Pages that discuss from_env.
In other ports#
The session this process is running inside
| Language | Equivalent |
|---|---|
| Haskell | No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing. |
| TypeScript | session |
| Rust | session |
| Go | no equivalent on Session |
| Java | no equivalent on Session |
| C# | Lib |
| C++ | no equivalent on Session |
| Swift | no equivalent on Session |
| OCaml | No direct public OCaml equivalent is recorded for this operation. |
| 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#.