Skip to content

Instantly share code, notes, and snippets.

@qn7o
Last active February 25, 2020 19:48
Show Gist options
  • Save qn7o/0921e211105ee46635de7f3b2c65629b to your computer and use it in GitHub Desktop.
Save qn7o/0921e211105ee46635de7f3b2c65629b to your computer and use it in GitHub Desktop.
Iterm2 python script
#!/usr/bin/env python3.7
import iterm2
import os
async def main(connection):
"""
Open an Iterm2 tab dedicated to projects with a double pane per project, ready to start and showing its git status.
"""
app = await iterm2.async_get_app(connection)
window = app.current_terminal_window
if window is None:
print("No current window")
return
projects = {
"Project A": "proj_a",
"Project B": "proj_b",
"Project C": "proj_c",
}
dev_dir = "/path/to/dev/dir/"
git_status_cmd = "git top"
fire_up_cmd = "docker-compose up"
tab = await window.async_create_tab()
await tab.async_set_title("My projects")
sess = tab.current_session
for k, v in projects.items():
project_sess = await sess.async_split_pane(vertical=True, before=True)
await project_sess.async_set_name(k)
project_path = os.path.join(dev_dir, v)
await project_sess.async_send_text(f"cd {project_path}\n{fire_up_cmd}")
git_sess = await project_sess.async_split_pane(vertical=False, before=False)
await git_sess.async_send_text(f"cd {project_path} && {git_status_cmd}\n")
await sess.async_close()
iterm2.run_until_complete(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment