Skip to content

Instantly share code, notes, and snippets.

@enihsyou
Created November 19, 2021 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enihsyou/c30a8039eee6bb203adc538bdc5877eb to your computer and use it in GitHub Desktop.
Save enihsyou/c30a8039eee6bb203adc538bdc5877eb to your computer and use it in GitHub Desktop.
Disable font ligatures on iTerm2 by monitoring on window size change
#!/usr/bin/env python3.7
# This script monitoring iTerm2 window state,
# disable font-ligatures when window size is big enough to drag FPS down,
# and (re-)enable ligatures when window size shrinks to acceptance range.
# Put this script under AutoLaunch folder to launch automatically when iTerm2 starts,
# as described at https://iterm2.com/python-api/tutorial/running.html#auto-run-scripts
import asyncio
import iterm2
async def update(connection, window):
if window is None:
return
frame = await window.async_get_frame()
small = (frame.size.width, frame.size.height) <= (1280, 720)
change = iterm2.LocalWriteOnlyProfile()
change.set_ascii_ligatures(small)
change.set_non_ascii_ligatures(small)
for tab in window.tabs:
await tab.current_session.async_set_profile_properties(change)
async def main(connection):
app = await iterm2.async_get_app(connection)
async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.WINDOW,
"frame", "all") as mon:
while True:
new_value = await mon.async_get()
await update(connection, app.current_window)
# This instructs the script to run the "main" coroutine and to keep running even after it returns.
iterm2.run_forever(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment