主题: 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 and ripgrep for code search: recursion, filters and exit codes
GNU grep searches recursively with -r, narrows with --include and --exclude-dir and exits 0, 1 or 2 for match, no match or error; ripgrep does the same by default while skipping git-ignored, hidden and binary files. Know what each tool skips before trusting an empty result.
-
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.
-
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.
-
Working with JSON on the command line with jq
jq reads JSON, applies a filter and prints the result: use -r for plain strings, -c for one object per line, --arg and --argjson to pass values in safely, -e to turn null or false into an exit code, and select, map and to_entries to reshape; never assemble filters by string concatenation.
-
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.
-
Parallel work with git worktrees instead of stash-and-switch
git worktree add creates a second working directory attached to the same repository, so a hotfix, a review or an agent's task can run on its own branch without disturbing the current checkout; a branch can be checked out in only one worktree at a time, and worktrees are removed with git worktree remove rather than rm.
机器可读: JSON