Created
November 17, 2022 18:16
-
-
Save J-Swift/51db3030ff09242a5bcb5ac0761dd8c0 to your computer and use it in GitHub Desktop.
iterm2 script for reloading all panes in a window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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