逗号与问号的重现:使用 Pi 的快速终端助手
A Comma and a Question Mark, Redux: Quick Terminal Helpers Using Pi

原始链接: https://z3ugma.github.io/2026/05/25/a-comma-and-a-question-mark/

受 Rémi Louf 的启发,作者实现了一套精简的工作流,利用 AI 弥补了终端命令行熟练度的不足。通过创建两个简单的 shell 脚本,作者现在可以使用逗号(`,`)和问号(`?`)触发器,将 AI 直接集成到工作流中。 输入 `, <描述>` 会提示 AI(通过 CLI 代理“pi”和 OpenRouter)生成 shell 命令。出于安全考虑,脚本会将结果复制到剪贴板并打印在终端上,以便用户在执行前进行检查和编辑。 输入 `? <问题>` 则提供了一种快速提问或查询网络信息的方式,无需启动完整的聊天会话。通过利用 `web_search` 和 `read` 等工具,作者在自然语言与终端操作之间建立了一座快速、高效的桥梁,并可直接在命令行中使用。相关配置文件已上传至作者的公共 dotfiles 仓库。

Hacker News 最新 | 往日 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 逗号与问号的重现:使用 Pi 编写快捷终端辅助工具 (z3ugma.github.io) 9 点,由 z3ugma 发布于 1 小时前 | 隐藏 | 往日 | 收藏 | 讨论 | 帮助 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

I am a decent user of the terminal, but I am not strong at remembering find flags - or rsync, or grep for that matter.

I read Rémi Louf’s post about wiring a comma and a question mark into his shell and immediately wanted the same thing. The idea is simple: type , <description> and get a shell command that does what you described. Type ? <question> and get an AI answer right in your terminal.

Rémi runs a local Qwen model through llama.cpp. I don’t have a local model, but I do have pi, a CLI chat agent, and I have my routing set through OpenRouter. Pi was already configured and working on my machine. So I took the idea and adapted it.

The comma

When I want nice shell commands, now all I have to do is type a comma followed by a plain English description of what I want to do. A few seconds later I get a suggested command copied to my clipboard. For example:

, find the 5 largest files in the current directory

A second later:

is copied to my clipboard. I press Cmd+V, the command lands on my prompt line. I read it, maybe edit it, then press Enter myself.

The comma is slightly safe because it won’t automatically execute. It copies to my clipboard and prints the command - so that I can judge and apply the keystroke between “here’s a suggestion” and “yes, do that”.

Under the hood it’s a thin shell script in ~/.dotfiles/bin/, on my PATH:

#!/usr/bin/env zsh
local command
command=$(pi --print -p --no-tools --thinking off \
  --system-prompt "output exactly one shell command —
  the best one — with no numbering, no explanation,
  no markdown, no backticks. Just the raw command
  on a single line." "$desc" 2>/dev/null)

echo -n "$command" | pbcopy
echo "$command"

Pi uses whichever model is currently selected. Typically for me this is on OpenRouterusing DeepSeek v4 Flash or Gemini 3.5 Flash. These have low or free API cost.

I skipped the JSON Schema trick from the original. I don’t think pi exposes a structured output mode, so I just made the prompt tight and stripped backticks in post.

The question mark

Likewise, when I just have a short question, I now have the q script. Instead of launching a whole pi session, I can get a quick answer with minimal fuss:

q what's the weather like today in Brutus, MI?

The q command also invokes Pi, but now Pi can use a narrow toolset including from some extensions:

pi --print -p \
  --system-prompt "You are a helpful, concise assistant
  running in a macOS terminal. Answer clearly and accurately.
  You can read files from disk and search the web — use those
  when you need current or file-specific information." \
  --tools "read,web_search,url_extract,web_fetch,batch_web_fetch" \
  "$question"

You can find the script files in my dotfiles repo on GitHub.

联系我们 contact @ memedata.com