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

config.Workspace

API reference · Markdown

struct config.Workspace
structoverload [source]
structoverload [source]
struct config.Workspace

One workspace: a session and the windows it should contain.

Discussed in Use the Rust workspace builder , Rust workspace builder behavior , Rust workspace builder API

In other ports Describe a workspace as data

Members

session_name

session_name : String
attribute [source]
attribute [source]
session_name

The session name to create.

Discussed in Format-token fields

start_directory

start_directory : Option<PathBuf>
attribute [source]
attribute [source]
start_directory

A working directory inherited by windows that do not set their own.

environment

environment : Vec<(String, String)>
attribute [source]
attribute [source]
environment

Environment variables to set on the session.

options

options : Vec<(String, String)>
attribute [source]
attribute [source]
options

Session options to apply once the session exists.

global_options

global_options : Vec<(String, String)>
attribute [source]
attribute [source]
global_options

Global options to apply once the session exists.

shell_command_before

shell_command_before : Vec<ShellCommand>
attribute [source]
attribute [source]
shell_command_before

Commands run in every pane before its own, in order.

suppress_history

suppress_history : bool
attribute [source]
attribute [source]
suppress_history

Whether to keep pane commands out of the shell's history.

A file that does not say reads as true, as in tmuxp.

windows

windows : Vec<WindowConfig>
attribute [source]
attribute [source]
windows

The windows to create, in order.

unsupported_keys

unsupported_keys : Vec<String>
attribute [source]
attribute [source]
unsupported_keys

Keys this parser recognized but does not act on.

Reported rather than dropped, so a caller can say what part of a file was ignored instead of leaving the difference to be discovered later.

from_yaml

from_yaml ( source : &str ) → Result<Self, ConfigError>
method [source]
method [source]
from_yaml

Parse one workspace from tmuxp-style YAML.

This accepts the shape tmuxp uses for the parts a builder needs. It is deliberately not a full tmuxp implementation: unknown keys are ignored rather than rejected, so a richer tmuxp file still loads.

As tmuxp does, it expands and $NAME or ${NAME} from this process's environment in names, start directories, and environment and option values, leaving an unset variable as written; commands are typed as written, for the pane's shell to expand. A start directory that begins with is relative to the one it inherits, or to the current directory at the top: Self::from_file uses the file's directory instead.

Errors

Returns an error when the document is not valid YAML, does not hold exactly one workspace, or is missing session_name . Every error except the document count names the line and column to look at.

Examples

use tmux_workspace::Workspace;
let workspace = Workspace::from_yaml(
"
session_name: demo
windows:
- window_name: editor
panes:
- echo one
- shell_command: echo two
",
)?;
assert_eq!(workspace.session_name, "demo");
assert_eq!(workspace.windows.len(), 1);
assert_eq!(workspace.windows[0].panes.len(), 2);

Discussed in Rust workspace internals , Use the Rust workspace builder , Rust workspace builder behavior , Rust workspace builder API

from_file

from_file ( path : impl AsRef<Path> ) → Result<Self, ConfigError>
method [source]
method [source]
from_file

Read and parse one workspace file, as tmuxp load does.

Everything Self::from_yaml says holds, except that a start directory beginning with and inheriting none is relative to the file's directory. JSON is read too, as the YAML it is a subset of.

Errors

Returns ConfigError::Read when the file cannot be read, and otherwise what Self::from_yaml returns.

Examples

use tmux_workspace::Workspace;
let project = tempfile::tempdir()?;
let file = project.path().join(".tmuxp.yaml");
std::fs::write(&file, "session_name: project\nstart_directory: ./\n")?;
let workspace = Workspace::from_file(&file)?;
assert_eq!(workspace.start_directory.as_deref(), Some(project.path()));

to_yaml

to_yaml ( self ) → String
method [source]
method [source]
to_yaml

Render this workspace as tmuxp-style YAML.

Emits the keys this crate acts on and nothing else, so a document that came from Self::from_yaml and back may be shorter than it started: what is dropped is what unsupported_keys already named.

Examples

use tmux_workspace::Workspace;
let workspace = Workspace::from_yaml(
"
session_name: demo
windows:
- window_name: editor
panes: [htop]
",
)?;
// What it writes, it can read.
assert_eq!(Workspace::from_yaml(&workspace.to_yaml())?, workspace);

Discussed in Use the Rust workspace builder , Rust workspace builder behavior , Rust workspace builder API

Esc

Type to search.