Add dump/restore commands to save and recreate session layouts - #5585
asRizvi888 wants to merge 4 commits into
Conversation
|
Thanks - this is a reasonable start but I think:
Also can you please put your real name in the copyright header. |
- dump previously wrote wp->cwd (a pane's spawn-time directory, never updated) instead of its live current directory, so restore always recreated panes wherever the shell was originally launched rather than where the user had since cd'd to. Now queries the live cwd via osdep_get_cwd(wp->fd), same as pane_current_path. - dump now pins base-index to the recorded value per session before emitting indexed commands, and restores the prior global value at the end, so restore works correctly even when the restoring environment's config sets a different base-index than dump time. - renamed the default dump file from .tmux-dump to .tmux.dump.
Address review feedback from nicm on the original dump/restore PR: - Renamed dump -> save-layout and restore -> load-layout to match tmux's existing verb-noun command naming (mirrors save-buffer/ load-buffer). - The layout file is now JSON (sessions -> windows -> panes), using the new json.c parser to read it back, instead of a hand-rolled plain-text script. Each window's pane arrangement is stored as the same JSON layout tree produced by layout_dump(), so splits, floating panes and z-index all round-trip. save-layout writes session/window/pane names, indexes, the active window and active pane, and each pane's live working directory. - I/O now goes through file.c (file_write/file_read), the same API used by save-buffer/load-buffer, instead of fopen/fwrite directly. This also means a path of "-" reads from stdin / writes to stdout, consistent with the buffer commands. - load-layout parses the JSON with json_parse()/json_find_*, builds an in-memory command script from it (still using the base-index pin/restore trick to place each session's first window at the correct recorded index regardless of the restoring server's own base-index), then runs it with load_cfg_from_buffer() rather than load_cfg() on a path. - Default file renamed from .tmux.dump to .tmux.layout. - Updated the manual page entries and moved them to their correct alphabetical position under save-layout/load-layout. - Copyright headers now use my real name.
cfe3971 to
043fb4a
Compare
|
I don't think you got the point... |
|
I think this should be entirely driven by JSON, it should not generate tmux commands. Could you maybe write up how you see this working? All the stuff that would be saved, restored, how the JSON would look, etc. So we can agree the design before writing the code. |
|
Thanks for the pointer - I think I understand now. Here's how I'd like this to work, before I write any more code: Scope (v1): for every session - name, base-index, current window; for every window - index, name, layout tree (splits/sizes/active pane, the same JSON the new layout format already produces); for every pane - index, live working directory. Not included: window/pane options, session environment, pane titles, zoomed state, or relaunching whatever was running in each pane. I'd rather ship this minimal version first and add any of that afterwards if you want it - let me know if you'd rather see more of that up front. JSON shape: {
"version": 1,
"sessions": [
{
"name": "work",
"base_index": 0,
"current_window": 1,
"windows": [
{
"index": 0,
"name": "zsh",
"active_pane": 0,
"layout": { "V": 2, "L": { "t": "p", "w": 80, "h": 24, "x": 0, "y": 0, "a": true, "i": 0, "I": "%0" } },
"panes": [ { "index": 0, "cwd": "/home/user" } ]
}
]
}
]
}
save-layout: unchanged from the current code - walks the live session/window/pane trees and writes the JSON above via load-layout: this is what I'll rework. Right now it parses the JSON and then generates a script of tmux commands ( Let me know if this matches what you had in mind, or if I'm still off - happy to adjust before writing the code. |
|
OK I think this is fine but I'm not sure about |
Address nicm's PR feedback: - load-layout no longer parses the JSON and generates a script of tmux commands to run through load_cfg_from_buffer(). It now walks the parsed JSON directly and calls the same internal functions new-session/new-window/split-window/select-layout use: session_create() for each session, spawn_window() for each window's first pane (with sc.idx set to the recorded index, so windows land at the right place without any base-index tricks), layout_split_pane()+spawn_pane() to get the remaining panes in place, and layout_parse() on the embedded layout JSON to get the exact recorded geometry and active pane. - Dropped base_index from the saved JSON - it was only ever needed to place a session's first window correctly when generating new-session text, which no longer happens. base-index is a session option, not layout data, and most sessions just inherit the global default anyway. - Dropped active_pane from the per-window JSON - it was redundant with the "a":true flag already present on the active pane's cell inside the layout JSON tree, which layout_parse() already applies. Verified end to end, including restoring a layout saved under base-index 0 into a session whose config sets base-index 1: windows still land at their recorded indexes, cwds and split geometry match, and the correct pane is active in each window.
|
Pushed an update addressing this. On Verified end to end, including restoring a layout saved under |
Summary
dump [-f path]to write the layout of every session (sessions,windows, panes, splits, active pane/window, and each pane's current
working directory) to a text file as a sequence of tmux commands.
restore [-f path]to recreate that layout by sourcing the file.This does not relaunch whatever process was previously running in each
pane - only the shape of the layout and where each pane's shell starts.
config file (falling back to $HOME), named .tmux.dump.
indexed commands, so restore places windows correctly even when the
restoring environment's config sets a different base-index, then
restores the prior global value afterward.
as the pane_current_path format variable), not the pane's original
spawn directory, so restore reflects where you actually left off.
Test plan
splits, and custom layouts; verified pane cwds match exactly.
base-index differs from the dump-time value.