Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

View as Markdown

Module
session
Package
libtmux
Source
crates/libtmux/src/session.rs
Other languages
PythonTypeScriptGoJava.NETC++Swift
struct session.Session
structoverload [source]
structoverload [source]
struct session.Session

One tmux session, together with the snapshot it was discovered with.

A Session is cheap to clone and shares its connection with the Server that produced it, but owns its snapshot outright. Cloning therefore does not share observed state: refreshing one clone leaves the others as they were.

Getters are synchronous because they read the owned snapshot. Anything that consults tmux is async.

Discussed in Rust workspace builder API · Environment

In other ports A tmux session

Examples

let guard = libtmux::test::TestServer::new().await?;
let session = guard.server().new_session("work").await?;
// The name is read from the snapshot this handle owns, so it costs
// nothing; asking tmux for the windows is `async` because it does.
assert_eq!(session.name().to_string_lossy(), "work");
assert_eq!(session.windows().await?.len(), 1);
guard.shutdown().await?;
>>> session
Session($1 ...)
>>> session.windows
[Window(@1 ...:..., Session($1 ...)]
>>> session.active_window
Window(@1 ...:..., Session($1 ...))
>>> session.active_pane
Pane(%1 Window(@1 ...:..., Session($1 ...)))

The session can be used as a context manager to ensure proper cleanup:

>>> with server.new_session() as session:
... window = session.new_window()
... # Do work with the window
... # Session will be killed automatically when exiting the context

48 declared, 0 inherited

Members

  • active_window method Return the session's active window.
  • append_option method Append to one option rather than replacing it.
  • attached_client_count method Return how many clients are attached to the session.
  • cmd method Run a raw tmux command against this session.
  • created method Return when the session was created.
  • detach_clients method Detach every client attached to this session.
  • display method Show a message on the clients viewing this session.
  • environment method Read one variable from the session's environment.
  • environment_all method Read the session's whole environment.
  • format method Expand a tmux format string in this session's context.
  • from_env method Find the session this process is running in.
  • from_env_value method Find a session from an explicit TMUX_PANE value.
  • get method Read one field of this session's snapshot, named by the handle that filters it.
  • hide_environment method Hide a variable from processes started in this session.
  • hook method Read one hook's commands, or None when it holds nothing.
  • hooks method Read every hook set at this session.
  • id method Return the tmux session identity.
  • is_attached method Report whether any client is attached.
  • kill method Kill the session.
  • last_attached method Return when a client last attached.
  • last_window method Move to the window that was active before this one, and return it.
  • lock method Lock every client attached to this session.
  • name method Return the session name.
  • new_window method Create a window in this session and return it.
  • next_window method Move to the next window, and return it.
  • option_names method List the option names set at this session's scope.
  • options method Read every option set at this session, decoded by its declared kind.
  • panes method List every pane in this session, preserving any failure.
  • path method Return the session's working directory.
  • previous_window method Move to the previous window, and return it.
  • refresh method Replace this handle's snapshot with the session's current state.
  • refreshed method Return a new handle holding the session's current state.
  • rename method Rename the session and update this handle.
  • search_windows method The windows under this session that a matcher accepts, reporting why if the listing fails.
  • set_environment method Set an environment variable for processes this session starts.
  • set_hook method Set one hook to a tmux command.
  • set_hooks method Write a whole hook at once.
  • set_option method Set one option to text, unchecked.
  • set_typed_option method Set one option to a typed value, checked before it is sent.
  • typed_option method Read one option, decoded according to what tmux declares about it.
  • unset_environment method Remove an environment variable from the session.
  • unset_hook method Remove one hook.
  • unset_option method Remove one option, restoring whatever it inherits.
  • window method Find this session's window with the given name.
  • window_at method Find this session's window at the given index.
  • window_count method Return how many windows the session contains.
  • windows method List the windows linked into this session, preserving any failure.
  • with_window method Create a window, run an operation with it, then kill it.
Esc

Type to search.