libtmux Reference MCP Search
On this page

session.settings.Session.environment

View as Markdown

Module
session.settings
Declared in
Session
Package
libtmux
Source
crates/libtmux/src/session/settings.rs
environment ( self , name : &str ) Result<Option<EnvironmentEntry>, Error>
method [source]
method [source]
environment

Read one variable from the session's environment.

tmux keeps two different things under a name: a value, and a mark saying a process started here must not inherit the name at all. [ EnvironmentEntry ] keeps them apart, because collapsing both to absence would hide the second, which a caller sets deliberately with Self::hide_environment.

None means tmux holds nothing under the name.

Errors

Returns an error when tmux cannot be reached.

Examples

use libtmux::EnvironmentEntry;

let guard = libtmux::test::TestServer::new().await?;
let session = guard.server().new_session("read").await?;

assert_eq!(session.environment("EDITOR").await?, None);

session.set_environment("EDITOR", "hx").await?;
assert!(matches!(
    session.environment("EDITOR").await?,
    Some(EnvironmentEntry::Set(value)) if value.as_bytes() == b"hx",
));

session.hide_environment("EDITOR").await?;
assert_eq!(
    session.environment("EDITOR").await?,
    Some(EnvironmentEntry::Removed),
);

guard.shutdown().await?;

0 declared, 0 inherited

Esc

Type to search.