有没有一种方法可以让Fish Shell纠正带空格的命令中的常见错别字?

问题描述

我对Fish还是很陌生,到目前为止,我还是喜欢它,但是我对缩写不能有空格感到恼火。例如,当我键入git statsu(比实际git status的命令执行更多的时候),我希望它用正确的命令替换文本。我尝试将以下内容添加到我的config.fish文件中:

abbr "git statsu" "git status"

...这给了我

abbr --add: Abbreviation 'git statsu' cannot have spaces in the word

第二次尝试(不支持空格的别名):

alias "git statsu"="git status"
- (line 1): function: Unexpected positional argument 'statsu'
function git statsu --wraps 'git status' --description 'alias git statsu=git status';  git status $argv; end
^
from sourcing file -
    called on line 61 of file /usr/share/fish/functions/alias.fish
in function 'alias' with arguments 'git\ statsu=git\ status'
    called on line 19 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
    called on line 1 of file -
in function 'config'

类似地,我尝试:

alias "git\ statsu"="git\ status"

其中无声的失败:

> git statsu
git: 'statsu' is not a git command. See 'git --help'.

The most similar command is
    status

最后(一个参数后的缩写未扩展):

abbr statsu status
> git statsu
git: 'statsu' is not a git command. See 'git --help'.

The most similar command is
    status

请提供替代解决方案;我厌倦了不断输入错误的命令并不得不手动纠正它。

解决方法

为什么不使用git别名呢?这是我的几个:

$ cat ~/.gitconfig
...
[alias]
    co = checkout
    stat = status

这是一条鱼,您可以通过其他常见的错字轻松进行扩展:

function git
    switch $argv[1]
        case statsu
            set argv[1] status
    end
    command git $argv
end