我如何在 ubuntu 中使用“你的意思是”功能?

ele*_*bby 6 command-line

如果我在 Ubuntu shell 中输错了命令,它会提供建议。通常,这个建议是正确的,我希望使用它。但是除了重复最后一个命令并自己进行更改之外别无他法。为什么它不提供是/否类型的建议,您只需输入 y 即可接受建议?有什么建议可以实现这种行为吗?

这是发生的事情:

sumeet@sumeet:/media/tux$ git stastus
git: 'stastus' is not a git command. See 'git --help'.

Did you mean this?
    status
sumeet@sumeet:/media/tux$
Run Code Online (Sandbox Code Playgroud)

ænd*_*rük 7

您示例中的建议不是由Ubuntu 的 shell提供,而是help.autocorrect内置于 Git 本身的功能的一部分。

去年讨论过向 Git 添加交互式“是/否”提示,但某些细节从未决定,因此工作仍未完成。

如果您正在寻找对任何命令提出此类建议的内容,您可能想尝试使用 Z shell (zsh) 而不是 Bash。它为命令和文件名提供通用拼写更正,并提供交互式提示:

$ ehco hello > test.txt
zsh: correct 'ehco' to 'echo' [nyae]? y
$ cat tesst.txt
zsh: correct 'tesst.txt' to 'test.txt' [nyae]? y
hello
Run Code Online (Sandbox Code Playgroud)

不过,换壳并不是一件容易的事。通过使用任何非默认 shell,您可能会遇到一些需要时间和精力来解决的障碍。