session.Session.from_env
Rust
- Python
- TypeScript
- Rust
- Go Unavailable
- Java Unavailable
- .NET
- C++ Unavailable
- Swift Unavailable
- Module
- session
- Declared in
- Session
- Package
- libtmux
- Source
- crates/libtmux/src/session.rs
- Other languages
- PythonTypeScript Go Java .NET C++ Swift
-
Find the session this process is running in.
Resolved through the pane, because
TMUX_PANEnames exactly one pane while a server'sTMUXvalue names the session that was current when the client attached, which may since have changed.Ok(None)means tmux no longer has that pane.Errors
Returns an error when
TMUX_PANEis absent or is not a pane ID, or when the listing fails.Discussed in Environment
In other ports The session this process is running inside
- Python
libtmux.Session.from_env - TypeScript
session.Session.fromEnv - Go no equivalent on
Session - Java no equivalent on
Session - .NET
LibTmux.Session.FromEnvironmentAsync - C++ no equivalent on
Session - Swift no equivalent on
Session
- Python
Examples
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());>>> 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;0 declared, 0 inherited