joshmfrankel / joshfrankel.me

Repo for my portfolio website
joshfrankel.me
0 stars 0 forks source link

Automate iterm2 for development #6

Open joshmfrankel opened 8 months ago

joshmfrankel commented 8 months ago

Install

Download: https://iterm2.com/downloads.html

For custom startup script

asdf plugin-add python
asdf install python latest

# Add python version to .tool-versions
subl ~/.tool-versions

pip install iterm2

Setup

Default Profile

Guake Profile

Startup script

Image

#!/usr/bin/env python3.7

import iterm2
# This script was created with the "basic" environment which does not support adding dependencies
# with pip.

async def main(connection):
    # Your code goes here. Here's a bit of example code that adds a tab to the current window:
    app = await iterm2.async_get_app(connection)
    window = app.current_terminal_window

    if window is not None:
        # TAB 1
        tab_1_session = app.current_terminal_window.current_tab.current_session
        await tab_1_session.async_send_text("cd ~/Development/rootly\n")
        await tab_1_session.async_send_text("BASE_URL=https://josh.rootly.ngrok.io rails s\n")

        # TAB 2
        await window.async_create_tab()
        tab_2_session_bottom_pane = app.current_terminal_window.current_tab.current_session

        # Bottom Section
        await tab_2_session_bottom_pane.async_send_text("cd ~/Development/rootly\n")
        await tab_2_session_bottom_pane.async_send_text("foreman start worker=1,genius_worker=1,searchkick_worker=1,webhooks_worker=1,slack_worker=1 -f Procfile.dev\n")
        await tab_2_session_bottom_pane.async_split_pane(before=True)

        # Top Section
        tab_2_session_top_pane = app.current_terminal_window.current_tab.current_session
        await tab_2_session_top_pane.async_send_text("cd ~/Development/rootly\n")
        await tab_2_session_top_pane.async_send_text("ngrok start josh --config ./ngrok.yml\n")

        # Split horizontally
        await tab_2_session_top_pane.async_split_pane(vertical=True)

        tab_2_session_top_middle_pane = app.current_terminal_window.current_tab.current_session
        await tab_2_session_top_middle_pane.async_send_text("cd ~/Development/rootly\n")
        await tab_2_session_top_middle_pane.async_send_text("rails tailwindcss:watch\n")

        # Split horizontally again
        await tab_2_session_top_middle_pane.async_split_pane(vertical=True)

        tab_2_session_top_right_pane = app.current_terminal_window.current_tab.current_session
        await tab_2_session_top_right_pane.async_send_text("cd ~/Development/rootly\n")
        await tab_2_session_top_right_pane.async_send_text("RAILS_ENV=development yarn esbuild:watch\n")

        # TAB 3
        await window.async_create_tab()
        tab_3_session = app.current_terminal_window.current_tab.current_session
        await tab_3_session.async_send_text("cd ~/Development/rootly\n")
        await tab_3_session.async_send_text("rails c\n")

        # TAB 4
        await window.async_create_tab()
        tab_4_session = app.current_terminal_window.current_tab.current_session
        await tab_4_session.async_send_text("cd ~/Development/rootly\n")
        await tab_4_session.async_send_text("echo '\n\n\nGood morning, Josh'\n")

    else:
        # You can view this message in the script console.
        print("No current window")

iterm2.run_until_complete(main)