Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am gnachman on github.
  • I am iterm2 (https://keybase.io/iterm2) on keybase.
  • I have a public key whose fingerprint is 8B55 5615 6DB7 B5A4 4C93 3018 3225 C306 16D4 4CCA

To claim this, I am signing this object:

View stream.py
#!/usr/bin/env python3.7
import iterm2
async def main(connection):
   app = await iterm2.async_get_app(connection)
   session = app.current_terminal_window.current_tab.current_session
   async with session.get_screen_streamer(want_contents=True) as streamer:
       while True:
View print_screen.py
#!/usr/bin/env python3.7
import iterm2
async def main(connection):
   app = await iterm2.async_get_app(connection)
   session = app.current_terminal_window.current_tab.current_session
   contents = await session.async_get_screen_contents()
   for i in range(contents.number_of_lines):
@gnachman
gnachman / .emacs
Created Jun 26, 2020
Make CSI u mode work in emacs
View .emacs
(unless (display-graphic-p)
(add-hook 'after-make-frame-functions
'(lambda
;; Take advantage of iterm2's CSI u support (https://gitlab.com/gnachman/iterm2/-/issues/8382).
(xterm--init-modify-other-keys)
;; Courtesy https://emacs.stackexchange.com/a/13957, modified per
;; https://gitlab.com/gnachman/iterm2/-/issues/8382#note_365264207
(defun character-apply-modifiers (c &rest modifiers)
"Apply modifiers to the character C.
View gist:dfdbfafcd6e18396fdde36cccb1fe596
_NXShowKeyAndMain
0x7fff35b16cf3 <+0>: pushq %rbp
0x7fff35b16cf4 <+1>: movq %rsp, %rbp
0x7fff35b16cf7 <+4>: pushq %r15
0x7fff35b16cf9 <+6>: pushq %r14
0x7fff35b16cfb <+8>: pushq %r13
0x7fff35b16cfd <+10>: pushq %r12
0x7fff35b16cff <+12>: pushq %rbx
0x7fff35b16d00 <+13>: pushq %rax
0x7fff35b16d01 <+14>: leaq 0x5a1c6c90(%rip), %r15 ; NSApp
@gnachman
gnachman / decode_term_features
Created May 10, 2020
Prototype of pure POSIX terminal features decoder
View decode_term_features
#!/bin/dash
__tf_decode() {
local TABLE="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
local COUNT=0
local ACCUMULATOR=0
local SKIP=0
local ENCODED="$1"
local REMAINING="$ENCODED"
local FEATURES="8 VERSION 1 24BIT_BASIC 1 24BIT_FULL 1 CLIPBOARD_WRITE 1 DECSLRM 1 MOUSE_BASIC 1 MOUSE_ALT_SCROLL 1 UTF8 1 DECSCUSR_BASIC 1 DECSCUSR_BAR 1 AMBIGUOUS_FULLWIDTH 4 UNICODE_VERSION 1 RTL_LEVEL1 1 RTL_LEVEL2 1 TITLE_SETTING 1 BRACKETED_PASTE 1 FOCUS_REPORTING 1 CWD 1 BCE 1 UNDERLINE_STYLING 1 UNDERLINE_STYLE_DOUBLE 1 UNDERLINE_STYLE_CURLY 1 UNDERLINE_STYLE_DOTTED 1 UNDERLINE_STYLE_DASHED 1 STRIKETHROUGH 1 OVERLINE 1 SYNC 1 HYPERLINKS 1 NOTIFICATIONS 1 SIXEL 1 ITALICS 1 INVERSE_7 0 EOF"
@gnachman
gnachman / serial_alert.py
Created Feb 9, 2020
Register function to show one alert at a time
View serial_alert.py
import asyncio
import iterm2
pending = False
last_coro = None
async def main(connection):
loop = asyncio.get_event_loop()
async def really_notify(message, window_id):
View gist:d7c35930c1191393838bf18a19b5bfe8
import iterm2
async def main(connection):
app = await iterm2.async_get_app(connection)
window = app.current_terminal_window
tab = window.tabs[0]
print(f'Before: {tab.sessions}')
await tab.sessions[0].async_split_pane()
print(f'After: {tab.sessions}')
View gist:8ff1d81817e8520137b3d951040a8d7d
<pre id="changelist7330916824228127372" style="display: none">The only change in version 3.2.9 vs 3.2.8 is that
it was built with libssh2 1.8.2 because of a
security vulnerability. iTerm2 version 3.2.8 was
built with libssh2 1.8.0.
More information on the vulnerability in libssh2
may be found here:
https://nvd.nist.gov/vuln/detail/CVE-2019-3855
View gist:0e7cab890fcfb0853810d78dc695e6c1
#!/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: