Created
April 21, 2019 05:49
-
-
Save gnachman/4f51906834c8ac4b6921b451b161795a to your computer and use it in GitHub Desktop.
iTerm2 Python script to increase font size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
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*)$') | |
@iterm2.RPC | |
async def increase_font_size(session_id): | |
session = app.get_session_by_id(session_id) | |
if not session: | |
return | |
# Get the session's profile because we need to know its font. | |
profile = await session.async_get_profile() | |
# Extract the name and point size of the font using a regex. | |
font = profile.normal_font | |
match = r.search(font) | |
if not match: | |
return | |
groups = match.groups() | |
name = groups[0] | |
size = int(groups[1]) | |
# Prepare an update to the profile that increases the font size | |
# by 6 points. | |
replacement = name + str(size + 6) | |
change = iterm2.LocalWriteOnlyProfile() | |
change.set_normal_font(replacement) | |
# Update the session's copy of its profile without updating the | |
# underlying profile. | |
await session.async_set_profile_properties(change) | |
await increase_font_size.async_register(connection) | |
iterm2.run_forever(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment