I added two new methods on Session in commit 0e3f995483a5c7488f10e51659b5981b298bed5e, which will be available in the next nightly build and require iterm2 module version 2.15:
async_move_to_new_tab(window=None, tab_index=None)
Moves a session out of a split pane into its own tab.
- window: Which window to create the tab in. None means the session's current window.
- tab_index: Position in the tab bar (0 = first). None places it after the session's current tab (same window) or at the end
(different window).
- Returns the new tab's ID, or None for tmux clients (which are moved asynchronously by the server).
async_move_to_new_window()
Moves a session out of a split pane into a new window.
- Returns the new window's ID, or None for tmux clients.
The existing App.async_move_session(session, destination, split_vertically, before) continues to handle the case of moving a
session into a split pane alongside another session.
Example usage:
app = await iterm2.async_get_app(connection)
window = app.windows[0]
tab = window.tabs[0]
session = tab.sessions[0]
# Move to a new tab in the same window
tab_id = await session.async_move_to_new_tab()
# Move to a new tab in a different window, at position 0
tab_id = await session.async_move_to_new_tab(
window=app.windows[1], tab_index=0)
# Move to a new window
window_id = await session.async_move_to_new_window()
These require the session to be one of at least two sessions in its tab (otherwise there's nothing to extract it from).