GitHub - oh-rid/kitty-context-menu: Native macOS right-click context menu for Kitty terminal · GitHub
Skip to content

About

Native macOS right-click context menu for Kitty terminal

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

kitty-context-menu

Native macOS right-click context menu for Kitty terminal.

Kitty doesn't have a built-in context menu. This adds one using a compiled Swift binary that renders a native NSMenu popup at your mouse cursor.

macOS only Kitty 0.35+

Menu Items

Item Action
Copy Confirms text is copied (auto-copied on selection via copy_on_select)
Paste Pastes from system clipboard
Copy All Copies entire scrollback + screen to clipboard
New Tab Opens a new kitty tab
Clear Screen Clears terminal and scrollback

"Copy" only appears when clipboard has content. Separator line between clipboard actions and terminal actions.

How It Works

Right-click
  → kitty fires: launch --type=background context_menu.sh
  → context_menu.sh calls compiled Swift binary (context_menu_bin)
  → Swift binary renders native NSMenu at mouse cursor
  → User clicks menu item → choice returned via temp file
  → context_menu.sh executes action via kitty remote control (kitty @)

Key design decisions:

  • launch --type=background — menu runs in separate process, doesn't block kitty
  • copy_on_select clipboard — text copied to clipboard the moment you select it, no race condition with right-click clearing selection
  • Compiled Swift binary — instant popup, no interpreter startup delay
  • discard_event on right press — prevents kitty's default "extend selection" from clearing your selection before the menu appears
  • Kitty remote control via unix socket — actions (paste, clear, new tab) executed reliably through kitty @

Requirements

  • macOS (uses NSMenu, Cocoa framework)
  • Kitty 0.35+ (needs allow_remote_control, listen_on, copy_on_select, launch --type=background)
  • Xcode Command Line Tools (swiftc compiler)

Install

git clone https://github.com/prthmgoyl/kitty-context-menu.git
cd kitty-context-menu
chmod +x install.sh
./install.sh

Then restart kitty (Cmd+Q, reopen).

Uninstall

cd kitty-context-menu
chmod +x uninstall.sh
./uninstall.sh

Manual Install

If you prefer to set it up manually:

  1. Copy context_menu.sh and context_menu.swift to ~/.config/kitty/
  2. Compile: swiftc ~/.config/kitty/context_menu.swift -o ~/.config/kitty/context_menu_bin -framework Cocoa
  3. Make executable: chmod +x ~/.config/kitty/context_menu.sh
  4. Add to ~/.config/kitty/kitty.conf:
allow_remote_control socket-only
listen_on unix:/tmp/kitty-sock
copy_on_select clipboard

mouse_map right press ungrabbed discard_event
mouse_map right release ungrabbed launch --type=background ~/.config/kitty/context_menu.sh
  1. Restart kitty

Customization

Edit context_menu.sh to add/remove/rename menu items. The ITEMS variable is a comma-separated list. Use --- for separator lines.

# Example: add "Open Config" item
ITEMS="Copy,Paste,---,Copy All,New Tab,Open Config,Clear Screen"

# In the case statement:
"Open Config")
    kitty @ --to "$KITTY_SOCKET" action edit_config_file
    ;;

No recompilation needed for menu item changes — only context_menu.sh is edited. Recompile Swift binary only if you change context_menu.swift (popup rendering logic).

Known Limitations

  • macOS only — NSMenu is a Cocoa API, no Linux/Windows support
  • No visual "Select All" — kitty doesn't support programmatic text selection. "Copy All" copies everything to clipboard instead
  • Popup appearance — follows your macOS system theme (light/dark), not kitty's color scheme
  • Multiple kitty instances — socket discovery uses ls /tmp/kitty-sock* and picks the first one. If you run multiple kitty instances, the menu may target the wrong one

License

MIT

About

Native macOS right-click context menu for Kitty terminal

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages