Пример #1
0
async def main(connection):
    app = await iterm2.async_get_app(connection)
    window = app.current_terminal_window
    timeout = 3
    if window is not None:
        # Run ryanair service
        await window.async_create_tab()
        session = app.current_terminal_window.current_tab.current_session
        await session.async_send_text('cd ~/code/indie-ryanair-service\nys\n')
        time.sleep(timeout)
        change = iterm2.LocalWriteOnlyProfile()
        color = iterm2.Color(204, 0, 126)
        change.set_tab_color(color)
        change.set_use_tab_color(True)
        await session.async_set_profile_properties(change)
        await session.async_set_name("ryanair serv")

        # Run ryanair frontend
        await window.async_create_tab()
        session = app.current_terminal_window.current_tab.current_session
        await session.async_send_text('cd ~/code/indie-ryanair-frontend\nys\n')
        time.sleep(timeout)
        change = iterm2.LocalWriteOnlyProfile()
        color = iterm2.Color(0, 140, 240)
        change.set_tab_color(color)
        change.set_use_tab_color(True)
        await session.async_set_profile_properties(change)
        await session.async_set_name("ryanair front")

    else:
        # You can view this message in the script console.
        print("No current window")
Пример #2
0
    async def hsplit_tab():
        print("\nVSplit the Tab in Window")

        cur_tab, cur_sess, cur_profile = await getCurrentTab()
        if not cur_tab:
            print("Cannot find the currnet Tab")
            return

        isLocal = await isLocalHost(cur_sess)
        cmd, msg = await getCommand(cur_tab, cur_profile)
        cur_profile_name = cur_profile.name

        print("Duplicate the Tab with Profile: name:%s, cmd:%s, new_cmd:%s, msg:%s" %
            (cur_profile_name, cur_profile.command, cmd, msg))

        change = None
        if cmd:
            change = iterm2.LocalWriteOnlyProfile()
            change.set_command(cmd)
            change.set_use_custom_command("Yes")

        new_sess = await cur_sess.async_split_pane(vertical=False, profile=cur_profile_name, profile_customizations=change)
        #new_sess = await cur_sess.async_split_pane(vertical=False, profile=cur_profile_name)
        await new_sess.async_activate()

        if msg:
            # send msg
            await sendText(msg, new_sess)
        else:
            # change dir
            await changeDir(cur_sess, new_sess)
Пример #3
0
async def main(connection):
    app = await iterm2.async_get_app(connection)

    # Foreground the app
    await app.async_activate()

    # Create a new tab or window
    myterm = app.current_terminal_window
    if not myterm:
        myterm = await iterm2.Window.async_create(connection)
    else:
        await myterm.async_create_tab()
    await myterm.async_activate()

    # Update the name and disable future updates by
    # control sequences.
    #
    # Changing the name this way is equivalent to
    # editing the Session Name field in
    # Session>Edit Session.
    session = myterm.current_tab.current_session
    update = iterm2.LocalWriteOnlyProfile()
    update.set_allow_title_setting(False)
    update.set_name("This is my customized session name")
    await session.async_set_profile_properties(update)
async def main(connection):

    app = await iterm2.async_get_app(connection)

    session = app.current_terminal_window.current_tab.current_session

    profile = iterm2.LocalWriteOnlyProfile()

    set_color = {
        'Foreground Color': profile.set_foreground_color,
        'Background Color': profile.set_background_color,
        'Bold Color': profile.set_bold_color,
        'Link Color': profile.set_link_color,
        'Selection Color': profile.set_selection_color,
        'Selected Text Color': profile.set_selected_text_color,
        'Cursor Color': profile.set_cursor_color,
        'Cursor Text Color': profile.set_cursor_text_color,
        'Cursor Guide Color': profile.set_cursor_guide_color,
        'Badge Color': profile.set_badge_color,
        'Tab Color': profile.set_tab_color,
        'Underline Color': profile.set_underline_color,
        'Ansi 0 Color': profile.set_ansi_0_color,
        'Ansi 1 Color': profile.set_ansi_1_color,
        'Ansi 2 Color': profile.set_ansi_2_color,
        'Ansi 3 Color': profile.set_ansi_3_color,
        'Ansi 4 Color': profile.set_ansi_4_color,
        'Ansi 5 Color': profile.set_ansi_5_color,
        'Ansi 6 Color': profile.set_ansi_6_color,
        'Ansi 7 Color': profile.set_ansi_7_color,
        'Ansi 8 Color': profile.set_ansi_8_color,
        'Ansi 9 Color': profile.set_ansi_9_color,
        'Ansi 10 Color': profile.set_ansi_10_color,
        'Ansi 11 Color': profile.set_ansi_11_color,
        'Ansi 12 Color': profile.set_ansi_12_color,
        'Ansi 13 Color': profile.set_ansi_13_color,
        'Ansi 14 Color': profile.set_ansi_14_color,
        'Ansi 15 Color': profile.set_ansi_15_color,
    }

    def interp(x):
        return int(round(x * 255))

    for key in root.keys():
        red = interp(root[key]['Red Component'])
        green = interp(root[key]['Green Component'])
        blue = interp(root[key]['Blue Component'])
        try:
            alpha = interp(root[key]['Alpha Component'])
        except KeyError:
            alpha = 255
        set_color[key](iterm2.Color(red, green, blue, alpha))

    if not args.quiet:
        for key in set(set_color.keys()) - set(root.keys()):
            print(f'Warning: Missing key \'{key}\' in {args.file}')

    await session.async_set_profile_properties(profile)
Пример #5
0
async def main(connection):
    app = await iterm2.async_get_app(connection)
    session = app.current_terminal_window.current_tab.current_session
    change = iterm2.LocalWriteOnlyProfile()
    tab_color = iterm2.Color(255, 153, 51)
    background_color = iterm2.Color(100, 0, 0)
    change.set_tab_color(tab_color)
    change.set_use_tab_color(True)
    change.set_background_color(background_color)
    await session.async_set_profile_properties(change)
Пример #6
0
async def main(connection):
    text = sys.argv[1]
    app = await iterm2.async_get_app(connection)
    window = app.current_terminal_window
    if window is not None:
        session = window.current_tab.current_session
        change = iterm2.LocalWriteOnlyProfile()
        change.set_badge_text(text)
        await session.async_set_profile_properties(change)
    else:
        # You can view this message in the script console.
        print("🚨 current window")
Пример #7
0
async def main(connection):
    app = await iterm2.async_get_app(connection)
    session = app.current_terminal_window.current_tab.current_session
    window = app.current_window
    #    if window is not None:
    #        await window.async_create_tab()
    #    else:
    #        print("No current window")

    change = iterm2.LocalWriteOnlyProfile()
    color = iterm2.Color(rand_color(), rand_color(), rand_color())

    change.set_tab_color(color)
    change.set_use_tab_color(True)
    await session.async_set_profile_properties(change)
Пример #8
0
async def main(connection):
    if len(sys.argv) == 1:
        print(
            'No hosts to connect to found! Usage is:\ni2cssh.py host1 [host2 ...]'
        )
        return
    hosts = sys.argv[1:]
    cols = 3 if len(hosts) <= 3 else ceil(sqrt(len(hosts)))
    app = await iterm2.async_get_app(connection)
    window = app.current_terminal_window

    # create sessions in new tab
    tab = None
    sessions = [None for x in range(cols)]  # sessions to split down
    col = 0
    for host in hosts:
        tmp_profile = iterm2.LocalWriteOnlyProfile()
        tmp_profile.set_use_custom_command('Yes')
        tmp_profile.set_command(f'ssh {host}')
        tmp_profile.set_close_sessions_on_end(False)

        if not tab:  # create new tab first
            tab = await window.async_create_tab(
                profile=profile, profile_customizations=tmp_profile)
            sessions[col] = tab.current_session
        else:
            if sessions[col]:  # split down
                sessions[col] = await sessions[col].async_split_pane(
                    vertical=False,
                    profile=profile,
                    profile_customizations=tmp_profile)
            else:  # first row, split right
                # https://gitlab.com/gnachman/iterm2/issues/7903
                if not sessions[col - 1]:
                    return
                sessions[col] = await sessions[col - 1].async_split_pane(
                    vertical=True,
                    profile=profile,
                    profile_customizations=tmp_profile)
        col = (col + 1) % cols

    # enable broadcast
    for session in tab.sessions:
        await iterm2.MainMenu.async_select_menu_item(
            connection,
            'Broadcast Input.Broadcast Input to All Panes in Current Tab')
Пример #9
0
async def main(connection):
    app = await iterm2.async_get_app(connection)
    # This regex splits the font into its name and size. Fonts always end with
    # their size in points, preceded by a space.
    r = re.compile(r'^(.* )(\d*)$')

    session = app.current_terminal_window.current_tab.current_session
    # profile=await session.async_get_profile()
    profile = await iterm2.Profile.async_get_default(connection)
    print(profile.normal_font)
    replacement = 'MesloLGMDZForPowerline-Regular 13'
    print(replacement)
    change = iterm2.LocalWriteOnlyProfile()
    await profile.async_set_normal_font(replacement)
    preset = await iterm2.ColorPreset.async_get(connection, "Brogrammer")
    await profile.async_set_color_preset(preset)
    await session.async_set_profile_properties(change)

    profile = await session.async_get_profile()
    print(profile.normal_font)
Пример #10
0
async def async_set_color_preset(connection, preset):
    """
    This updates the color scheme of all profiles and of all active sessions.
    """
    # Update the list of all profiles and iterate over them.
    profiles = await iterm2.PartialProfile.async_query(connection)
    for partial in profiles:
        # Fetch the full profile and then set the color preset in it.
        profile = await partial.async_get_full_profile()
        await profile.async_set_color_preset(preset)

    # Update all currently running sessions with the new preference.
    app = await iterm2.async_get_app(connection)
    for window in app.terminal_windows:
        for tab in window.tabs:
            for session in tab.sessions:
                profile = await session.async_get_profile()
                change = iterm2.LocalWriteOnlyProfile()
                set_color_preset(change, preset)
                await session.async_set_profile_properties(change)
Пример #11
0
async def main(connection):
    app = await iterm2.async_get_app(connection)
    session = app.current_terminal_window.current_tab.current_session
    change = iterm2.LocalWriteOnlyProfile()
    command = 'ssh ' + ' '.join(sys.argv[1:])
    host = parse_ssh_command(full_command=command)

    alias, color = get_host_config(host)

    # set config
    change.set_badge_text(alias)
    change.set_tab_color(color)
    change.set_use_tab_color(True)
    change.set_badge_color(color)

    # apply new config for iterm2 and ssh to server
    await session.async_set_profile_properties(change)
    subprocess.call(command.split())

    # revert config
    change.set_badge_text('')
    change.set_use_tab_color(False)
    await session.async_set_profile_properties(change)
Пример #12
0
async def main(connection):
    app = await iterm2.async_get_app(connection)
    window = app.current_terminal_window
    timeout = 3
    if window is not None:
        # Run Ariana
        await window.async_create_tab()
        session = app.current_terminal_window.current_tab.current_session

        await session.async_send_text('cd ~/code/indie-ariana-service\nys\n')
        time.sleep(timeout)
        change = iterm2.LocalWriteOnlyProfile()
        color = iterm2.Color(255, 128, 128)
        change.set_tab_color(color)
        change.set_use_tab_color(True)
        await session.async_set_profile_properties(change)
        await session.async_set_name("ariana")

        # Run Rita-Ora
        await window.async_create_tab()
        session = app.current_terminal_window.current_tab.current_session
        await session.async_send_text('cd ~/code/indie-rita-ora\nys\n')
        time.sleep(timeout)
        change = iterm2.LocalWriteOnlyProfile()
        color = iterm2.Color(245, 193, 7)
        change.set_tab_color(color)
        change.set_use_tab_color(True)
        await session.async_set_profile_properties(change)
        await session.async_set_name("rita")

        # Run Billie-Eilish
        await window.async_create_tab()
        session = app.current_terminal_window.current_tab.current_session
        await session.async_send_text('cd ~/code/indie-billie-eilish\nys\n')
        time.sleep(timeout)
        change = iterm2.LocalWriteOnlyProfile()
        color = iterm2.Color(0, 204, 143)
        change.set_tab_color(color)
        change.set_use_tab_color(True)
        await session.async_set_profile_properties(change)
        await session.async_set_name("billie")

        # Run Fka-twigs
        await window.async_create_tab()
        session = app.current_terminal_window.current_tab.current_session
        await session.async_send_text('cd ~/code/indie-fka-twigs\nys\n')
        time.sleep(timeout)
        change = iterm2.LocalWriteOnlyProfile()
        color = iterm2.Color(105, 0, 204)
        change.set_tab_color(color)
        change.set_use_tab_color(True)
        await session.async_set_profile_properties(change)
        await session.async_set_name("fka")

        # Run Shakira
        await window.async_create_tab()
        session = app.current_terminal_window.current_tab.current_session
        await session.async_send_text('cd ~/code/indie-shakira\nys\n')
        time.sleep(timeout)
        change = iterm2.LocalWriteOnlyProfile()
        color = iterm2.Color(252, 252, 28)
        change.set_tab_color(color)
        change.set_use_tab_color(True)
        await session.async_set_profile_properties(change)
        await session.async_set_name("shakira")

        # Run Back Office graph
        await window.async_create_tab()
        session = app.current_terminal_window.current_tab.current_session
        await session.async_send_text('cd ~/code/backoffice-graphql-server\nys\n')
        time.sleep(timeout)
        change = iterm2.LocalWriteOnlyProfile()
        color = iterm2.Color(204, 0, 126)
        change.set_tab_color(color)
        change.set_use_tab_color(True)
        await session.async_set_profile_properties(change)
        await session.async_set_name("bo graph")

        # Run Back Office frontend
        await window.async_create_tab()
        session = app.current_terminal_window.current_tab.current_session
        await session.async_send_text('cd ~/code/backoffice-frontend\nys\n')
        time.sleep(timeout)
        change = iterm2.LocalWriteOnlyProfile()
        color = iterm2.Color(0, 140, 240)
        change.set_tab_color(color)
        change.set_use_tab_color(True)
        await session.async_set_profile_properties(change)
        await session.async_set_name("bo front")

    else:
        # You can view this message in the script console.
        print("No current window")
Пример #13
0
async def main(connection):
    app = await iterm2.async_get_app(connection)
    tabLeft = app.current_terminal_window.current_tab.current_session

    # Change color tab to BLUE
    change = iterm2.LocalWriteOnlyProfile()
    color = iterm2.Color(0, 0, 255)
    change.set_tab_color(color)
    change.set_use_tab_color(True)
    await tabLeft.async_set_profile_properties(change)

    # Start Docker
    os.system('open --background -a Docker')
    isDockerRunning = 0
    while (not isDockerRunning):
        proc1 = subprocess.Popen(['docker', 'version'], stdout=subprocess.PIPE)
        proc2 = subprocess.Popen(['grep', 'Server: Docker Engine'],
                                 stdin=proc1.stdout,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
        out, err = proc2.communicate()
        isDockerRunning = len(out)
        if isDockerRunning > 0:
            print("Docker is running")
        else:
            print("Docker isn't running")
            sleep(10)

    # Start Container
    os.system('cd %s && docker-compose start' % PROJECT_MYSQL_PATH)
    isContainerRunning = -1
    while (isContainerRunning == -1):
        print('Checking if MySql container is running')
        container = subprocess.run(['docker ps | grep mysql57'],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.STDOUT,
                                   shell=True)
        isContainerRunning = container.stdout.decode('utf-8').find('mysql57')
        if isContainerRunning != -1:
            print("MySql container is running")
        else:
            print("MySql container isn't running")
            sleep(5)

    # Open Visual Studio Code
    open_vs_code = """osascript -e 'tell application "Visual Studio Code"
    activate
    delay 5
    tell application "System Events"
        keystroke "f" using {control down, command down}
    end tell
    end tell'"""
    os.system(open_vs_code)

    # Open Github Desktop
    open_github_desktop = """osascript -e 'delay 10
    tell application "GitHub Desktop"
    activate
    delay 5
    tell application "System Events"
        keystroke "f" using {control down, command down}
    end tell
    end tell'"""
    os.system(open_github_desktop)

    # Create new tab in the right
    tabRight = await tabLeft.async_split_pane(vertical=True)
    color = iterm2.Color(0, 255, 0)
    change.set_tab_color(color)
    change.set_use_tab_color(True)
    await tabRight.async_set_profile_properties(change)

    # Start server
    await tabRight.async_send_text("cd %s && npm start \n" %
                                   PROJECT_SERVER_PATH)

    # Create tab at bottom
    tabLeftBottom = await tabLeft.async_split_pane()
    color = iterm2.Color(255, 0, 0)
    change.set_tab_color(color)
    change.set_use_tab_color(True)
    await tabLeftBottom.async_set_profile_properties(change)

    # Start client
    await tabLeftBottom.async_send_text("cd %s && npm start \n" %
                                        PROJECT_CLIENT_PATH)
 async def set_font(font, size):
     profile = iterm2.LocalWriteOnlyProfile()
     profile.set_normal_font(f'{font} {size}')
     await session.async_set_profile_properties(profile)