Skip to content

Instantly share code, notes, and snippets.

User runs `ssh-wrapper example.com`
`ssh-wrapper` does:
`ssh example.com /usr/bin/env sh -c "$(cat conductor.sh)"
Where `conductor.sh` is a sh script that does something like (pseudoterminal below):
echo <control sequence to notify terminal emulator that it's in ssh mode>
run login shell as a child process through `script` on file descriptor 3
while true:
output = [read from file descriptor 3 without blocking]

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:

#!/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:
#!/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 June 26, 2020 07:05
Make CSI u mode work in 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.
_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 06:13
Prototype of pure POSIX terminal features decoder
#!/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 February 9, 2020 00:55
Register function to show one alert at a time
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):
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}')
<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