Created
May 6, 2026 13:09
-
-
Save dhruvbaldawa/8c07b3bf2adf7b8693a41b7a6b8f0fbe to your computer and use it in GitHub Desktop.
patch-pi.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Patches pi to fix Shift+Enter in tmux with extended-keys on | |
| # Run this after upgrading pi: bash ~/Code/pi-playground/patch-pi.sh | |
| set -e | |
| # Find the installed paths | |
| PI_TUI=$(node -e "console.log(require.resolve('@mariozechner/pi-tui/dist/keys.js'))" | xargs dirname) | |
| PI_AGENT=$(node -e "console.log(require.resolve('@mariozechner/pi-coding-agent/dist/modes/interactive/components/custom-editor.js'))" | xargs dirname) | |
| echo "Patching pi-tui at: $PI_TUI" | |
| echo "Patching pi-agent at: $PI_AGENT" | |
| # 1. Patch keys.js: add \x1b\n and \x1b[13;3u as shift+enter matches | |
| KEYS_FILE="$PI_TUI/keys.js" | |
| if ! grep -q "13;3u" "$KEYS_FILE"; then | |
| # Add \x1b[13;3u match in shift+enter case | |
| sed -i '/Also handle \\x1b\\n when Kitty is not active/a\ // tmux with extended-keys always sends \\x1b[13;3u for shift+enter,\n // which has modifier value 3 (decoded as alt in Kitty protocol),\n // but it'\''s actually shift+enter from tmux.\n if (data === "\\x1b[13;3u") {\n return true;\n }' "$KEYS_FILE" | |
| echo " Patched keys.js: added \\\\x1b[13;3u as shift+enter" | |
| else | |
| echo " keys.js already patched (skipping)" | |
| fi | |
| # 2. Patch editor.js: add alt+enter, \x1b[13;2u, \x1b[13;3u as newline triggers | |
| EDITOR_FILE="$PI_TUI/components/editor.js" | |
| if ! grep -q "13;3u" "$EDITOR_FILE"; then | |
| # Add alt+enter and CSI-u sequences to newline check | |
| sed -i 's/kb\.matches(data, "tui\.input\.newline") ||/kb.matches(data, "tui.input.newLine") ||\n kb.matches(data, "alt+enter") ||/' "$EDITOR_FILE" | |
| sed -i '/data === "\\\\x1b\\[13;2~"/a\ data === "\\x1b[13;2u" ||\n data === "\\x1b[13;3u" ||' "$EDITOR_FILE" | |
| echo " Patched editor.js: added newline triggers" | |
| else | |
| echo " editor.js already patched (skipping)" | |
| fi | |
| # 3. Patch custom-editor.js: early intercept of \x1b[13;3u before app keybindings | |
| CUSTOM_EDITOR_FILE="$PI_AGENT/custom-editor.js" | |
| if ! grep -q "13;3u" "$CUSTOM_EDITOR_FILE"; then | |
| sed -i '/\/\/ Check for paste image keybinding/a\ // tmux with extended-keys always sends \\x1b[13;3u for shift+enter,\n // which decodes as alt+enter in Kitty protocol. Handle it as newline\n // before app keybindings (like followUp) intercept it.\n if (data === "\\x1b[13;3u") {\n super.handleInput(data);\n return;\n }' "$CUSTOM_EDITOR_FILE" | |
| echo " Patched custom-editor.js: early intercept of \\\\x1b[13;3u" | |
| else | |
| echo " custom-editor.js already patched (skipping)" | |
| fi | |
| echo "" | |
| echo "Done! Restart pi for changes to take effect."% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment