use-ghostty

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Use Ghostty

使用 Ghostty

Ghostty (1.3+ on macOS) ships an AppleScript dictionary.
scripts/ghostty.js
wraps it so you can see and drive the user's real panes by id. Every call is a plain shell command and takes well under a second.
bash
G=scripts/ghostty.js   # resolve against this skill's folder; it is executable
$G ls                  # id  w<window>:t<tab>  flags  title  cwd
ls
flags:
>
the tab is the visible one in its window,
*
the pane is focused in its tab. Ids are stable for a pane's life, and any unique prefix works (
$G read 481a
). Window numbers follow front-to-back order and change when focus moves, so target panes by id, never by
w1:t2
.
Ghostty(macOS 上 1.3+)附带一个 AppleScript 字典。
scripts/ghostty.js
对其进行了封装,因此可以按 id 查看并控制用户真实的窗格。每次调用都是普通的 shell 命令,耗时远少于一秒。
bash
G=scripts/ghostty.js   # resolve against this skill's folder; it is executable
$G ls                  # id  w<window>:t<tab>  flags  title  cwd
ls
标志:
>
表示该标签页是其窗口中当前可见的标签页,
*
表示该窗格是其标签页中处于焦点的窗格。id 在窗格存续期间保持稳定,任何唯一前缀都可使用(
$G read 481a
)。窗口编号按前后层级排列,并会随焦点移动而变化,因此应始终按 id 定位窗格,绝不要使用
w1:t2
。

Find the right pane first

先找到正确的窗格

  • Identify panes by title and cwd from
    ls
    . Claude Code and most shells keep the title current (
    ✳ <session name>
    ,
    user@host:dir
    ).
  • Your own pane is one of them. It is usually the one whose title is this session's name. Never
    send
    or
    key
    into it, and never close it.
  • When two panes could match, ask the user which one. Do not guess before typing into a pane.
  • 通过
    ls
    中的标题和 cwd 识别窗格。Claude Code 和大多数 shell 会持续更新标题(
    ✳ <session name>
    、
    user@host:dir
    )。
  • 你自己的窗格也在其中。 通常,它的标题就是当前会话的名称。绝不要向它
    send
    或
    key
    ,也不要关闭它。
  • 如果可能有两个窗格匹配,请询问用户是哪一个。在向窗格输入内容前不要猜测。

Read

读取

bash
$G read <id>                 # visible screen
$G read <id> --all --tail 200  # scrollback + screen, last 200 lines
$G wait <id> 'PASS|FAIL' --timeout 120   # poll the screen until the regex matches, prints it
Ghostty can only dump a pane through
write_*_file:copy
, which puts a temp path on the clipboard. The script snapshots every clipboard item and type first and restores them after, then deletes the temp file. If the user copies something during that half second, it can be lost.
bash
$G read <id>                 # visible screen
$G read <id> --all --tail 200  # scrollback + screen, last 200 lines
$G wait <id> 'PASS|FAIL' --timeout 120   # poll the screen until the regex matches, prints it
Ghostty 只能通过
write_*_file:copy
导出窗格内容,这会将临时路径放到剪贴板。脚本会先快照剪贴板中的每个条目及其类型,随后恢复这些条目,再删除临时文件。如果用户恰好在这半秒内复制了内容,该内容可能会丢失。

Act

操作

bash
$G send <id> 'make test' --enter     # types as a paste, then presses enter
$G key <id> c --mods control         # Ctrl-C; keys: enter, escape, tab, up, a, ...
$G split <id> right --cwd ~/repo --cmd 'npm run dev' --wait-after   # prints new pane id
$G tab --near <id> --cwd ~/repo      # new tab in that pane's window, prints new pane id
$G window --input $'git status\n'    # new window, initial input typed after launch
$G focus <id>
$G close <id>                        # also close-tab <id>, close-window <id>
$G action <id> <ghostty-action>      # any keybind action, e.g. clear_screen, toggle_split_zoom
--cmd
replaces the shell, so the pane closes when the command exits unless
--wait-after
is set. To keep a shell after the command, use
--input $'cmd\n'
instead.
bash
$G send <id> 'make test' --enter     # types as a paste, then presses enter
$G key <id> c --mods control         # Ctrl-C; keys: enter, escape, tab, up, a, ...
$G split <id> right --cwd ~/repo --cmd 'npm run dev' --wait-after   # prints new pane id
$G tab --near <id> --cwd ~/repo      # new tab in that pane's window, prints new pane id
$G window --input $'git status\n'    # new window, initial input typed after launch
$G focus <id>
$G close <id>                        # also close-tab <id>, close-window <id>
$G action <id> <ghostty-action>      # any keybind action, e.g. clear_screen, toggle_split_zoom
--cmd
会替换 shell,因此除非设置
--wait-after
,否则命令退出后窗格也会关闭。若要在命令执行后保留 shell,请改用
--input $'cmd\n'
。

Rules

规则

  • Read before you type. Run
    read <id> --tail 20
    and check that the pane is at the prompt you expect. A pane running Claude, a REPL,
    less
    , or an editor takes your text as input to that program.
  • Closing is instant.
    close
    ,
    close-tab
    and
    close-window
    kill running processes with no confirmation. Close only panes you created in this session, or ones the user named.
  • Verify by reading back. After
    send
    , use
    wait
    or
    read
    to confirm what happened, and report what the pane showed.
  • The first call may trigger a macOS Automation prompt ("allow <terminal> to control Ghostty"). The user has to accept it once.
  • 输入前先读取。 运行
    read <id> --tail 20
    ,确认窗格正处于预期的提示符。正在运行 Claude、REPL、
    less
    或编辑器的窗格会把你的文本当作该程序的输入。
  • 关闭会立即生效。
    close
    、
    close-tab
    和
    close-window
    会终止正在运行的进程,且不会要求确认。只关闭本次会话中创建的窗格,或用户明确指定的窗格。
  • 通过回读进行验证。 执行
    send
    后,使用
    wait
    或
    read
    确认发生了什么,并报告窗格显示的内容。
  • 首次调用可能会触发 macOS Automation 权限提示(“允许 <terminal> 控制 Ghostty”)。用户需要接受一次。