chronic

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Chronic

Chronic

chronic
(from
moreutils
) runs a command quietly unless it fails. On success (exit 0) all stdout/stderr is suppressed. On failure the full output is shown.
chronic
(来自
moreutils
工具集)会静默运行命令,仅在命令失败时输出内容。命令成功(退出码0)时,所有stdout和stderr输出都会被抑制;失败时则显示完整输出。

Installation

安装

Ensure
chronic
is available before use:
bash
undefined
使用前请确保
chronic
已可用:
bash
undefined

NixOS / nix

NixOS / nix

nix-shell -p moreutils --run "chronic ..."
nix-shell -p moreutils --run "chronic ..."

or add moreutils to system/devshell packages

或者将moreutils添加到系统/开发环境包中

Debian/Ubuntu

Debian/Ubuntu

apt install moreutils
apt install moreutils

macOS

macOS

brew install moreutils

If the project uses `flake.nix`, `devbox.json`, or `devenv.nix`, add `moreutils` there.
brew install moreutils

如果项目使用`flake.nix`、`devbox.json`或`devenv.nix`,请在其中添加`moreutils`。

When to Add chronic

何时添加chronic

Wrap a command with
chronic
when all of these are true:
  1. The command produces output on success that neither you nor the user need to read
  2. The command's failure output is sufficient for diagnosing problems
  3. The command is invoked repeatedly (in Justfiles, Makefiles, CI, or interactive sessions)
Common candidates: linters, formatters, type checkers, static analysis, compilation, dependency installation, database migrations, deploy scripts.
当满足以下所有条件时,使用
chronic
包装命令:
  1. 命令成功时产生的输出对你和用户来说都无阅读必要
  2. 命令失败时的输出足以用于诊断问题
  3. 该命令会被重复调用(如在Justfile、Makefile、CI或交互式会话中)
常见适用场景:代码检查工具、格式化工具、类型检查器、静态分析、编译、依赖安装、数据库迁移、部署脚本。

Examples

示例

makefile
undefined
makefile
undefined

Before — noisy on every run

之前——每次运行都会产生大量输出

check: eslint src/ tsc --noEmit
check: eslint src/ tsc --noEmit

After — silent on success, verbose on failure

之后——成功时静默,失败时显示详细输出

check: chronic eslint src/ chronic tsc --noEmit

```just
check: chronic eslint src/ chronic tsc --noEmit

```just

Justfile

Justfile

check: chronic cargo clippy --all-targets chronic cargo fmt -- --check

When running ad-hoc commands in the terminal:

```bash
chronic npm install
chronic terraform plan -detailed-exitcode
check: chronic cargo clippy --all-targets chronic cargo fmt -- --check

在终端中运行临时命令时:

```bash
chronic npm install
chronic terraform plan -detailed-exitcode

When to Remove chronic

何时移除chronic

Remove
chronic
from a command when any of these are true:
  1. The output contains information the user needs even on success (e.g., build artifacts paths, deploy URLs, generated file lists, timing/performance data)
  2. The command is interactive or streams progress that the user wants to monitor
  3. You or the user are debugging — temporarily remove chronic to see full output, then restore it after the issue is resolved. But also consider adding an extra command for that
  4. The command's exit code doesn't reliably reflect success/failure (some tools exit 0 on warnings)
Do not bypass chronic by calling the underlying command directly (e.g., running
cargo clippy
instead of
just check
to avoid chronic). Instead, remove chronic from the wrapper (Justfile/Makefile) for that specific command.
当满足以下任一条件时,从命令中移除
chronic
  1. 命令成功时的输出包含用户需要的信息(如构建产物路径、部署URL、生成文件列表、计时/性能数据等)
  2. 命令是交互式的,或会输出用户需要监控的进度信息
  3. 你或用户正在调试——临时移除chronic以查看完整输出,问题解决后再恢复。也可以考虑为此添加一个额外的命令
  4. 命令的退出码无法可靠反映成功/失败状态(部分工具即使有警告也会返回0)
请勿通过直接调用底层命令绕过chronic(例如,为了避开chronic而直接运行
cargo clippy
而非
just check
)。相反,应从包装器(Justfile/Makefile)中移除该特定命令的chronic。

Flags

选项

  • chronic -v
    — on failure, labels stdout vs stderr and shows the return code. Use when diagnosing which stream contains the error.
  • chronic -e
    — triggers output when stderr is non-empty, even if exit code is 0. Use for commands that print warnings to stderr but still exit 0.
  • chronic -v
    —— 失败时,标记stdout和stderr并显示返回码。用于诊断错误来自哪个输出流。
  • chronic -e
    —— 即使退出码为0,只要stderr非空就触发输出。适用于那些会在stderr输出警告但仍返回0的命令。

Continuous Optimization

持续优化

Adopt chronic incrementally and adjust based on experience:
  1. Start without chronic for new/unfamiliar commands until their output patterns are understood
  2. Add chronic once a command is confirmed to be noisy-on-success and informative-on-failure
  3. Remove chronic when output turns out to be useful — don't hesitate, this is expected and healthy
  4. Re-add chronic after debugging is complete
When you notice a command producing output that nobody reads, suggest adding chronic. When chronic is hiding something useful, suggest removing it. Mention these suggestions naturally, not as a separate concern.
逐步采用chronic并根据使用经验调整:
  1. 初始不使用chronic:对于新的或不熟悉的命令,先了解其输出模式后再决定是否使用
  2. 添加chronic:确认命令在成功时冗余、失败时信息充足后,再添加chronic
  3. 移除chronic:当发现输出实际有用时,不要犹豫移除——这是正常且合理的调整
  4. 重新添加chronic:调试完成后恢复使用chronic
当你注意到某个命令产生无人阅读的冗余输出时,建议添加chronic;当chronic隐藏了有用内容时,建议移除它。自然地提出这些建议,不要将其作为单独的问题。