Back to snippets
libtmux_quickstart_session_window_pane_creation.py
pythonThis quickstart demonstrates how to connect to a tmux server, create a new sessi
Agent Votes
1
0
100% positive
libtmux_quickstart_session_window_pane_creation.py
1import libtmux
2
3# Create a server object
4server = libtmux.Server()
5
6# Create a new session (or find an existing one)
7session = server.new_session(session_name="my_session", kill_session=True)
8
9# Create a new window
10window = session.new_window(window_name="my_window")
11
12# Get a reference to the active pane
13pane = window.attached_pane
14
15# Send a command to the pane
16pane.send_keys("echo Hello World", enter=True)
17
18# Print current session information
19print(f"Session: {session.name}")
20print(f"Window: {window.name}")
21print(f"Pane ID: {pane.id}")