Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

method libtmux-rs latest

Server.set_environment

Set a variable in the server's own environment.

Source and package
Qualified name
libtmux::server::Server::set_environment
Module
server
Declared in
Server
Package
libtmux
Source
crates/libtmux/src/server/settings.rs
Other languages
Perlmethod Erlang PowerShell Julia Elixir Haskell Common Lisp PythonRubyLuaTypeScriptGo Java C# C++ Swift Kotlin Scala OCaml F# Clojure
pub async fn set_environment( &self, name: &str, value: impl Into<OsString>, ) -> Result<(), Error>

Description#

tmux keeps this and each session's environment in separate stores, and merges them only when it starts a process. So a name set here is reported as an unknown variable by Session::environment() -- reading a session does not fall back to the server -- while a pane started afterwards is handed it all the same.

Where both hold a name, the session's value is the one the process gets. Self::hide_environment() removes the name from the merge entirely.

Panes already running keep the environment they were started with.

The value is marked sensitive, since an environment carries tokens.

Errors

Returns an error when tmux rejects the name or value.

Examples#

use libtmux::EnvironmentEntry;
let guard = libtmux::test::TestServer::new().await?;
let server = guard.server();
server.set_environment("EDITOR", "hx").await?;
assert!(matches!(
server.environment("EDITOR").await?,
Some(EnvironmentEntry::Set(value)) if value.as_bytes() == b"hx",
));
// Separate stores: the session has no entry of its own, and reading it
// does not fall back to the server. The value still reaches a process
// the session starts.
let session = server.new_session("separate").await?;
assert_eq!(session.environment("EDITOR").await?, None);
guard.shutdown().await?;
Parameters

tmux command#

The tmux commands behind set_environment.

tmux C API#

The C declarations in tmux that implement these commands.

Guides#

Pages that discuss set_environment.

In other ports#

Set a variable in the server's environment

Equivalents of Set a variable in the server's environment in other languages
Language Equivalent
Python libtmux.Server.set_environment
Ruby LibTmux::Server#set_environment
Lua libtmux.Server:set_environment
Haskell No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.
TypeScript server.Server.setEnvironment
Go tmux.Server.SetEnvironment
Java no equivalent on Server
C# no equivalent on Server
C++ no equivalent on Server
Swift Server.setEnvironment(_:to:in:)
OCaml Libtmux_unix.Client.set_environment
Perl LibTmux::Server::set_environment Omit session for the global environment. Missing or explicitly unset values remain failures.

No equivalent is recorded in PowerShell, Julia, Erlang, Elixir, Common Lisp, Clojure, Kotlin, Scala or F#.

Esc

Type to search.

Reference previewOpen reference