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