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.from_env

Build a server from the TMUX variable tmux exports into every pane.

Source and package
Qualified name
libtmux::server::Server::from_env
Module
server
Declared in
Server
Package
libtmux
Source
crates/libtmux/src/server.rs
Other languages
Perl Erlang PowerShell Julia Elixir Haskell Common Lisp Python Ruby Lua TypeScript Go Java C#C++ Swift Kotlin Scala OCaml F# Clojure
pub fn from_env() -> Result<Self, Error>

Description#

This is how a caller asks for that server by name, as -S. Server::new() and Server::builder() pass no socket of their own, so tmux picks.

tmux sets TMUX to <socket_path>,<server_pid>,<session_id>. Only the socket path is used: the pid and session id are frozen when the pane spawns, and the session id goes stale as soon as the pane's window is moved to another session.

Being frozen is what makes the pid worth something to a caller who wants to know the daemon has not been replaced since. A server that restarts on the same socket answers here just as well, and reissues ids from the start, so Server::generation() and Server::require_generation() are what tell the two apart. This does not check on its own initiative, because that would cost a round trip on a call documented as running no tmux command.

This runs no tmux command and does not check that the server is alive; use Server::is_alive() for that.

Errors

Returns an error when TMUX is unset, empty, or not shaped like that triple, and when the socket path it names is unusable.

Examples#

let outside = libtmux::Server::from_env_value(None::<OsString>);
assert!(outside.is_err(), "a process outside tmux has no TMUX value");
let inside = libtmux::Server::from_env_value(Some("/tmp/tmux-1000/default,7,$0"))?;
assert_eq!(inside.socket_path(), std::path::Path::new("/tmp/tmux-1000/default"));

Guides#

Pages that discuss from_env.

In other ports#

The server this process is running inside

Equivalents of The server this process is running inside in other languages
Language Equivalent
Python libtmux.Server.from_env
Haskell No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.
TypeScript no equivalent on Server
Go no equivalent on Server
Java no equivalent on Server
C# LibTmux.Server.FromEnvironment
C++ libtmux::Server::from_env
Swift no equivalent on Server
OCaml Endpoint selection is explicit. Construct a named socket or socket path; the library does not infer an ambient server.
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#.

Esc

Type to search.

Reference previewOpen reference