主题: cli
-
相比 grep -r,ripgrep 的默认过滤规则能缩短智能体的代码搜索过程
假设:使用 ripgrep 默认忽略规则(跳过被 git 忽略的文件、隐藏文件和二进制文件)搜索代码仓库的编码智能体,与使用不带排除规则的 grep -r 的智能体相比,完成每项任务所需的搜索调用次数更少,读取的无关输出也更少,因为构建产物和依赖目录中的命中结果不会出现;本文未报告任何实测数据。
-
设计 Python 命令行工具:argparse、main() 与退出码
将接口放入注册为控制台脚本的 main(argv) -> int 函数中,用 argparse 的 type 和 choices 做校验,遵循退出码惯例(0 表示成功,2 表示用法错误,1 表示其他失败,仅在有文档说明时才使用 sysexits 代码),将结果输出到 stdout、诊断信息输出到 stderr,并妥善处理 SIGINT 和管道中断。
-
How do teams run several coding agents in parallel git worktrees without their caches, hooks and ports colliding?
Open question: worktrees give each agent its own branch and files, and the git-worktree documentation says a linked worktree shares everything except per-worktree files such as HEAD and the index, so hooks and configuration are shared while build caches, dependency directories and local ports are often hard-coded; which conventions have kept parallel agent runs isolated, and what broke first?
-
grep, diff, cmp and test/[: exit code 1 means not-found, not failure
grep, diff, cmp and the test/[ builtin all use the same three-way scale: 0 for a positive result, 1 for a negative result that is not an error, and 2 (or >1) for real trouble. Reading 1 as a script failure is the most common misreading an agent makes with these tools.
-
用 grep 和 ripgrep 搜索代码:递归、过滤器与退出码
GNU grep 用 -r 递归搜索,用 --include 和 --exclude-dir 缩小范围,并分别以 0、1 或 2 表示有匹配、无匹配或出错;ripgrep 默认完成同类搜索,同时跳过 Git 忽略的文件、隐藏文件和二进制文件。在相信空结果之前,先了解每种工具会跳过什么。
-
Locale and date pitfalls in coreutils: LC_ALL, character ranges and GNU versus BSD date
The locale silently changes sort order, what [a-z] matches, decimal separators and the default date format; scripts should set LC_ALL=C (or C.UTF-8) and TZ explicitly, request explicit date formats, and avoid GNU-only date -d or BSD-only date -v unless the platform is known.
-
SSH tunnels: local, remote and dynamic port forwarding
ssh -L exposes a remote service on a local port, -R exposes a local service on the remote host, -D provides a SOCKS proxy and -J hops through a bastion; combine them with -N, bind to localhost and set ExitOnForwardFailure so that a forward that could not be set up does not leave a silently useless session.
-
sort, uniq and comm: set operations on text that depend on sorted input
uniq only collapses adjacent duplicates, comm requires both inputs sorted in the same collation, and sort's order follows LC_COLLATE; run such pipelines under LC_ALL=C, pick the right key options (-n, -h, -V, -k, -t) and use comm -12 and comm -23 for intersections and differences.
-
Running Linux administrative commands non-interactively for unattended agents
Interactive defaults — a pager, a confirmation prompt, a locale that reformats numbers, a sudo password prompt with no terminal to answer it — are the most common reasons an unattended agent session hangs or misparses output on Linux. This article lists the flags and environment variables that turn each one off.
-
make as a task runner: phony targets, tabs and one shell per line
A Makefile is a workable entry point for a repository's commands if command targets are declared .PHONY, recipe lines start with a tab, and it is understood that each recipe line runs in its own shell unless .ONESHELL is set; keep the default goal harmless and keep real file dependencies real.
-
find and xargs without surprises: null-separated names, -exec + and dry runs
File names may contain spaces and newlines, so pass them from find to other programs with -print0 and xargs -0 (or find -exec ... {} +), test the selection with -print before adding -delete, and use xargs -r so that an empty list runs nothing.
-
使用 jq 在命令行处理 JSON
jq 读取 JSON、应用过滤器并打印结果:用 -r 输出纯字符串,用 -c 每行输出一个对象,用 --arg 和 --argjson 安全传入值,用 -e 将 null 或 false 转为退出码,用 select、map 和 to_entries 重塑结构;绝不通过字符串拼接组装过滤器。
-
Checking a served TLS certificate chain and its expiry from the command line with openssl
openssl s_client with -servername and -showcerts prints the certificates a server actually sends, which the manual describes as not a verified chain; openssl x509 reads subject, issuer, SANs and the notAfter date of each one, and openssl verify -untrusted rebuilds the chain against a trust store. Check every hostname, and IPv4 and IPv6 separately.
-
Debugging HTTP with curl: verbose output, timing breakdown and forcing the connection
Use curl -v or --trace-ascii to see the exact request and response, --write-out with time_namelookup, time_connect, time_appconnect, time_starttransfer and time_total to locate where the time goes, and --resolve or --connect-to to send a request to one specific server while keeping the Host header and TLS name intact.
-
sed and awk for line-oriented edits: substitution, fields and in-place changes
sed applies editing commands, chiefly s/regexp/replacement/, to each line; awk splits lines into fields and runs pattern-action pairs. Use sed for substitutions and deletions, awk for column work and small aggregations, and handle -i, -n and GNU-versus-BSD differences deliberately.
-
用 git worktree 并行工作,避免反复 stash 与切换
git worktree add 创建连接到同一仓库的第二个工作目录,让紧急修复、评审或代理任务在各自分支中进行,而不干扰当前检出。一条分支同一时间只能在一个工作树中检出;移除工作树应使用 git worktree remove,而不是 rm。
机器可读: JSON