kitty

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Kitty Remote Control Skill

Kitty远程控制技能

This skill empowers you to manage multiple concurrent processes (like servers, watchers, or long builds) using kitty's remote control feature directly from the
Bash
tool.
Since you are running inside a kitty terminal, you can spawn new windows or tabs to handle these tasks without blocking your main communication channel.
借助该技能,你可以直接通过
Bash
工具,利用kitty的远程控制功能管理多个并发进程(如服务器、监视器或长时间构建任务)。
由于你正运行在kitty终端中,你可以创建新的窗口或标签页来处理这些任务,而不会阻塞主通信通道。

1. Verify Environment & Check Status

1. 验证环境并检查状态

First, verify you are running inside kitty with remote control enabled. You can try listing windows:
bash
kitten @ ls
If this fails, check if
$KITTY_LISTEN_ON
is set. Note that in some configurations it might be empty even if remote control is enabled (using default sockets).
bash
echo $KITTY_LISTEN_ON
If remote control is not enabled, the user should add
allow_remote_control yes
to their
kitty.conf
or start kitty with
--allow-remote-control
.
首先,验证你是否在已启用远程控制的kitty终端中运行。你可以尝试列出所有窗口:
bash
kitten @ ls
如果该命令失败,请检查是否已设置
$KITTY_LISTEN_ON
环境变量。注意,在某些配置中,即使已启用远程控制(使用默认套接字),该变量也可能为空。
bash
echo $KITTY_LISTEN_ON
如果未启用远程控制,用户需要在
kitty.conf
中添加
allow_remote_control yes
配置,或者使用
--allow-remote-control
参数启动kitty。

2. Spawn a Background Process

2. 启动后台进程

To run a command (e.g., a dev server) in a way that persists and can be inspected:
  1. Create a new window in the SAME tab as the agent (recommended): Use
    $KITTY_WINDOW_ID
    to ensure the new window stays with you.
    bash
    WID=$(kitten @ launch --match "id:$KITTY_WINDOW_ID" --title "server-log" --keep-focus)
    echo "Created window with ID: $WID"
  2. Or create a new tab:
    bash
    kitten @ launch --type=tab --title "server-log" --keep-focus
  3. Launch with a command directly: (Use
    --hold
    if you want the window to stay open after the command finishes)
    bash
    kitten @ launch --title "server-log" --keep-focus --hold npm start
要以持久化且可查看的方式运行命令(例如开发服务器):
  1. 在当前会话的同一标签页中创建新窗口(推荐): 使用
    $KITTY_WINDOW_ID
    确保新窗口始终与当前会话关联。
    bash
    WID=$(kitten @ launch --match "id:$KITTY_WINDOW_ID" --title "server-log" --keep-focus)
    echo "Created window with ID: $WID"
  2. 或者创建新标签页:
    bash
    kitten @ launch --type=tab --title "server-log" --keep-focus
  3. 直接带命令启动: (如果希望命令执行完成后窗口保持打开状态,请使用
    --hold
    参数)
    bash
    kitten @ launch --title "server-log" --keep-focus --hold npm start

3. Send Text/Commands to a Window

3. 向窗口发送文本/命令

Send keystrokes to a specific window. Use the window ID for precision, or matching for convenience.
Using ID (Reliable):
bash
kitten @ send-text --match "id:$WID" "npm start\n"
Using Matching (Title):
Note: Use
\n
for Enter. In some shells, you may need to use
$'...'
or pipe to ensure the newline is interpreted correctly.
bash
kitten @ send-text --match "title:server-log" "npm start
"
向指定窗口发送按键操作。可以使用窗口ID精准匹配,或者使用便捷匹配方式。
使用ID(可靠方式):
bash
kitten @ send-text --match "id:$WID" "npm start\n"
使用匹配(标题):
注意:使用
\n
表示回车键。在某些shell中,你可能需要使用
$'...'
或管道来确保换行符被正确解析。
bash
kitten @ send-text --match "title:server-log" "npm start
"

OR

或者

echo "npm start" | kitten @ send-text --match "title:server-log" --stdin

Or send to all windows:

```bash
kitten @ send-text --all "echo hello\n"
echo "npm start" | kitten @ send-text --match "title:server-log" --stdin

也可以向所有窗口发送:

```bash
kitten @ send-text --all "echo hello\n"

4. Inspect Output (Get Text from Window)

4. 查看输出(从窗口获取文本)

Get the current visible text from a window:
bash
kitten @ get-text --match "id:$WID"
Get text including scrollback buffer:
bash
kitten @ get-text --match "title:server-log" --extent=all
Get only the last command output (requires shell integration):
bash
kitten @ get-text --match "title:server-log" --extent=last_cmd_output
获取窗口当前显示的文本:
bash
kitten @ get-text --match "id:$WID"
获取包含回滚缓冲区的文本:
bash
kitten @ get-text --match "title:server-log" --extent=all
仅获取最后一条命令的输出(需要shell集成):
bash
kitten @ get-text --match "title:server-log" --extent=last_cmd_output

5. Focus or Bring Window to Front

5. 聚焦或前置窗口

Focus a specific window:
bash
kitten @ focus-window --match "id:$WID"
Focus a specific tab:
bash
kitten @ focus-tab --match "title:server-log"
聚焦指定窗口:
bash
kitten @ focus-window --match "id:$WID"
聚焦指定标签页:
bash
kitten @ focus-tab --match "title:server-log"

6. Interact with Processes

6. 与进程交互

Send Ctrl+C (Interrupt):
bash
kitten @ send-text --match "id:$WID" "\x03"
Close a window:
bash
kitten @ close-window --match "id:$WID"
Close a tab: (Note: You can close a tab by matching its title or any window ID inside it)
bash
undefined
发送Ctrl+C(中断信号):
bash
kitten @ send-text --match "id:$WID" "\x03"
关闭窗口:
bash
kitten @ close-window --match "id:$WID"
关闭标签页: (注意:你可以通过匹配标签页标题或其中任意窗口的ID来关闭标签页)
bash
undefined

By ID of a window inside the tab

通过标签页内某窗口的ID

kitten @ close-tab --match "id:$WID"
kitten @ close-tab --match "id:$WID"

By tab title

通过标签页标题

kitten @ close-tab --match "title:server-log"
undefined
kitten @ close-tab --match "title:server-log"
undefined

7. Advanced: Window Matching

7. 进阶:窗口匹配

Kitty supports powerful matching expressions:
  • title:pattern
    - Match by window title
  • id:number
    - Match by window ID
  • pid:number
    - Match by process ID
  • cwd:path
    - Match by current working directory
  • cmdline:pattern
    - Match by command line
  • state:focused
    - Match the focused window
  • state:active
    - Match the active window
Combine with
and
,
or
,
not
:
bash
kitten @ focus-window --match "title:server and state:active"
Kitty支持强大的匹配表达式:
  • title:pattern
    - 按窗口标题匹配
  • id:number
    - 按窗口ID匹配
  • pid:number
    - 按进程ID匹配
  • cwd:path
    - 按当前工作目录匹配
  • cmdline:pattern
    - 按命令行匹配
  • state:focused
    - 匹配当前聚焦的窗口
  • state:active
    - 匹配当前活动的窗口
可以结合
and
or
not
使用:
bash
kitten @ focus-window --match "title:server and state:active"

8. Get Window/Tab Information

8. 获取窗口/标签页信息

List all OS windows, tabs, and windows as JSON:
bash
kitten @ ls
Get current focused window ID:
bash
kitten @ ls | jq -r '.[].tabs[] | select(.is_focused) | .windows[] | select(.is_focused) | .id'
Parse for specific info:
bash
kitten @ ls | jq '.[].tabs[].windows[] | {id, title, cmdline}'
以JSON格式列出所有系统窗口、标签页和终端窗口:
bash
kitten @ ls
获取当前聚焦窗口的ID:
bash
kitten @ ls | jq -r '.[].tabs[] | select(.is_focused) | .windows[] | select(.is_focused) | .id'
解析特定信息:
bash
kitten @ ls | jq '.[].tabs[].windows[] | {id, title, cmdline}'

Summary of Pattern

模式总结

  1. WID=$(kitten @ launch --title "NAME" --keep-focus [CMD])
    - Create window and save ID
  2. kitten @ send-text --match "id:$WID" "CMD\n"
    - Send command reliably
  3. kitten @ get-text --match "id:$WID"
    - Read output
  4. kitten @ close-window --match "id:$WID"
    - Cleanup
  1. WID=$(kitten @ launch --title "NAME" --keep-focus [CMD])
    - 创建窗口并保存ID
  2. kitten @ send-text --match "id:$WID" "CMD\n"
    - 可靠地发送命令
  3. kitten @ get-text --match "id:$WID"
    - 读取输出
  4. kitten @ close-window --match "id:$WID"
    - 清理资源

Common Remote Control Commands

常用远程控制命令

CommandDescription
kitten @ ls
List all windows/tabs
kitten @ launch
Create new window/tab
kitten @ send-text
Send text to window
kitten @ get-text
Get text from window
kitten @ focus-window
Focus a window
kitten @ focus-tab
Focus a tab
kitten @ close-window
Close a window
kitten @ close-tab
Close a tab
kitten @ signal-child
Send signal to process
kitten @ set-tab-title
Change tab title
kitten @ set-colors
Change terminal colors
命令描述
kitten @ ls
列出所有窗口/标签页
kitten @ launch
创建新窗口/标签页
kitten @ send-text
向窗口发送文本
kitten @ get-text
从窗口获取文本
kitten @ focus-window
聚焦窗口
kitten @ focus-tab
聚焦标签页
kitten @ close-window
关闭窗口
kitten @ close-tab
关闭标签页
kitten @ signal-child
向进程发送信号
kitten @ set-tab-title
修改标签页标题
kitten @ set-colors
修改终端颜色