Skip to content

Instantly share code, notes, and snippets.

@J-Swift
Created November 17, 2022 18:16
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 J-Swift/51db3030ff09242a5bcb5ac0761dd8c0 to your computer and use it in GitHub Desktop.
Save J-Swift/51db3030ff09242a5bcb5ac0761dd8c0 to your computer and use it in GitHub Desktop.
iterm2 script for reloading all panes in a window
#!/usr/bin/env python3.7
import iterm2
async def get_last_line(session):
async with session.get_screen_streamer() as streamer:
ready = False
while ready != True:
content = await streamer.async_get()
for i in range(content.number_of_lines):
line = content.line(content.number_of_lines-i-1)
if line.string != "":
return line.string
async def main(connection):
app = await iterm2.async_get_app(connection)
@iterm2.RPC
async def reload_all_sessions():
window = app.current_terminal_window
tab = window.current_tab
for old_pane in tab.sessions:
await old_pane.async_send_text("pwd\n", True)
last_line = await get_last_line(old_pane)
new_pane = await old_pane.async_split_pane(vertical=False)
await new_pane.async_send_text(f"cd \"{last_line}\"\n", True)
await old_pane.async_send_text("fge\n", True)
await reload_all_sessions.async_register(connection)
iterm2.run_forever(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment