How to use the iterm2.run_forever function in iterm2

To help you get started, we’ve selected a few iterm2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gnachman / iTerm2 / sources / template_basic_daemon.py View on Github external
# This script was created with the "basic" environment which does not support adding dependencies
# with pip.

async def main(connection):
    # This is an example of using an asyncio context manager to register a custom control
    # sequence. You can send a custom control sequence by issuing this command in a
    # terminal session in iTerm2 while this script is running:
    #
    # printf "\033]1337;Custom=id=%s:%s\a" "shared-secret" "create-window"
    async with iterm2.CustomControlSequenceMonitor(connection, "shared-secret", r'^create-window$') as mon:
        while True:
            match = await mon.async_get()
            await iterm2.Window.async_create(connection)

# This instructs the script to run the "main" coroutine and to keep running even after it returns.
iterm2.run_forever(main)
github gnachman / iTerm2 / sources / template_pyenv_daemon.py View on Github external
import iterm2
# To install, update, or remove packages from PyPI, use Scripts > Manage > Manage Dependencies...

async def main(connection):
    # This is an example of using an asyncio context manager to register a custom control
    # sequence. You can send a custom control sequence by issuing this command in a
    # terminal session in iTerm2 while this script is running:
    #
    # printf "\033]1337;Custom=id=%s:%s\a" "shared-secret" "create-window"
    async with iterm2.CustomControlSequenceMonitor(connection, "shared-secret", r'^create-window$') as mon:
        while True:
            match = await mon.async_get()
            await iterm2.Window.async_create(connection)

# This instructs the script to run the "main" coroutine and to keep running even after it returns.
iterm2.run_forever(main)
github daneah / iterm-components / rvm_gemset.py View on Github external
detailed_description='The currently active rvm gemset',
        exemplar='πŸ’Ž gemset',
        update_cadence=2,
        identifier='engineering.dane.iterm-components.rvm-gemset',
        knobs=[],
    )

    @iterm2.StatusBarRPC
    async def rvm_gemset_coroutine(knobs, ruby=iterm2.Reference('user.ruby_version?')):
        ruby = ruby or 'default'
        ruby = ruby.replace('@', '') or 'default'
        return f'πŸ’Ž {ruby}'

    await component.async_register(connection, rvm_gemset_coroutine)

iterm2.run_forever(main)
github daneah / iterm-components / generic_command.py View on Github external
    @iterm2.StatusBarRPC
    async def generic_command_coroutine(knobs):
        proc = await asyncio.create_subprocess_shell(
            knobs[SCRIPT],
            stdout=asyncio.subprocess.PIPE,
            stderr=asyncio.subprocess.PIPE,
        )
        stdout, stderr = await proc.communicate()
        prefix = knobs[PREFIX]
        prefix = f'{prefix} ' if prefix else ''
        return f'{prefix}{stdout.decode().strip()}' if not stderr else 'Command failed!'

    await component.async_register(connection, generic_command_coroutine)

iterm2.run_forever(main)
github daneah / iterm-components / pyenv.py View on Github external
short_description='pyenv',
        detailed_description='The currently active Python',
        exemplar='🐍 3.7.2',
        update_cadence=2,
        identifier='engineering.dane.iterm-components.pyenv',
        knobs=[],
    )

    @iterm2.StatusBarRPC
    async def pyenv_coroutine(knobs, python=iterm2.Reference('user.python_version?')):
        python = python or '☠️'
        return f'🐍 {python}'

    await component.async_register(connection, pyenv_coroutine)

iterm2.run_forever(main)
github daneah / iterm-components / hello_world.py View on Github external
component = iterm2.StatusBarComponent(
        short_description='Hello, world!',
        detailed_description='Says hello in a random language periodically',
        exemplar='Β‘Hola, mundo!',
        update_cadence=5,
        identifier='engineering.dane.iterm-components.sentinel',
        knobs=[],
    )

    @iterm2.StatusBarRPC
    async def hello_world_coroutine(knobs):
        return random.choice(GREETINGS)

    await component.async_register(connection, hello_world_coroutine)

iterm2.run_forever(main)