无法让 Zsh 不建议修复别名

Léo*_* 준영 2 zsh alias

我有一个别名

alias tdA='todo -a'
Run Code Online (Sandbox Code Playgroud)

我在 Zsh 中得到以下信息

tdA          
zsh: correct 'tdA' to 'tda' [nyae]? 
Run Code Online (Sandbox Code Playgroud)

如何让 Zsh 不建议修复别名?

Lar*_*old 8

我已经使用 zsh 大约 18 年了,我必须说我不喜欢公认的解决方案。原因如下:

您需要找出问题的根源 - 确定为什么提供 'tda' 作为更正选项。您所做的是在全球范围内完全禁用拼写更正。这在试图摆脱战术问题的同时拒绝了您一些非常好的功能。这就像想通过引爆炸药来杀死你家中的苍蝇,只是因为你懒得弄清楚苍蝇拍在哪里:它可能会解决问题,但作为回报你牺牲了很多。:)

在您可以确定 zsh 当前的拼写校正配置之前,您应该考虑将特殊 shell 变量 $CORRECT_IGNORE 的值设置为 'tda' 值。

这是 zsh 手册页中的条目:

   CORRECT_IGNORE
          If set, is treated as a pattern during spelling correction.  Any
          potential  correction  that matches the pattern is ignored.  For
          example, if the value is `_*' then completion functions  (which,
          by  convention,  have  names  beginning  with `_') will never be
          offered as spelling corrections.  The pattern does not apply the
          correction  of  file names, as applied by the CORRECT_ALL option
          (so with the example just given files beginning with `_' in  the
          current directory would still be completed).
Run Code Online (Sandbox Code Playgroud)

这应该可以帮助您度过难关,直到您可以确定 'tda' 的实际来源。

另请注意,您可以使用 precommand 修饰符 'nocorrect' 在每个命令的基础上禁用拼写更正。你可以用它来做一些有点hacky但有效的事情:

alias tdA="nocorrect tda"
alias tda="todo -a"
Run Code Online (Sandbox Code Playgroud)

别名只是由 zsh 替换到命令行中的标记,并且会重新扫描这些替换以获取其他别名。所以以上应该有效。

希望这些替代方法可以为您提供一种更有选择性的方法来解决您的问题,同时仍然可以让您受益于 zsh 丰富的拼写校正功能。

祝你好运!