How to use the iterm2.StatusBarComponent 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 daneah / iterm-components / rvm_gemset.py View on Github external
async def main(connection):
    component = iterm2.StatusBarComponent(
        short_description='rvm gemset',
        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)
github daneah / iterm-components / WIP_environment_variable.py View on Github external
async def main(connection):
    component = iterm2.StatusBarComponent(
        short_description='Environment variable',
        detailed_description='Show the current value of an environment variable',
        exemplar='SOME_ENV_VAR=foo',
        update_cadence=3,
        identifier='engineering.dane.iterm-components.environment-variable',
        knobs=[
            iterm2.StringKnob('Variable name', 'SOME_ENV_VAR', 'SOME_ENV_VAR', ENV_VAR_KNOB_NAME),
            iterm2.CheckboxKnob('Show variable name', True, SHOW_NAME_KNOB_NAME)
        ],
    )

    @iterm2.StatusBarRPC
    async def env_var_coroutine(knobs):
        env_var_name = knobs[ENV_VAR_KNOB_NAME]
        show_name = knobs[SHOW_NAME_KNOB_NAME]
        prefix = f'{env_var_name}=' if show_name else ''
github daneah / iterm-components / hello_world.py View on Github external
async def main(connection):
    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)
github daneah / iterm-components / github_stars.py View on Github external
async def main(connection):
    component = iterm2.StatusBarComponent(
        short_description='GitHub stars',
        detailed_description='How many stars a GitHub repository has',
        exemplar='some-user/project β˜… 103',
        update_cadence=300,
        identifier='engineering.dane.iterm-components.github-stars',
        knobs=[
            iterm2.StringKnob('Repository', 'some-user/project', 'some-user/project', REPO_KNOB_NAME),
            iterm2.StringKnob('Personal access token', 'token value (optional, for rate limiting or private repos)', '', TOKEN_KNOB_NAME)
        ],
    )

    @iterm2.StatusBarRPC
    async def github_stars_coroutine(knobs):
        github_repo = knobs[REPO_KNOB_NAME]
        token = knobs[TOKEN_KNOB_NAME]
        info_url = f'https://api.github.com/repos/{github_repo}'
github daneah / iterm-components / generic_command.py View on Github external
async def main(connection):
    component = iterm2.StatusBarComponent(
        short_description='Execute a user defined command',
        detailed_description='A component that displays the output of an arbitrary command with an optional prefix',
        exemplar='> hello world',
        update_cadence=7,
        identifier='engineering.dane.iterm-components.generic-command',
        knobs=[
           iterm2.StringKnob('Script', 'echo "hello world"', '', SCRIPT),
           iterm2.StringKnob('Prefix', '>', '', PREFIX)
        ],
    )

    @iterm2.StatusBarRPC
    async def generic_command_coroutine(knobs):
        proc = await asyncio.create_subprocess_shell(
            knobs[SCRIPT],
            stdout=asyncio.subprocess.PIPE,
github daneah / iterm-components / pyenv.py View on Github external
async def main(connection):
    component = iterm2.StatusBarComponent(
        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)