Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
import asyncio
import iterm2
async def main(connection):
async def update(theme):
# Themes have space-delimited attributes, one of which will be light or dark.
parts = theme.split(" ")
if "dark" in parts:
@gnachman
gnachman / gist:4f51906834c8ac4b6921b451b161795a
Created April 21, 2019 05:49
iTerm2 Python script to increase font size
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):
@gnachman
gnachman / gist:2b31bbed2995f18ae9307339584db3ec
Created April 18, 2019 03:34
Prompt to enter tab title after creating a new tab
#!/usr/bin/env python3.7
import iterm2
async def main(connection):
app = await iterm2.async_get_app(connection)
def get_all_tab_ids():
result = []
for window in app.terminal_windows:
for tab in window.tabs:
[libssh2] 1.110621 Conn: Connection Established - ID: 0/0 win: 0/2097152 pack: 140630114205696/4295000064
[libssh2] 1.110646 Conn: starting request(exec) on channel 0/0, message=scp -f '~/test.txt'
=> libssh2_transport_write plain (18 bytes)
0000: 62 00 00 00 00 00 00 00 04 65 78 65 63 01 00 00 : b........exec...
0010: 00 14 : ..
=> libssh2_transport_write plain2 (20 bytes)
0000: 73 63 70 20 2D 66 20 27 7E 2F 74 65 73 74 2E 74 : scp -f '~/test.t
0010: 78 74 27 00 : xt'.
[libssh2] 1.110690 Socket: Sent 80/80 bytes at 0x7fe74da7a260
=> libssh2_transport_write send() (80 bytes)
- (void)drawRect:(NSRect)dirtyRect {
NSString *string = @"Hello world";
NSDictionary *attributes = @{ (NSString *)kCTForegroundColorAttributeName: (id)[[NSColor blackColor] CGColor],
NSFontAttributeName: [NSFont fontWithName:@"PragmataProMono-Regular" size:12],
NSLigatureAttributeName: @0,
NSUnderlineStyleAttributeName: @1 };
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string
attributes:attributes];
CGColorRef cgColor = (__bridge CGColorRef)attributes[(NSString *)kCTForegroundColorAttributeName];
#!/usr/bin/env python3
import asyncio
import iterm2
import sys
# This script was created with the "basic" environment which does not support adding dependencies
# with pip.
async def main(connection, argv):
app = await iterm2.async_get_app(connection)
@gnachman
gnachman / gist:3f3b78030e02b6949de9fe7f813ae47c
Created June 28, 2018 18:32
Get terminal geometry when stdin/stdout are not ttys.
#!/bin/bash
#@ Copyright: © 2011 Chris F.A. Johnson
#@ Released under the terms of the GNU General Public License V2
#@ See the file COPYING for the full license
# Originally from http://cfajohnson.com/shell/listing1.txt
# Hacked to be completely different by George Nachman
if [ ! -t 1 ] ; then
# WARNING * THIS IS A HACK * IT MIGHT BREAK * THERE BE DRAGONS HERE * DO NOT USE IF YOU CARE FOR CORRECTNESS
"$0" < /dev/tty > /dev/tty
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
# *) local and remote branch names
# *) local and remote tag names
H4sIAPmefFcAA908a3fbtpLf/StQRqmkrKXEdh/b6ri5ju22PieJs7bTx0l8FYqELNYSqfJh2Unz33ce
AAjwIdnd3i+b08YxCQwGg3nPgI++eDqJ4qcTP5ttPRIXsygT8B/8KkORxMJbplLeymCIAzwxKXJ8HRRZ
niyijzBmmqQiupDpYne4BQBeJ7n8XuQIZpGExVyKVP5ZRKnMxC5CnYmp9PMCf1/NomAm7pJCLACciJNc
JPlMpqsok2IiAViRRfEVQpPCOzp+8fYnT+Spv9wWfhzy0zdnp6/eXIwPT1+9Onh95IkbP438yVwOhYhy
RGqs8B9HcZb78zlAXUXzuUhuZJpGoUQwsBwCjKaEjHmTxPB/SusQXryrMU4fi0kq/WvasSbZdZysYpEn
IiuWyyTNabd7gCvsVMKK8PPJIsny+d0TZ8ju8NnXE8D3JAdgMxg1kRLgyCwH6q6ifEYYhHLqF/NcZDOA
leHJvPKD03Pxm9h5NvxKeBfRlUy9bfF2UsR5Ib4e7jwDcN4L2P3HO/HCD53X3wyffQMk9ZdL2NZR6l9L
j4lq3u88E95xeHUnjqe5R/vMF8UtjcmCFDH0U0lnpvYiw5GQN/CcDo1wphkzP7hGqlzJXMgs8Jd4sEES
AgMs/Qy5LJ+lSXE12xZxUKQZPI9iOLqpRB7RB41vkNGyuAsMGNOzNLqaIc2Wcz+AE8x5zWgh4ei7VejD
LTjed++E17k4PnvliS/29T6+/BIenuDT8fnPxy9fjk9eXxz/dHZwcXL6Gv59fnHw8uUxsNa+8DwePIBf
#!/usr/bin/python
import re
import sys
import os
def ReadUntilPrefix(prefix):
k = 0
buff = ''
while True:
buff += sys.stdin.read(1)