Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/cli/import.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ $ tmuxp import teamocil /path/to/file.json

````

### Supported teamocil fields

The teamocil importer preserves top-level and `session`-wrapped configs, window
`root`, `layout`, `clear`, `focus`, `options`, and `filters` entries. Pane
entries using `cmd`, `commands`, string panes, and blank panes are converted to
tmuxp pane dictionaries. Unsupported pane `width` and `height` values are
dropped with a warning.

(import-tmuxinator)=

## From tmuxinator
Expand All @@ -64,6 +72,18 @@ $ tmuxp import tmuxinator /path/to/file.yaml

````

### Supported tmuxinator fields

The tmuxinator importer maps `project_name`/`name`, `project_root`/`root`,
legacy `tabs`, `cli_args`/`tmux_options` values for `-f`, `-L`, and `-S`,
`socket_name`, `socket_path`, `pre`, `pre_window`, `pre_tab`, `rbenv`, `rvm`,
`startup_window`, `startup_pane`, `synchronize`, pane-title keys, and lifecycle
hook keys.

Named pane entries such as `{logs: tail -f log/development.log}` become tmuxp
pane `title` values. Imported `config` values are resolved relative to the saved
workspace file when the workspace is loaded.

````{tab} JSON

```console
Expand Down
40 changes: 40 additions & 0 deletions src/tmuxp/cli/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,29 @@ def load_plugins(
return plugins


def _resolve_workspace_config_file(
config_file: str,
workspace_file: pathlib.Path,
) -> str:
"""Resolve a workspace-level tmux config path.

Relative paths are interpreted from the workspace file directory.

Examples
--------
>>> from tmuxp.cli.load import _resolve_workspace_config_file
>>> _resolve_workspace_config_file(
... "./tmux.conf",
... pathlib.Path("/tmp/project/session.yaml"),
... )
'/tmp/project/tmux.conf'
"""
config_path = pathlib.Path(config_file).expanduser()
if not config_path.is_absolute():
config_path = workspace_file.parent / config_path
return str(config_path.resolve(strict=False))


def _reattach(builder: WorkspaceBuilder, colors: Colors | None = None) -> None:
"""
Reattach session (depending on env being inside tmux already or not).
Expand Down Expand Up @@ -609,6 +632,23 @@ def load_workspace(
if new_session_name:
expanded_workspace["session_name"] = new_session_name

if socket_name is None:
socket_name = expanded_workspace.pop("socket_name", None)
else:
expanded_workspace.pop("socket_name", None)

if socket_path is None:
socket_path = expanded_workspace.pop("socket_path", None)
else:
expanded_workspace.pop("socket_path", None)

workspace_config_file = expanded_workspace.pop("config", None)
if tmux_config_file is None and workspace_config_file is not None:
tmux_config_file = _resolve_workspace_config_file(
str(workspace_config_file),
workspace_file,
)

# propagate workspace inheritance (e.g. session -> window, window -> pane)
expanded_workspace = loader.trickle(expanded_workspace)

Expand Down
Loading
Loading