From 176aa8bdafa0ffecbc863d0f1ce53e5cbf3f49ff Mon Sep 17 00:00:00 2001 From: Coelacanthus Date: Fri, 13 Nov 2020 16:22:04 +0800 Subject: [PATCH] feat(cmd.md): add auto-complete --- docs/tools/cmd.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/tools/cmd.md b/docs/tools/cmd.md index 7661e745..269811c2 100644 --- a/docs/tools/cmd.md +++ b/docs/tools/cmd.md @@ -119,8 +119,36 @@ command < input > output | u | 按十进制格式显示无符号整型 | | o | 按八进制格式显示变量 | +## 命令行使用技巧 + +### 自动补全 + +补全是 Shell 提供的基本功能之一,主要用于减少命令行使用中的输入量和 typo 概率。 + +一般情况下,使用补全的快捷键一般是 Tab,按下后 Shell 会根据已输入的字符补全信息。 + +不同的 Shell 提供了能力不尽相同的补全能力。 + +以下是常见 Shell 的补全能力[^autocomplete]: + +| Shell | 补全能力(补全范围) | +| ----- | -------------------- | +| cmd (Windows 的传统控制台) | 文件路径 | +| PowerShell | 文件路径、PATH 中的命令名、内建命令名、函数名、命令参数,支持模糊匹配,自动纠错 | +| Bash | 文件路径、PATH 中的命令名、内建命令名、函数名、命令参数 | +| Zsh | 文件路径、PATH 中的命令名、内建命令名、函数名、命令参数,支持模糊匹配,自动纠错和建议 | +| Fish | 文件路径、PATH 中的命令名、内建命令名、函数名、命令参数,支持模糊匹配,补全时可显示参数功能,自动纠错和建议 | + +???+ note + PowerShell 的部分功能需要 PSReadline Module 载入或者位于 PowerShell ISE 中。 + Bash 的补全功能一般需要一个名为 `bash-completions` 的包才能获得完整功能,部分软件的补全文件由软件包自带。 + Zsh 完整的补全功能需要配合用户预定义的文件(一般随 Zsh 包或对应软件包安装)。 + Fish 在默认配置下提供良好完整的补全功能,但仍有部分官方未覆盖到的软件的补全文件由软件自行提供。 + ## 参考资料与注释 [^1]: 刘汝佳《算法竞赛入门经典(第 2 版)》附录 A 开发环境与方法 [^have-to-link-libm-in-gcc]: [Why do you have to link the math library in C?](https://stackoverflow.com/questions/1033898/why-do-you-have-to-link-the-math-library-in-c) + +[^autocomplete]: [Comparison_of_command_shells#Interactive_features](https://en.wikipedia.org/wiki/Comparison_of_command_shells#Interactive_features) -- 2.11.0