# pane.Pane.from_env

- **Module:** pane.Pane
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/pane.rs#L113
- **Page:** https://libtmux.org/reference/rs/pane-pane-from_env/

```
pane.Pane.from_env(server: &crate::Server) -> Result<Option<Self>, Error>
```

Find the pane this process is running in.

tmux sets `TMUX_PANE` in every process it starts, so a program running
inside a pane can locate itself without being told which one it is.
Pair it with [`crate::Server::from_env`], which reads the server from
the same place.

`Ok(None)` means tmux no longer has that pane, which is possible when
the value came from an environment that outlived it.

# Errors

Returns an error when `TMUX_PANE` is absent or is not a pane ID, or
when the pane listing fails.

## Example

```rust
use libtmux::Pane;

let session = server.new_session("locating").await?;
let expected = session.panes().await?.remove(0);

// Standing in for the environment tmux gives a process it starts.
let found = Pane::from_env_value(server, Some(expected.id().as_ref())).await?;

assert_eq!(found.expect("the pane exists").id(), expected.id());
```
