Skip to content

Instantly share code, notes, and snippets.

@gnachman
Created September 8, 2019 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnachman/d7c35930c1191393838bf18a19b5bfe8 to your computer and use it in GitHub Desktop.
Save gnachman/d7c35930c1191393838bf18a19b5bfe8 to your computer and use it in GitHub Desktop.
import iterm2
async def main(connection):
app = await iterm2.async_get_app(connection)
window = app.current_terminal_window
tab = window.tabs[0]
print(f'Before: {tab.sessions}')
await tab.sessions[0].async_split_pane()
print(f'After: {tab.sessions}')
iterm2.run_until_complete(main)
# Output is:
Before: [<Session name=vim id=4058DAA1-B6C6-4376-B822-7A6E5EDADBB0>]
After: [<Session name=vim id=4058DAA1-B6C6-4376-B822-7A6E5EDADBB0>, <Session name= id=A82F1674-C386-4CAA-868B-507C4474A1BB>]
@nicad
Copy link

nicad commented Sep 9, 2019

Here is a version that doesn't behave properly:

import iterm2

async def main(connection):
    app = await iterm2.async_get_app(connection)
    window = app.current_terminal_window
    tab = await window.async_create_tab()
    print(f'Before: {len(tab.sessions)}')
    session = tab.current_session
    for i in range(0, 2):
        session = await session.async_split_pane()
        print(f'During: {len(tab.sessions)}')
    print(f'After: {len(tab.sessions)}')

iterm2.run_until_complete(main)

# Output is:
# python ./test_tab_update.py
# Before: 1
# During: 1
# During: 1
# After: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment