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

session.Session.fromEnv

TypeScript

View as Markdown

Module
session
Declared in
Session
Package
libtmux
Source
packages/libtmux/src/session.ts
Other languages
Python Ruby Lua Rust Go Java .NET C++ Swift
fromEnv ( environment : : Readonly<Record<string, string | undefined>> = process.env ) → Promise<Session>
methodstaticasync [source]
methodstaticasync [source]
fromEnv

Resolve the session this process is running inside.

The pane is authoritative: $TMUX's exported session id goes stale when a pane is moved, so the session is looked up through $TMUX_PANE instead.

Discussed in Environment

In other ports The session this process is running inside

Examples

const current = await Session.fromEnv();
current.name;
>>> 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_id
True
>>> Session.from_env(env)
Session($1 ...)
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

Esc

Type to search.