Skip to content

Instantly share code, notes, and snippets.

@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.
#!/bin/bash
CD_CMD="cd "\\\"$(pwd)\\\"" && clear"
if echo "$SHELL" | grep -E "/fish$" &> /dev/null; then
CD_CMD="cd "\\\"$(pwd)\\\""; and clear"
fi
VERSION=$(sw_vers -productVersion)
OPEN_IN_TAB=0
while [ "$1" != "" ]; do
@gnachman
gnachman / iterm.scpt
Last active April 8, 2023 23:42
Replace /Applications/Docker/Docker Quickstart Terminal.app/Contents/Resources/Scripts/iterm.scpt with this.
set itermRunning to (application "iTerm" is running)
set scriptPath to quoted form of POSIX path of ((path to me as text) & "::" & "start.sh")
set user_shell to do shell script "dscl /Search -read /Users/$USER UserShell | awk '{print $2}'"
tell application "iTerm"
activate
if not (exists window 1) or (itermRunning = false) then
reopen
end if
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]
@gnachman
gnachman / gist:4cbe6743baa7fe07536b
Last active April 16, 2022 23:42
Script to use Alfred with nightly build of iTerm2
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try

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):
_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"