Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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 ''
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)
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}'
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,
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)