# io.github.libtmux.TmuxEnvironment.TmuxEnvironment

- **Module:** io.github.libtmux.TmuxEnvironment
- **Package:** io.github.libtmux:libtmux
- **Language:** Java
- **Kind:** class
- **Source:** https://github.com/libtmux/libtmux-java/blob/c3517519ee799428a809ce6deb1708c8be289cd1/libtmux/src/main/java/io/github/libtmux/TmuxEnvironment.java#L34
- **Page:** https://libtmux.org/reference/java/io-github-libtmux-tmuxenvironment-tmuxenvironment/

What tmux tells a program running inside one of its panes.

<p>tmux exports {@code TMUX} as {@code <socket>,<server-pid>,<session>} and {@code TMUX_PANE} as
the pane's id. That is how a process discovers the server it is already inside, without being told
where to look.

<pre>{@code
TmuxEnvironment here = TmuxEnvironment.current().orElseThrow();

try (Server server = Server.open(here.config())) {
    Session mine = server.sessions().stream()
            .filter(session -> session.id().equals(here.session()))
            .findFirst()
            .orElseThrow();
}
}</pre>

<p>Reading is separated from the environment itself, so the parsing is testable without a process
ever having to be started inside tmux: {@link #of} takes the variables, {@link #current} is the
one-line wrapper that fetches them.

<p>A class rather than a record for the reason {@link ServerConfig} gives — and because the pane
is genuinely absent sometimes, which an {@link Optional} accessor says better than a nullable
record component.

## Members

- `current` (method) — Reads this process's own environment.
- `of` (method) — Reads a set of environment variables.
- `socket` (method) — The socket the server is listening on.
- `serverPid` (method) — The process id of the tmux server, which is not the pane's process.
- `session` (method) — The session this process is running in.
- `pane` (method) — The pane this process is running in, absent when {@code TMUX_PANE} was not set.
- `config` (method) — A config addressing this server, ready for {@link Server#open}.
- `toString` (method)
